简体   繁体   English

使用服务帐号将 GCP 项目关联到结算帐号

[英]Link a GCP project to a billing account using a service account

I'm trying to create a new project using GCP's API and link it to a billing account.我正在尝试使用 GCP 的 API 创建一个新项目并将其链接到计费帐户。

I have a service account I use to authenticate to GCP, this service account is a part of project1 .我有一个用于向 GCP 进行身份验证的服务帐户,该服务帐户是project1的一部分。

This service account has the following permission on the organization level:此服务帐号在组织级别具有以下权限:

  • Billing Account User结算帐号用户
  • Project Billing Manager项目计费经理

I also tried to give this service account Organization Administrator , which didn't help as it isn't a permissions issue.我还尝试提供此服务帐户Organization Administrator ,这没有帮助,因为它不是权限问题。

Using the API I've created a new project - project 2 , and I was able to enable Cloud Billing API and Deployment Manager API for project 2 .使用 API 我创建了一个新项目 - project 2 ,并且我能够为project 2启用云计费 API 和部署管理器 API 。

For some reason, when I'm trying to follow the API reference on how to enable billing for a GCP project, the request fails with 403 (Permission Denied).出于某种原因,当我尝试遵循有关如何为 GCP 项目启用计费的API 参考时,请求失败并显示 403(权限被拒绝)。

Here is a sample request I'm trying to make:这是我正在尝试提出的示例请求:

curl --location --request PUT 'https://cloudbilling.googleapis.com/v1/projects/project2/billingInfo' --header 'Authorization: Bearer ya29.blablabla' --header 'Content-Type: application/json' --data-raw '{"billingAccountName": "billingAccounts/1234-9248-4321"}'

The reason this request fails is that for some reason it is trying to link project1 (where the service account resides) to this billing account instead of project2 .此请求失败的原因是由于某种原因它试图将project1 (服务帐户所在的位置)链接到此计费帐户而不是project2

Here is the response I'm getting:这是我得到的回复:

{ "error": { "code": 403, "message": "Cloud Billing API has not been used in project project1_number before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=project1_number then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.", "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com/google.rpc.Help", "links": [ { "description": "Google developers console API activation", "url": "https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=project1_number" } ] }, { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "SERVICE_DISABLED", "domain": "googleapis.com", "metadata": { "service": "cloudbilling.googleapis.com", "consumer": "projects/project1_number" } { "error": { "code": 403, "message": "Cloud Billing API 之前没有在项目 project1_number 中使用或被禁用。通过访问https://console.developers.google.com/apis启用它/api/cloudbilling.googleapis.com/overview?project=project1_number然后重试。如果您最近启用了此 API,请等待几分钟让该操作传播到我们的系统并重试。", "status": "PERMISSION_DENIED", " details": [ { "@type": "type.googleapis.com/google.rpc.Help", "links": [ { "description": "Google 开发者控制台 API 激活", "url": "https:// /console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=project1_number" } ] }, { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "原因”:“SERVICE_DISABLED”、“域”:“googleapis.com”、“元数据”:{“服务”:“cloudbilling.googleapis.com”、“消费者”:“projects/project1_number”} } ] } } } ] } }

If I'm trying to enable the billing API for project1 , I'm starting to get 400's with "Unexpected token" message.如果我尝试为project1启用计费 API ,我开始收到 400 个“意外令牌”消息。

Is there a way (using the API) to link project2 to my billing account using a service account that resides on project1 ?有没有办法(使用 API)使用驻留在project1上的服务帐户将project2链接到我的结算帐户?

You have two problems:你有两个问题:

  1. The Billing API is not enabled.计费 API 未启用。
  2. The service account does not have permission to access the Billing API.服务帐号无权访问 Billing API。

To enable the Billing API, you must use an identity that has the role Service Usage Admin aka roles/serviceusage.serviceUsageAdmin要启用计费 API,您必须使用具有角色Service Usage Admin aka roles/ serviceusage.serviceUsageAdmin 的身份

Use the Google Cloud Console GUI or use the CLI example:使用 Google Cloud Console GUI 或使用 CLI 示例:

gcloud services enable cloudbilling.googleapis.com

Is there a way (using the API) to link project2 to my billing account using a service account that resides on project1?有没有办法(使用 API)使用驻留在 project1 上的服务帐户将 project2 链接到我的结算帐户?

Using an API, No. Using the GUI, Yes.使用 API,否。使用 GUI,是。 To allow a service account to access a Billing Account you must complete this task in the Billing Account GUI.要允许服务帐户访问计费帐户,您必须在计费帐户 GUI 中完成此任务。 For personal Google Cloud Accounts, you cannot add additional members (the limit is one identity).对于个人 Google Cloud 帐户,您不能添加其他成员(限制为一个身份)。

Tip: If you are expecting to be able to access billing data, you will not be able to.提示:如果您希望能够访问计费数据,您将无法访问。 Instead, enable Google Cloud Billing export to BigQuery and then execute queries to retrieve billing data.相反,启用 Google Cloud Billing 导出到 BigQuery,然后执行查询以检索结算数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式更新Google Cloud Project上的结算帐户? - Update billing account on google cloud project programmatically? GCP:无法从 Java 尝试 Cloud Billing Account API - GCP: Unable to try Cloud Billing Account API from Java tmforum open-api 账户管理服务规范中的计费账户和财务账户有什么区别 - what is the difference between billing account and financial account in tmforum open-api account management service specs 使用服务帐户访问 SharePoint 文件夹 - Access SharePoint Folder using Service account 为项目创建OAuth 2.0服务帐户客户端ID时出错 - Error when creating OAuth 2.0 Service Account client ID for a Project GCP 数据丢失防护 API 身份验证:是否需要使用服务帐户? - GCP Data Loss Prevention API Authentication: Does it require the use of a service account? 尝试使用帐户服务从Gmail帐户读取Gsuite中的公司电子邮件时出现401未经授权的错误 - 401 Unauthorized Error when trying to read corporative emails in Gsuite from a Gmail account using Account Service 将帐户与Xbox Live Gamertag关联? - Link an account with Xbox Live Gamertag? NodeJS Patreon API帐户链接 - NodeJS Patreon API account link 如何使用PHP的服务帐户将文件上传到Google云端硬盘? - How to upload a file to Google Drive using Service Account in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM