Google Cloud IAM中缺少Cloud Function用户代理角色

时间:2018-12-27 22:42:23

标签: google-cloud-platform google-cloud-functions google-iam

我正在一个Google Cloud项目中处理一系列Cloud Functions,由于某种原因,我突然收到此错误:

Deployment failure:
Missing necessary permission resourcemanager.projects.getIamPolicy for service-1092904037961@gcf-admin-robot.iam.gserviceaccount.com on resource projects/la-cloud-functions. Please grant service-1092904037961@gcf-admin-robot.iam.gserviceaccount.com the Cloud Functions Service Agent role. You can do that by running 'gcloud iam service-accounts add-iam-policy-binding projects/la-cloud-functions --member=service-1092904037961@gcf-admin-robot.iam.gserviceaccount.com --role=Cloud Functions Service Agent'

当我尝试运行修改后的命令时,除了格式错误的错误响应(您不能使用--role=Cloud Functions Service Agent-应该为--role=roles/cloudfunctions.serviceAgent)之外

gcloud iam service-accounts add-iam-policy-binding projects/la-cloud-functions --member=service-1092904037961@gcf-admin-robot.iam.gserviceaccount.com --role=roles/cloudfunctions.serviceAgent

我收到此错误:

The requested URL <code>/v1/projects/la-cloud-functions/serviceAccounts/projects/la-cloud-functions:getIamPolicy?alt=json</code> was not found on this server.

最后,尝试通过控制台分配Cloud Functions Server Agent角色给了我另一个惊喜-该角色从列表中丢失了,应该在服务管理下:

enter image description here

我尝试通过使用以下命令重新启用Cloud Functions API来重置服务帐户:

gcloud services enable cloudfunctions.googleapis.com

但还是没有成功。

任何人都对如何解决此问题并使Cloud Functions Service Agent角色再次可用有任何想法?

TIA-乔

1 个答案:

答案 0 :(得分:3)

尝试以下步骤解决此问题:

禁用云功能API:

gcloud services disable cloudfunctions.googleapis.com --project la-cloud-functions

请等待大约一分钟以完成禁用。

使用CLI或IAM下的GCP控制台删除云功能成员帐户。

gcloud projects remove-iam-policy-binding la-cloud-functions --member="serviceAccount:service-1092904037961@gcf-admin-robot.iam.gserviceaccount.com" --role="roles/cloudfunctions.serviceAgent"

等待大约一分钟。然后,在IAM下的GCP控制台中确认已删除该成员。

启用云功能API:

gcloud services enable cloudfunctions.googleapis.com --project la-cloud-functions

返回GCP控制台。您应该找到一个新的Google Cloud Functions Service代理成员。

注意:

您使用错误的命令添加了cloudfunctions.serviceAgent。这是正确的命令:

gcloud projects add-iam-policy-binding la-cloud-functions --member="serviceAccount:service-1092904037961@gcf-admin-robot.iam.gserviceaccount.com" --role="roles/cloudfunctions.serviceAgent"