使用特定服务帐户部署功能时(gcloud.functions.deploy)权限被拒绝

时间:2019-08-06 22:05:48

标签: function deployment gcloud

我正在尝试使用其他服务帐户来部署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激活服务帐户mynewserviceaccount@appspot.gserviceaccount.com-密钥文件“ /path/to/keys/mynewserviceaccount.json”

运行此命令时,我得到:     错误:(gcloud.functions.deploy)ResponseError:状态= [403],代码= [禁止],消息= [呼叫者没有权限]

当我尝试在“角色”列表中找到“ gcloud.functions.deploy”时,看不到它。我不知道这是文档问题还是代码问题。

2 个答案:

答案 0 :(得分:2)

如果这是在运行 gcloud builds submit 命令时,最可能的原因是 Cloud Functions Developer 角色没有为 Cloud Build 服务启用。

  1. 导航到 Cloud Build > 设置
  2. 启用 Cloud Functions 开发者角色

enter image description here

答案 1 :(得分:0)

关于云功能的Docs指出,如果要使用服务帐户部署功能,则必须执行额外的步骤。

您必须在Cloud Functions Runtime服务帐户上为用户分配IAM服务帐户用户角色(roles / iam.serviceAccountUser)