Google 云部署管理器无法使用 "logging.v2.sink" 创建部署,权限被拒绝

Google cloud deployment manager couldn't create deployment using "logging.v2.sink" by Permission Denied

我使用 Google 云部署管理器部署了 logging.v2.sink,但是部署因权限被拒绝而失败。

问题也发生在this logsink example of Google Cloud Deployment Manager

结果如下:

- code: RESOURCE_ERROR
  location: /deployments/my-project-id/resources/sink
  message: 
{   
    "ResourceType": "logging.v2.sink",
    "ResourceErrorCode": "403",
    "ResourceErrorMessage": {
        "code": 403,
        "message": "The\n    caller does not have permission",
        "status": "PERMISSION_DENIED",
        "statusMessage": "Forbidden",
        "requestPath": "https://logging.googleapis.com/v2/projects/my-project-id/sinks",
        "httpMethod": "POST"   
    }
}

部署是由所有者角色执行的,而且我可以使用 cli 创建日志接收器。 gcloud安装在本地是最新的(v217.0.0)。

为什么会出现这个问题?

我误解了云部署管理器的权限。 我发现部署模板和创建资源的账号不一样(https://cloud.google.com/deployment-manager/docs/access-control).

当我将 Logging Admin 角色添加到服务帐户时,部署成功。

[PROJECT_NUMBER]@cloudservices.gserviceaccount.com

运行成同样的问题。详细说明上面的答案:

部署管理器使用 [PROJECT_NUMBER]@cloudservices.gserviceaccount.com 代表您创建资源。您可以检查此服务帐户的策略绑定:

gcloud projects get-iam-policy [PROJECT_NUMBER]

默认情况下,此服务帐户在项目上有 roles/editor,它具有以下日志接收器策略:

- logging.sinks.get
- logging.sinks.list

您可以使用以下命令确认这一点: gcloud iam roles describe roles/editor

roles/logging.configWriter 具有 logging.sinks.{list, create, get, update, delete} 权限,因此您可以向项目添加新的策略绑定,然后重试:

gcloud projects add-iam-policy-binding secstate-gcp-test02 \
--member serviceAccount:[PROJECT_ID]@cloudservices.gserviceaccount.com \
--role roles/logging.configWriter