在 Firebase Cloud Function 中使用 Secret Manager 的正确方法是什么?

发布于 2025-01-15 06:31:49 字数 1368 浏览 1 评论 0原文

我开始使用 Node.js 在 Cloud Function 中添加包含特定密码的 SECRET_NAME 的 Secret Manager。我两种方法都尝试过。首先,使用控制台添加 Secret Manager,然后直接通过 Firebase CLI 添加 Secret Manager。不幸的是,这两种方法都会在 Secret 的 Cloud Function 变量中给出空的 Secret 值,如下图所示。
链接到picture

我使用了参数 runWith({secret: ["SECRET_NAME"]}) ,如下面的代码所示。

exports.Auth = functions.runWith(secret).https.onCall(async (data, context) => {
  const response = 129132;
  return Promise.resolve(response);
});

const secret = {
  timeoutSeconds: 120,
  memory: "1GB",
  secret: ["SECRET_NAME"],
  minInstances: 0,
};

我遵循 Firebase Cloud Function 中编写的文档 (https://firebase.google.com/docs /functions/config-env)。

我花了将近一个星期的时间来找出我错在哪里,但一无所获。我还在 Google Cloud Console 中的当前 SECRET_NAME 中添加了一个角色“Secret Manager Secret Accessor”,但它根本没有给出任何结果。正如这篇 stackoverflow 帖子 中所写参考

我的问题是我应该在 Google Cloud Platform 的 Cloud Function Console 中手动添加 SECRET_NAME 吗?如果是这样,那么上面写的文档有什么用呢? Firebase 是否试图将我们引向无处可去的地方?

I started to add Secret Manager with a SECRET_NAME contains a certain password inside Cloud Function using Node.js. I tried both ways. First, adding Secret Manager using Console and another, adding Secret Manager directly through Firebase CLI. Unfortunately, both ways give an empty Secret value in Cloud Function variable of Secret as shown in picture below.

Link to the picture

I used parameter runWith({secret: ["SECRET_NAME"]}) as shown in code below.

exports.Auth = functions.runWith(secret).https.onCall(async (data, context) => {
  const response = 129132;
  return Promise.resolve(response);
});

const secret = {
  timeoutSeconds: 120,
  memory: "1GB",
  secret: ["SECRET_NAME"],
  minInstances: 0,
};

I followed the documentation written in Firebase Cloud Function (https://firebase.google.com/docs/functions/config-env).

I had wasted almost a week to figure out where I got wrong and found nothing. I also added a role "Secret Manager Secret Accessor" to current SECRET_NAME in Google Cloud Console, and it gave result to nothing at all. As written in this stackoverflow post reference

My question is should I add SECRET_NAME manually in Cloud Function Console in Google Cloud Platform? If so, then what is the use of documentation written above? Is Firebase trying to lead us to nowhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱她像谁 2025-01-22 06:31:49

我很抱歉各位。

显然,我写的代码是错误的:

const secret = {
  timeoutSeconds: 120,
  memory: "1GB",
  secrets: ["SECRET_NAME"], //Must use secrets not secret
  minInstances: 0,
};

enter image description here

谢谢你,@MichaelBleigh。

问题现已解决。

I am sorry guys.

Apparently, I was wrong in writing the code:

const secret = {
  timeoutSeconds: 120,
  memory: "1GB",
  secrets: ["SECRET_NAME"], //Must use secrets not secret
  minInstances: 0,
};

enter image description here

Thank you, @MichaelBleigh.

Problem is now solved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文