无法从 Google Cloud Function 访问存储在 Secrets Manager 中的密钥

2023-11-26

在测试我编写的尝试访问存储在 Secret Manager 中的密钥的 Google Cloud Function 时,出现以下错误:Error: 7 PERMISSION_DENIED: Permission 'secretmanager.versions.access' denied for resource '<resource-name>' (or it may not exist).

My code:

const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
const secretClient = new SecretManagerServiceClient();

...

const [version] = await secretClient.accessSecretVersion({
  name: secretName
});
const secret = version.payload.data.toString();

我已按照文档中的步骤操作,在服务调用中指定密钥的全名(projects/<project-id>/secrets/<secret-name>/versions/latest,所以问题在无法访问 GCP Secret Manager 中的密钥此处不适用),并为运行我的云功能的服务帐户提供“Secret Manager Secret Accessor”角色(这应该排除中的根本问题)为什么我的 Firebase 应用无法连接到 Google Secret Manager?).

我在尝试使用curl 在本地触发该函数时以及在UI 中测试该函数时(GCF > 函数详细信息> 测试)都看到了此问题。

我在这里缺少什么吗?


事实证明,我将“Secret Manager Secret Accessor”角色赋予了错误的服务帐户 - 我将其赋予了GCF 管理服务帐户,用于创建/更新/删除函数(service-<project-id>@gcf-admin-robot.iam.gserviceaccount.com)而不是运行时服务帐户,这就是实际用于运行该函数的内容(<project-id>@appspot.gserviceaccount.com).

将上述角色(以及所需的功能)添加到运行时服务帐户后,该功能成功完成。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法从 Google Cloud Function 访问存储在 Secrets Manager 中的密钥 的相关文章

随机推荐