简体   繁体   English

谷歌云平台服务帐号无法访问项目

[英]Google Cloud Platform Service Account is Unable to Access Project

I encounter the following warning:我遇到以下警告:

WARNING: You do not appear to have access to project [$PROJECT] or it does not exist.警告:您似乎无权访问项目 [$PROJECT] 或它不存在。

after running the following commands locally:在本地运行以下命令后:

  1. Activate and set a service account:激活并设置服务帐户:

     gcloud auth activate-service-account \ $SERVICE_ACCOUNT \ --key-file=key.json #=> Activated service account credentials for: [$SERVICE_ACCOUNT]
  2. Select $PROJECT as the above service account: Select $PROJECT作为上述服务帐户:

     gcloud config set project $PROJECT #=> Updated property [core/project]. WARNING: You do not appear to have access to project [$PROJECT] or it does not exist.

My own GCP account is associated with the following roles:我自己的 GCP 帐户与以下角色相关联:

  • App Engine Admin App 引擎管理员
  • Cloud Build Editor云构建编辑器
  • Cloud Scheduler Admin云调度器管理员
  • Storage Object Creator存储 Object 创建者
  • Storage Object Viewer存储 Object 查看器

Why is this service account unable to set $PROJECT ?为什么此服务帐户无法set $PROJECT Is there a role or permission I am missing?是否有我缺少的角色或权限?

The solution to this issue might be to enable Cloud Resource Manager api in your Google Cloud Console.此问题的解决方案可能是在您的 Google Cloud Console 中启用Cloud Resource Manager api。 Go to https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=<project-id> and click enable. Go 到https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=<project-id>并单击启用。

I believe this is an erroneous warning message.我相信这是一个错误的警告信息。 I see the same warning message on my service account despite the fact that the account has permissions on my GCP project and can successfully perform necessary actions.尽管该帐户对我的 GCP 项目具有权限并且可以成功执行必要的操作,但我在我的服务帐户上看到了相同的警告消息。

You might be seeing this error due to an unrelated problem.由于不相关的问题,您可能会看到此错误。 In my case, I was trying to deploy to AppEngine from a continuous integration environment (Circle CI), but I hadn't enabled the App Engine Admin API .就我而言,我试图从持续集成环境 (Circle CI) 部署到 AppEngine,但我没有启用App Engine Admin API Once I enabled the API, I was able to deploy successfully.启用 API 后,我就能够成功部署。

I encountered this error when I started out with Google CLoud Platform.我在开始使用 Google CLoud Platform 时遇到了这个错误。

The issue was that I configured/set a non-existing project ( my-kube-project ) as my default project using the command below:问题是我使用以下命令配置/设置了一个不存在的项目( my-kube-project )作为我的默认项目:

gcloud config set project my-kube-project

Here's how I solved it :这是我解决它的方法

I had to list my existing projects first:我必须首先列出我现有的项目:

gcloud projects list

And then I copied the ID of the project that I wanted, and rannthe command again this time:然后我复制了我想要的项目的ID,这次再次运行命令:

gcloud config set project gold-magpie-258213

And it worked fine.它工作得很好。

Note : You cannot change the ID of a project's ID or Number ,you can only change the Name .注意:您不能更改项目的ID编号的 ID,您只能更改名称

That's all.就这样。

I hope this helps我希望这有帮助

I was encountering the same error when trying to deploy an app to Google App Engine via a service account configured in CircleCI and resolved it by having the following roles (permissions) attached to my service role:尝试通过在 CircleCI 中配置的服务帐户将应用程序部署到 Google App Engine 并通过将以下角色(权限)附加到我的服务角色来解决它时,我遇到了同样的错误:

  • App Engine Deployer App Engine 部署程序
  • App Engine Service Admin App Engine 服务管理员
  • Cloud Build Editor云构建编辑器
  • Storage Object Creator存储 Object 创建者
  • Storage Object Viewer存储 Object 查看器

I also had the App Engine Admin API enabled, but not the Cloud Resource Manager API .我还启用了App Engine 管理员 API ,但没有启用云资源管理器 API

Are you passing it like this?你就这样过吗?

gcloud auth activate-service-account [ACCOUNT] --key-file key.json 

Or are you leaving the account blank?还是您将帐户留空? The account has to be the service account that you will use to access.该帐户必须是您将用于访问的服务帐户。 You can also specify the project like this.您也可以像这样指定项目。

gcloud auth activate-service-account [ACCOUNT] --key-file key.json --project=[PROJECT ID]

Let me know.让我知道。

UPDATE:更新:

Just tested it and it works as I mentioned.刚刚测试过它,它就像我提到的那样工作。

You can do either --key-file=key.json or --key-file key.json .您可以执行--key-file=key.json--key-file key.json

The

WARNING: You do not appear to have access to project [$PROJECT_ID] or it does not exist.警告:您似乎无权访问项目 [$PROJECT_ID],或者它不存在。

warning will appear if there isn't at least one role granted to the service account that contains the resourcemanager.projects.get permission.如果没有向包含resourcemanager.projects.get权限的服务帐户授予至少一个角色,则会出现警告。

