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

gcloud - no permissions for any API even though I am owner and works fine through web UI

我是我新创建的组织的所有者,我在该组织下创建了一个项目并将其链接到我有 1000 美元信用的组织计费帐户。通过网络 UI,我能够启动集群、虚拟机、网络...但是当我想通过 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

但我可以在网络 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>

$ 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

使用不同的帐户(和不同的 organization/projects)它完全可以正常工作,但我过去没有设置过那个帐户。我应该怎么办?非常感谢!

更新: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

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

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

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

gcloud init - 如果您想切换 gcloud 以在项目之间工作,这将配置其设置以指向正确的项目。