我正在尝试使用不同的服务帐户部署 Google Cloud Functions。我将服务帐户属性保存到 json 文件中。我换掉了这些值以使其更易于阅读。
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keys/mynewserviceaccount.json"
gcloud functions deploy MyFunction \
--runtime python37 \
--entry-point MyFunction \
--source src \
--service-account mynewserviceaccount@appspot.gserviceaccount.com \
--verbosity debug \
--stage-bucket staging.projectname.appspot.com \
--trigger-event providers/cloud.firestore/eventTypes/document.write \
--trigger-resource "projects/projectname/databases/(default)/documents/User/{userId}" &
mynewserviceaccount 具有以下角色。我已经尝试了其他一些,但都没有成功。
- 云功能管理员
- 云功能服务代理
- 错误作家
- 服务帐户用户
- 日志编写器
- 发布/订阅订阅者
我也跑过
gcloud auth activate-service-account mynewserviceaccount@appspot.gserviceaccount.com --key-file "/path/to/keys/mynewserviceaccount.json"
当我运行这个时,我得到:
ERROR: (gcloud.functions.deploy) ResponseError: status=[403], code=[Forbidden], message=[调用者没有权限]
当我尝试在角色列表中查找“gcloud.functions.deploy”时,我没有看到它。我不知道这是文档问题还是代码问题。
最佳答案
Docs关于云函数指出,如果您想使用服务帐户部署函数,则必须执行额外的步骤。
您必须为用户分配 Cloud Functions Runtime 服务账户上的 IAM 服务账户用户角色 (roles/iam.serviceAccountUser)。
关于function - (gcloud.functions.deploy) 使用特定服务帐户部署功能时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57384609/