【发布时间】:2019-05-08 10:56:39
【问题描述】:
我想为客户端创建 GCP 的自动部署。
为了做到这一点,我打开了一个页面让他们使用 google 登录,然后启用了 IAM API 和 Service Usage API。
然后我创建了一个服务帐户,我想从现在开始使用它来按需启用其他所需的 API,而不是一次性启用。
当我尝试启用 cloudkms API 时,我得到了
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://serviceusage.googleapis.com/v1/projects/x-y-z/services/cloudkms.googleapis.com?alt=json returned "The caller does not have permission"
我尝试使用根据创建服务帐户的响应创建的服务帐户凭据 (google.auth.jwt.Credentials),并添加了所有必需的权限。我不想将角色所有者授予服务帐号,因为我希望该帐号拥有尽可能少的权限。
当我尝试使用用户权限获取 cloudkms API 的状态时,它可以工作。
我已经看到一些解决方案解决了我需要为服务帐户创建凭据的问题:https://console.developers.google.com/apis/credentials,但我也确实需要以编程方式执行此操作。
我的代码:
credentials = jwt.Credentials.from_service_account_file(service_account_info['email'] + '.json', audience="https://www.googleapis.com/auth/cloud-platform")
# credentials = GoogleCredentials.get_application_default() - it works with this
service_usage = googleapiclient.discovery.build('serviceusage', 'v1', credentials=credentials)
service_usage.services().get(name="projects/<project_id>/services/cloudkms.googleapis.com").execute()
上面提到了错误。
【问题讨论】:
标签: python authentication google-cloud-platform google-cloud-iam google-auth-library