In other words, the warning will appear if the result of the following commands is blank:换句话说,如果以下命令的结果为空,就会出现警告:

  1. Gather all roles for a given $SERVICE_ACCOUNT (this works for any account, not just service accounts):收集给定$SERVICE_ACCOUNT的所有角色(这适用于任何帐户,而不仅仅是服务帐户):

     gcloud projects get-iam-policy $PROJECT_ID \ --flatten='bindings[].members' \ --format='table(bindings.role)' \ --filter="bindings.members:${SERVICE_ACCOUNT}" #=> ROLE. . .
  2. For each $ROLE gathered above, either:对于上面收集的每个$ROLE ,可以:

     gcloud iam roles describe $ROLE \ --flatten='includedPermissions' \ --format='value(includedPermissions)' \ --project=$PROJECT_ID | grep \ --regexp '^resourcemanager.projects.get$'

    if the $ROLE is a custom ( projects/$PROJECT_ID/roles/$ROLE ), or:如果$ROLE自定义的( projects/$PROJECT_ID/roles/$ROLE ),或者:

     gcloud iam roles describe roles/$ROLE \ --flatten='includedPermissions' \ --format='value(includedPermissions)' | grep \ --regexp '^resourcemanager.projects.get$'

    if the $ROLE is a curated ( roles/$ROLE ).如果$ROLE策划的( roles/$ROLE )。

Note : the difference between gcloud command formatting for custom and curated roles is what makes listing all permissions associated with all roles associated with a single account difficult.注意:自定义角色和精选角色的gcloud命令格式之间的区别在于,难以列出与单个帐户关联的所有角色关联的所有权限。

If you have confirmed that none of the roles associated with a service account contain the resourcemanager.projects.get permission, then either:如果您已确认与服务帐户关联的任何角色都不包含resourcemanager.projects.get权限,则:

  • Update at least one of the custom roles associated with the service account with the resourcemanager.projects.get permission:使用resourcemanager.projects.get权限更新至少一个与服务帐户关联的自定义角色:

     gcloud iam roles update $ROLE \ --add-permissions=resourcemanager.projects.get \ --project=$PROJECT_ID #=> description: $ROLE_DESCRIPTION etag: . . . includedPermissions: . . . - resourcemanager.projects.get. . . name: projects/$PROJECT_ID/roles/$ROLE stage: . . . title: $ROLE_TITLE

    Warning : make sure to use the --add-permissions flag here when updating, as the --permissions flag will remove any other permissions the custom role used to have.警告:确保在更新时在此处使用--add-permissions标志,因为--permissions标志将删除自定义角色曾经拥有的任何其他权限。

  • Create a custom role:创建自定义角色:

     gcloud iam roles create $ROLE \ --description="$ROLE_DESCRIPTION" \ --permissions=resourcemanager.projects.get \ --project=$PROJECT_ID \ --title='$ROLE_TITLE' #=> Created role [$ROLE]. description: $ROLE_DESCRIPTION etag: . . . includedPermissions: - resourcemanager.projects.get name: projects/$PROJECT_ID/roles/$ROLE stage: . . . title: $ROLE_TITLE

    and associate it with the service account:并将其与服务帐户相关联:

     gcloud projects add-iam-policy-binding $PROJECT_ID \ --member=serviceAccount:$SERVICE_ACCOUNT \ --role=projects/$PROJECT_ID/roles/$ROLE #=> Updated IAM policy for project [$PROJECT_ID]. auditConfigs: . . .
  • Associate the service account with a curated role that already contains the resourcemanager.projects.get permission, which has been discussed above.将服务帐户与已包含resourcemanager.projects.get权限的策划角色相关联,这已在上面讨论过。

    If you want to know which curated roles already contain the resourcemanager.projects.get permission and don't want to craft a complex shell loop, it might be easier to go here and filter all roles by Permission:resourcemanager.projects.get .如果您想知道哪些策划角色已经包含resourcemanager.projects.get权限并且不想制作复杂的 shell 循环,则在此处使用 go 并按Permission:resourcemanager.projects.get过滤所有角色可能更容易。

Note : if you are running into issues, be sure to read the requirements for granting access to resources here .注意:如果您遇到问题,请务必阅读此处授予资源访问权限的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Google Cloud Platform 服务帐户的访问权限限制为特定的 Gmail 帐户 - Limiting the access to Google Cloud Platform Service Account to specific Gmail Accounts 升级到 Workspace 帐户后无法访问 Google Cloud Platform - Unable to access Google Cloud Platform after Upgrading to a Workspace Account 无法访问 Cloud 中的 Google Cloud Storage 服务帐户密钥文件 - Unable to access Google Cloud Storage service account key file in Cloud Google Cloud Platform - 使用多个服务帐户 - Google Cloud Platform - Use Multiple Service Account Google Cloud Platform 上的“无效”服务帐号密钥 - "INVALID" Service Account key on Google Cloud Platform Google Maps Platform 无法创建项目(Google Cloud Platform 服务已被禁用) - Google Maps Platform unable to create project (Google Cloud Platform service has been disabled) 如何让 Google Cloud Platform 上的服务帐户访问 Firebase 存储? - How to let service account on Google Cloud Platform to have access to the Firebase Storage? 无法访问 Google Cloud Platform 上的 Kubernetes 仪表板 - Unable to access the Kubernetes Dashboard on Google Cloud Platform 处理管理员对Google Cloud Platform项目的访问 - Handling admin access to a Google Cloud Platform Project 无法创建Google Cloud服务帐户 - Unable to creat a Google Cloud service account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM