按照Google Artifact Registry Quickstart中的说明使用时,我看到了权限错误。如该问题所述,问题似乎归结为访问令牌上缺少范围。在我的本地 shell 中,范围是这些(如 所示):docker push
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=<token>
openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/appengine.admin https://www.googleapis.com/auth/compute https://www.googleapis.com/auth/accounts.reauth
当我在 Cloud Shell 中运行相同的步骤序列时,访问令牌上有更多范围:
https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/appengine.admin https://www.googleapis.com/auth/bigquery https://www.googleapis.com/auth/compute https://www.googleapis.com/auth/devstorage.full_control https://www.googleapis.com/auth/devstorage.read_only https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/ndev.cloudman https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/sqlservice.admin https://www.googleapis.com/auth/prediction https://www.googleapis.com/auth/projecthosting https://www.googleapis.com/auth/source.full_control https://www.googleapis.com/auth/source.read_only https://www.googleapis.com/auth/source.read_write openid"
我无法确定我的 Cloud Shell 配置和我的本地配置之间的差异可能会导致这种范围差异。这些命令都具有相同的输出:
$ gcloud auth list
Credentialed Accounts
ACTIVE: *
ACCOUNT: <my email address>
$ cat ~/.docker/config.json
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud",
"us-central1-docker.pkg.dev": "gcloud"
}
}
gcloud config list
显示这些差异:
// in Cloud Shell
[accessibility]
screen_reader = True
[component_manager]
disable_update_check = True
[compute]
gce_metadata_read_timeout_sec = 30
[core]
account = <my email address>
disable_usage_reporting = True
project = <my project>
[metrics]
environment = devshell
// on my local machine
[core]
account = <my email address>
disable_usage_reporting = True
pass_credentials_to_gsutil = false
project = <my project>
问题:
- 无论如何,这里的范围是什么?它们与分配给项目负责人 ( ) 的角色有什么关系
example@stackoverflow.com
? - 什么可能导致 Cloud Shell 与本地计算机上的范围不同?如何修复它,以便我可以在本地正确访问 Artifact Registry?
编辑:
为了澄清,这里是我正在运行的命令和我看到的错误,它与上面引用的 SO 问题完全相同。命令直接取自 [Artifact Registry Quickstart] ( https://cloud.google.com/artifact-registry/docs/docker/quickstart#gcloud )。这个问题本来是关于范围的,但似乎这些可能不是我的问题。
$ gcloud auth configure-docker us-central1-docker.pkg.dev
WARNING: Your config file at [~/.docker/config.json] contains these credential helper entries:
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud",
"us-central1-docker.pkg.dev": "gcloud"
}
}
Adding credentials for: us-central1-docker.pkg.dev
gcloud credential helpers already registered correctly.
$ sudo docker tag us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 \
us-central1-docker.pkg.dev/<my project>/quickstart-docker-repo/quickstart-image:tag1
$ sudo docker push us-central1-docker.pkg.dev/<my project>/quickstart-docker-repo/quickstart-image:tag1
The push refers to repository [us-central1-docker.pkg.dev/<my project>/quickstart-docker-repo/quickstart-image]
260c3e3f1e70: Preparing
e2eb06d8af82: Preparing
denied: Permission "artifactregistry.repositories.downloadArtifacts" denied on resource "projects/qwanto/locations/us-central1/repositories/quickstart-docker-repo" (or it may not exist)