在 Firebase Cloud Function 中使用 Secret Manager 的正确方法是什么?
我开始使用 Node.js 在 Cloud Function 中添加包含特定密码的 SECRET_NAME 的 Secret Manager。我两种方法都尝试过。首先,使用控制台添加 Secret Manager,然后直接通过 Firebase CLI 添加 Secret Manager。不幸的是,这两种方法都会在 Secret 的 Cloud Function 变量中给出空的 Secret 值,如下图所示。
我使用了参数 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很抱歉各位。
显然,我写的代码是错误的:
谢谢你,@MichaelBleigh。
问题现已解决。
I am sorry guys.
Apparently, I was wrong in writing the code:
Thank you, @MichaelBleigh.
Problem is now solved.