代码之家  ›  专栏  ›  技术社区  ›  Jan

GCP部署管理器:403没有存储。水桶。得以进入

  •  6
  • Jan  · 技术社区  · 6 年前

    我试图使用部署管理器创建一个bucket,但当我想创建部署时,出现以下错误:

    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
    

    我的部署模板:

    水桶金贾

    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
    

    职位。yml公司

    imports:
      - path: bucket.jinja
    
    resources:
    - name: posts
      type: bucket.jinja
      properties:
        name: posts
        datatype: posts
    
    1 回复  |  直到 6 年前
        1
  •  6
  •   GalloCedrone    6 年前

    我成功地测试了您的代码,我认为问题在于您试图创建/更新属于不同项目的不同用户拥有的bucket,而您的服务帐户对此没有权限。

    因此,请尝试重新部署更改可能是唯一的名称,并让我知道这是否解决了问题。在某些情况下,这可能是一个问题,因为您选择的名称很长,或者已经存在风险。


    注意 您必须更改bucket的名称,因为它必须 unique across all the project 在所有用户中。

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

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

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


    注意 如果从服务帐户中删除权限 请勿 收到消息,告诉您服务帐户在bucket上没有任何电源:

    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
    

    注意 如果你试图创建一个你已经拥有的bucket,那就没有问题了。

    $ 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  []
    
    推荐文章