即使授予了正确的角色,GCP Cloud Build 也会因权限错误而失败
GCP Cloud Build fails with permissions error even though correct role is granted
我在我的 GCP 项目中设置了 Cloud Build Trigger,以便通过 .yaml 文件从 Cloud Source Repository 部署 Cloud Function。一切似乎都已正确设置 permissions granted according to the official documentation,但是当我通过 运行 手动测试触发器时,出现以下错误:
ERROR: (gcloud.functions.deploy) ResponseError: status=[403], code=[Forbidden], message=[Missing necessary permission iam.serviceAccounts.actAs for on resource [MY_SERVICE_ACCOUNT]. Please grant the roles/iam.serviceAccountUser role. You can do that by running 'gcloud iam service-accounts add-iam-policy-binding [MY_SERVICE_ACCOUNT] --member= --role=roles/iam.serviceAccountUser']
现在首先,运行 建议的命令甚至不起作用,因为建议的语法错误(缺少 "member=" 的值)。但更重要的是,我已经将该角色添加到错误消息所抱怨的服务帐户中。我尝试从 UI 和 CLI 中删除它,然后将其添加回来,但仍然始终显示此错误。
为什么?
经过反复试验,我弄明白了。该文档似乎不正确(缺少一些额外的必要权限)。我用 到达那里。
简而言之,您还需要将cloudfunctions.developer
和iam.serviceAccountUser
角色添加到[PROJECT_NUMBER]@cloudbuild.gserviceaccount.com
帐户中,并且(我相信)上述cloudbuild服务帐户也需要添加为有权部署您的 Cloud Function 的服务帐户的成员(再次显示在链接的 SO 答案中)。
文档确实应该反映这一点。
祝你好运!
我在我的 GCP 项目中设置了 Cloud Build Trigger,以便通过 .yaml 文件从 Cloud Source Repository 部署 Cloud Function。一切似乎都已正确设置 permissions granted according to the official documentation,但是当我通过 运行 手动测试触发器时,出现以下错误:
ERROR: (gcloud.functions.deploy) ResponseError: status=[403], code=[Forbidden], message=[Missing necessary permission iam.serviceAccounts.actAs for on resource [MY_SERVICE_ACCOUNT]. Please grant the roles/iam.serviceAccountUser role. You can do that by running 'gcloud iam service-accounts add-iam-policy-binding [MY_SERVICE_ACCOUNT] --member= --role=roles/iam.serviceAccountUser']
现在首先,运行 建议的命令甚至不起作用,因为建议的语法错误(缺少 "member=" 的值)。但更重要的是,我已经将该角色添加到错误消息所抱怨的服务帐户中。我尝试从 UI 和 CLI 中删除它,然后将其添加回来,但仍然始终显示此错误。
为什么?
经过反复试验,我弄明白了。该文档似乎不正确(缺少一些额外的必要权限)。我用
简而言之,您还需要将cloudfunctions.developer
和iam.serviceAccountUser
角色添加到[PROJECT_NUMBER]@cloudbuild.gserviceaccount.com
帐户中,并且(我相信)上述cloudbuild服务帐户也需要添加为有权部署您的 Cloud Function 的服务帐户的成员(再次显示在链接的 SO 答案中)。
文档确实应该反映这一点。
祝你好运!