1

运行部署管理器以创建部署时,我从 GCP 收到 403 PERMISSION_DENIED 响应,该部署创建服务帐户并使用云资源管理器 API 为其设置 IAM 策略。这是 setIamPolicy 模板:

{
        'resources': [
            {
                'name': context.env['name'],
                'action': 'gcp-types/cloudresourcemanager-v1:cloudresourcemanager.projects.setIamPolicy',
                'properties': {
                    'resource': context.properties['resource'],
                    'policy': {
                        'bindings': context.properties['bindings']
                    }
                }
            }
        ]
    }

来自 GCP 的回应:

'{"ResourceType":"gcp-types/cloudresourcemanager-v1:cloudresourcemanager.projects.setIamPolicy","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"message":"调用者没有有权限","status":"PERMISSION_DENIED","statusMessage":"Forbidden","re​​questPath":" https://cloudresourcemanager.googleapis.com/v1/projects/project-name@project-name.iam.gserviceaccount .com:setIamPolicy ","httpMethod":"POST"}}'

仅供参考:机器人帐户 (12345@cloudservices.gserviceaccount.com) 在 IAM 中被授予项目所有者权限。

4

1 回答 1

2

正确的做法是:

    {
        # Set the IAM policy by patching the existing policy with the
        # config contents.
        'name': policy_add_name,
        'action': 'gcp-types/cloudresourcemanager-v1:cloudresourcemanager.projects.setIamPolicy',
        'properties':
            {
                'resource': project_id,
                'policy': '$(ref.' + policy_get_name + ')',
                'gcpIamPolicyPatch': {
                    'add': policies_to_add,
                }
            }
    }
于 2018-11-06T18:15:41.720 回答