【问题标题】:GCP Deployment Manager: 403 does not have storage.buckets.get accessGCP 部署管理器:403 没有 storage.buckets.get 访问权限
【发布时间】:2018-05-06 11:38:32
【问题描述】:

我正在尝试使用部署管理器创建存储桶,但是当我想创建部署时,我收到以下错误:

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1525606425901-56b87ed1537c9-70ca4aca-72406eee]: errors:
- code: RESOURCE_ERROR
  location: /deployments/posts/resources/posts
  message: '{"ResourceType":"storage.v1.bucket","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"errors":[{"domain":"global","message":"myprojectid@cloudservices.gserviceaccount.com
    does not have storage.buckets.get access to posts.","reason":"forbidden"}],"message":"myprojectid@cloudservices.gserviceaccount.com
    does not have storage.buckets.get access to posts.","statusMessage":"Forbidden","requestPath":"https://www.googleapis.com/storage/v1/b/posts","httpMethod":"GET","suggestion":"Consider
    granting permissions to myprojectid@cloudservices.gserviceaccount.com"}}'

如果我理解正确,部署管理器使用服务帐户(如消息中所述)来实际创建我的所有资源。我检查了 IAM 并确保服务角色 (myprojectid@cloudservices.gserviceaccount.com) 确实可以作为“编辑器”访问,甚至添加了“存储管理员”(包括 storage.buckets.get)以更加确定。但是,我仍然收到相同的错误消息。

我是否将权限分配给了错误的 IAM 用户/我做错了什么?


使用的命令:

gcloud deployment-manager deployments create posts --config posts.yml

我的部署模板:

bucket.jinja

resources:
- name: {{ properties['name'] }}
  type: storage.v1.bucket
  properties:
    name: {{ properties['name'] }}
    location: europe-west1
    lifecycle:
      rule:
      - action:
          type: Delete
        condition:
          age: 30
          isLive: true
    labels:
      datatype: {{ properties['datatype'] }}
    storageClass: REGIONAL

posts.yml

imports:
  - path: bucket.jinja

resources:
- name: posts
  type: bucket.jinja
  properties:
    name: posts
    datatype: posts

【问题讨论】:

  • 我也遇到了同样的问题!我的天啊。奇怪的是 Deployer manager 成功创建了第一个 bucket。之后我得到相同的 403
  • @Fabrizio 你能检查一下这是问题所在吗?
  • @GalloCedrone 你是最棒的!非常感谢您的回答,我也是这样

标签: google-cloud-platform google-cloud-storage google-iam google-deployment-manager


【解决方案1】:

我成功测试了您的代码,我认为问题在于您试图创建/更新属于您的服务帐户无权访问的不同项目的不同用户拥有的存储桶。

因此,请尝试重新部署更改可能是唯一名称的名称,如果这样可以解决问题,请告诉我。在某些情况下,这可能是一个问题,因为您选择的名称很长,或者已经承担了风险。


注意,您必须更改存储桶的名称,因为它必须是所有用户中的unique across all the project

这似乎是一个过度的要求,但它可以创建静态网站或使用标准 URL 引用文件:

  • https://storage.googleapis.com/nomebucket/folder/nomefile

从跟踪错误我认为这是问题所在,您正在尝试创建一个不存在且您不拥有的存储桶。


注意,如果您从服务帐户中删除权限,您不会收到告诉您服务帐户对存储桶没有任何权力的消息:

xxx@cloudservices.gserviceaccount.com does not have storage.buckets.get access to posts.

而是一条消息指出服务帐户对项目没有权力:

Service account xxx@cloudservices.gserviceaccount.com is not authorized
    to take actions for project xxx. Please add xxx@cloudservices.gserviceaccount.com
    as an editor under project xxx using Google Developers Console

注意,如果您尝试创建一个您已经拥有的存储桶,则没有问题。

$ gcloud deployment-manager deployments create posts22 --config posts.yml                                                                                             
The fingerprint of the deployment is xxx==
Waiting for create [operation-xxx-xxx-xxx-xxx]...done.
Create operation operation-xxx-xxx-xxx-xxx completed successfully.
NAME                  TYPE               STATE      ERRORS  INTENT
nomebuckettest4536  storage.v1.bucket  COMPLETED  []

【讨论】:

  • 看来你是对的!谢谢。再次阅读它是有道理的,但我仍然希望错误消息更清楚一点,问题可能是存储桶名称。谢谢!
  • 这完全是因为 GCS 存储桶是一个真正的全局命名空间(不是项目范围),所有“好”的名称(例如 posts)可能都是几年前使用的。
  • 这也发生在我身上..我没有意识到我试图创建的存储桶名称已经存在于另一个项目中
猜你喜欢
  • 2020-12-03
  • 2023-02-21
  • 2019-08-08
  • 1970-01-01
  • 1970-01-01
  • 2019-08-21
  • 2018-09-16
  • 2021-01-01
  • 2016-01-27
相关资源
最近更新 更多