google-cloud-platform - 无法从 Google Cloud Function 访问存储在 Secrets Manager 中的密钥
问题描述
在测试我编写的尝试访问存储在 Secret Manager 中的密钥的 Google Cloud 函数时,我收到此错误:Error: 7 PERMISSION_DENIED: Permission 'secretmanager.versions.access' denied for resource '<resource-name>' (or it may not exist).
我的代码:
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 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
) 的内容。
一旦我将上述角色(以及所需的功能)添加到运行时服务帐户,该功能就成功完成了。
推荐阅读
- spring-boot - 在运行时从 Google Cloud Storage 刷新 Spring 资源
- vb.net - 如何通过设置时间限制和不包括周末来汇总 DateTime 小时数
- python - 为什么机器人不按时加入?
- laravel - 我想按组织 ID 显示所有具有用户分数的用户
- git - 个人访问令牌生成后 Git 不允许拉取请求
- c++ - 我可以根据它是用作左值还是右值来为返回引用的函数运行不同的逻辑吗?
- django - 在模板中使用 Django StreamingHttpResponse
- flutter - 如何将 BloC AppTheme 的 id 放入颤动并防止主题重新启动
- android - Android 应用程序给出错误 W/BroadcastQueueInjector
- java - Android 流媒体音频延迟随着时间的推移而增加