![](/img/trans.png)
[英]Unable to push docker image to GCP registry : denied: Token exchange failed for project <my_project_id> Access denied
[英]gcloud docker push results in “denied: Token exchange failed for project 'gcp-project-id-example'.”
我已经运行gcloud auth login
, gcloud auth configure-docker
gcloud components install docker-credential-gcr
, gcloud components install docker-credential-gcr
, gcloud config set project gcp-project-id-example
。
我之前已经推送到这个存储库,所以我有点惊讶它现在不起作用? 我已使用gcloud auth login
身份验证,并且我的用户具有完整的编辑器权限。
sudo gcloud docker -- push eu.gcr.io/gcp-project-id-example/pipelinebuild:latest
WARNING: `gcloud docker` will not be supported for Docker client versions above 18.03.
As an alternative, use `gcloud auth configure-docker` to configure `docker` to
use `gcloud` as a credential helper, then use `docker` as you would for non-GCR
registries, e.g. `docker pull gcr.io/project-id/my-image`. Add
`--verbosity=error` to silence this warning: `gcloud docker
--verbosity=error -- pull gcr.io/project-id/my-image`.
See: https://cloud.google.com/container-registry/docs/support/deprecation-notices#gcloud-docker
The push refers to repository [eu.gcr.io/gcp-project-id-example/pipelinebuild]
09a1efc2708d: Preparing
484c62332bc0: Preparing
737446294222: Preparing
5330921097a0: Preparing
898d09fcad4e: Preparing
8ebe2c7c93e3: Waiting
2d360789868b: Waiting
43c7850e5ceb: Waiting
212ad79ba733: Waiting
b12c0a65bf50: Waiting
2ec89235b54b: Waiting
770a49082d40: Waiting
2a4ee56ebd9d: Waiting
f38582ca1d15: Waiting
3cc68fcb53a4: Waiting
577d10d964a3: Waiting
96e5efb05969: Waiting
aae94198c5bb: Waiting
9e5b0f110abc: Waiting
bddf843523ce: Waiting
6ab9447934c9: Waiting
9cc1209e0dce: Waiting
072f13fb321e: Waiting
0926f7bf84b3: Waiting
cdb414de0edf: Waiting
eceffb9b1d52: Waiting
6219baf3e782: Waiting
c9189dccc6a7: Waiting
93715b5af77e: Waiting
032237575276: Waiting
5f70bf18a086: Waiting
0d81735d8272: Waiting
982549bd6b32: Waiting
8698b31c92d5: Waiting
denied: Token exchange failed for project 'gcp-project-id-example'. Caller does not have permission 'storage.buckets.get'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control
我也试过:
docker login -u _json_key --password-stdin https://eu.gcr.io < aysc.json
:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
但是仍然使用gcloud docker -- push ...
获得相同的行为gcloud docker -- push ...
或者只是gcloud docker -- push ...
docker push ...
。
我刚刚从头开始创建了一个全新的 GCP 项目,但我仍然得到相同的行为。 我认为必须在我的系统上重新配置一些东西。
为什么我收到这个错误?
创建并下载 keyfile.json 后,我将 GOOGLE_APPLICATION_CREDENTIALS 导出到文件所在的位置
export GOOGLE_APPLICATION_CREDENTIALS=/var/lib/jenkins/gcp/keyfile.json
这就是我所做的对我有用的事情:
docker login -u _json_key -p "`cat ${GOOGLE_APPLICATION_CREDENTIALS}`" https://gcr.io
希望能帮助到你
当您以普通用户gcloud auth configure-docker
运行gcloud auth configure-docker
它会在~/.docker/config.json
保存一个配置文件 - 之后通过root
用户或sudo
运行时不会使用该文件...
所以一个简单的解决方法是sudo -u $USER docker push gcr.io/example/example:latest
使用sudo
似乎存在一些问题(我需要在我的机器上访问 docker)。
直接从 root 运行时工作正常......所以可能是一个错误。
我认为这是由以前的同名服务帐户的缓存引起的(参见此处https://github.com/kubernetes/kubernetes/issues/34395 )。
我怀疑问题出在 sudo 上。 我能够在不使用 sudo 的情况下对 gcr.io/some-registry/some-image 执行“docker push”。 然后突然间,我无法运行相同的“docker push”命令并得到“拒绝:my-gcp-project 的令牌交换失败。
运行此命令再次激活令牌 -
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io
我在尝试从容器优化的操作系统将 docker 映像上传到 GCR 时遇到了类似的问题,我运行了以下命令序列,
docker-credential-gcr configure-docker
docker login -u _json_key -p "$(cat ./mygcrserviceaccount.JSON)" https://gcr.io
命令docker login -u _json_key -p "$(cat ./mygcrserviceaccount.JSON)" https://gcr.io
docker push gcr.io/project-id/imagename:tage01
它因以下错误而失败,
denied: Token exchange failed for project 'project-id'. Caller does not have permission 'storage.buckets.create'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control
我尝试通过 IAM 角色为我的服务帐户授予所有可能的权限,但它会因相同的错误而失败。
阅读此问题后,我做了以下更改,
rm -rf ~/.docker
配置目录rm -rf ~/.docker
docker-credential-gcr configure-docker
GOOGLE_APPLICATION_CREDENTIALS=/path/to/mygcrserviceaccount.JSON
使用docker login -u _json_key -p "$(cat ${GOOGLE_APPLICATION_CREDENTIALS})" https://gcr.io
命令docker login -u _json_key -p "$(cat ${GOOGLE_APPLICATION_CREDENTIALS})" https://gcr.io
执行docker push gcr.io/project-id/imagename:tage01
push 命令 - docker push gcr.io/project-id/imagename:tage01
瞧,它就像一个魅力!
在运行 docker login 之前,请尝试:
gcloud auth activate-service-account --key-file new-service-account-credentials.json
这必须只做一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.