gcloud - 即使我是所有者并且通过 Web UI 工作正常,也没有任何 API 的权限

kot*_*rfa 2 google-cloud-platform gcloud

我是我新创建的组织的所有者,我在该组织下创建了一个项目,并将其链接到我有 1000 美元积分的组织计费帐户。通过网络用户界面,我能够启动集群、虚拟机、网络......但是当我想通过 gcloud 这样做时,我的权限被拒绝。例如:

$ gcloud compute networks list
API [compute.googleapis.com] not enabled on project [XXX]. 
Would you like to enable and retry (this will take a few minutes)? 
(y/N)?  y

ERROR: (gcloud.compute.networks.create) PERMISSION_DENIED: The caller does not have permission
Run Code Online (Sandbox Code Playgroud)

但是我可以在 Web UI GCP 中看到 API 已明确启用(并且可以使用),只是 gcloud 不允许我使用它们。gcloud 下的帐户与我在 Web 控制台中使用的帐户完全相同 - 由gcloud auth list和验证:

$ gcloud config configurations describe myproject
is_active: true
name: myproject
properties:
  compute:
    region: europe-west1
    zone: europe-west1-b
  core:
    account: <my-email>
    project: <the-project-I-want>

Run Code Online (Sandbox Code Playgroud)

或者

$ gcloud services list
ERROR: (gcloud.services.list) User [<myusername>] does not have permission to access project [myproject] (or it may not exist): The caller does not have permission
Run Code Online (Sandbox Code Playgroud)

它适用于不同的帐户(和不同的组织/项目),但我过去没有设置过。我该怎么办?非常感谢!

更新: 之后gcloud init,至少gcloud services list开始工作了。但其余的没有:

$ gcloud services list
NAME                              TITLE
bigquery-json.googleapis.com      BigQuery API
cloudapis.googleapis.com          Google Cloud APIs
clouddebugger.googleapis.com      Stackdriver Debugger API
cloudtrace.googleapis.com         Stackdriver Trace API
compute.googleapis.com            Compute Engine API
container.googleapis.com          Kubernetes Engine API
containerregistry.googleapis.com  Container Registry API
datastore.googleapis.com          Cloud Datastore API
logging.googleapis.com            Stackdriver Logging API
monitoring.googleapis.com         Stackdriver Monitoring API
oslogin.googleapis.com            Cloud OS Login API
pubsub.googleapis.com             Cloud Pub/Sub API
servicemanagement.googleapis.com  Service Management API
serviceusage.googleapis.com       Service Usage API
sql-component.googleapis.com      Cloud SQL
storage-api.googleapis.com        Google Cloud Storage JSON API
storage-component.googleapis.com  Google Cloud Storage
$ gcloud compute networks create testing-net --subnet-mode=custom '--description=Network to host testing kubernetes cluster'

API [compute.googleapis.com] not enabled on project [{PROJECT_ID}]. 
Would you like to enable and retry (this will take a few minutes)? 
(y/N)?  y

ERROR: (gcloud.compute.networks.create) PERMISSION_DENIED: The caller does not have permission

Run Code Online (Sandbox Code Playgroud)

^PROJECT_ID以上显示的是我所在组织的 ID,而不是该组织下的实际项目。

kot*_*rfa 8

所以问题是我使用了错误的project_id时间gcloud config set project并且 gcloud 由于某种原因默认为组织。

所以我必须找到正确的项目 ID gcloud projects list,然后使用gcloud config set project {PROJECT-ID}不是项目名称!)