You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

按官方教程配置后Pulumi仍未使用指定GCP服务账号的问题

问题:Pulumi配置GCP服务账号密钥后权限拒绝,环境变量方式却正常

问题详情

  • 已按官方教程配置GCP服务账号密钥,执行命令:
pulumi --config-file stacks/Pulumi.dev-core.yaml \
   -s dev-core config \
   set gcp:credentials ./stacks/dec.sa-pulumi-dev-keys.json    
  • 该服务账号拥有Cloud KMS CryptoKey Encrypter/Decrypter角色,执行加密配置命令时触发权限拒绝:
pulumi config set --path stack:data.test-foo-bar --secret “testvalue” --config-file stacks/Pulumi.dev-core.yaml
  • 错误信息:
error: secrets (code=PermissionDenied): rpc error: code = PermissionDenied 
desc = Permission 'cloudkms.cryptoKeyVersions.useToDecrypt' 
denied on resource 'projects/example/locations/global/keyRings/example/cryptoKeys/my-key' 
(or it may not exist).
  • 确认资源路径存在,当前配置文件内容:
config:
  gcp:credentials: ./stacks/dec.sa-dev-pulumi-keys.json # file is gitignored must be downloaded from lastpass
  gcp:impersonateServiceAccount: my-sa@example.iam.gserviceaccount.com
  • 改用环境变量设置密钥则可正常执行:
export GOOGLE_CREDENTIALS=$(cat stacks/dec.sa-dev-pulumi-keys.json)  
# now it works
pulumi config set --path stack:data.test-foo-bar --secret “testvalue” --config-file stacks/Pulumi.dev-core.yaml
  • 疑问:多栈多环境下环境变量方式扩展性差,为何最初的配置命令无法生效?

原因分析

  1. Pulumi配置优先级冲突:当配置中同时存在gcp:credentials和gcp:impersonateServiceAccount时,Pulumi会优先启用服务账号身份模拟,实际使用的是my-sa@example.iam.gserviceaccount.com,而非gcp:credentials指定的密钥对应的账号。
  2. 模拟账号权限不足:你给密钥对应的账号配置了KMS角色,但被模拟的my-sa@example.iam.gserviceaccount.com没有cloudkms.cryptoKeyVersions.useToDecrypt权限,导致操作失败。
  3. 环境变量优先级更高:通过GOOGLE_CREDENTIALS环境变量设置密钥时,Pulumi会忽略配置中的身份模拟设置,直接使用环境变量对应的账号执行操作,因此权限验证通过。

解决方案

  • 给模拟账号补全权限:为my-sa@example.iam.gserviceaccount.com添加Cloud KMS CryptoKey Encrypter/Decrypter角色,确保其具备KMS操作权限。
  • 移除身份模拟配置:如果不需要服务账号模拟,删除配置文件中的gcp:impersonateServiceAccount项,让Pulumi直接使用gcp:credentials指定的密钥文件。
  • 明确身份使用规则:若必须保留模拟配置,执行pulumi config set gcp:useImpersonatedCredentials true,确保Pulumi正确使用模拟账号权限(前提是已给模拟账号配置好对应权限)。

内容的提问来源于stack exchange,提问作者CommonSenseCode

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:12:58