部署firebase云函数v2时出现权限问题

问题描述 投票:0回答:1

在部署 firebase cloud function v2 期间,我尝试访问我在 GCP UI 中声明的秘密环境变量。

事实上,在运行 cli 命令后,我被授予了

secretmanager.version.access
的权限:
firebase deploy --only functions
, 我收到错误:
Error: HTTP Error: 403, Permission 'secretmanager.secrets.setIamPolicy' denied for resource 'projects/{my-project}/secrets/{secret-name}' (or it may not exist)

这里代表了函数的代码以及我如何访问秘密环境变量:

import { initializeApp, getApps, getApp } from "firebase-admin/app";
import { getFirestore } from "firebase-admin/firestore";
import { onCall, HttpsError } from "firebase-functions/v2/https";
import jwt from "jsonwebtoken";

initializeApp();
const db = getFirestore();
const {sign,verify} = jwt;
export const inviteClientPerMail = onCall(
    {
      secrets: ["secret-name"],
      region: "europe-west3",
      cors: true,
      enforceAppCheck: false
    },
    async (request) => {

"""function logic"""
...
console.log("Secret is: ", process.env.`secret-name`);
...
"""function logic"""
}
...

是否是与 firebase 或云平台相关的问题?或者 Firebase CLI 应该如何查看我在 GCP 平台中设置的权限?

node.js google-cloud-firestore google-cloud-functions google-secret-manager
1个回答
0
投票

正如约翰·汉利所建议的,你已获得许可。但是,云功能不会使用您的身份。这意味着附加到云功能的服务帐户缺少所需的权限(IAM 角色)。所以,你需要授予他们。

按照以下步骤进行相应尝试:

  1. 检查您使用哪个服务帐户来使用云功能。您可以在云功能的部署信息详情中找到serviceAccountEmail:xxxxxxxxxxxx.gserviceaccount.com

  2. 检查此服务帐户是否具有足够的

    IAM 权限,例如密钥上的 (roles/secretmanager.secretAccessor) IAM 角色。

  3. 如果这些角色不存在,请按照此

    文档并提供所需的角色。

© www.soinside.com 2019 - 2024. All rights reserved.