gcloud docker 身份验证 x509 错误

gcloud docker authentication x509 error

我在尝试推送到 google 容器存储库时遇到身份验证错误。我看到很多关于此的问题,并将根据其他建议完成我已完成的步骤。我在 Windows 本地工作,使用最新版本的 gcloud 和 docker.

让我们开始吧,我有一个具有完全所有者权限的活动服务帐户。

我可以很好地查看我的项目和存储桶。

C:\Program Files (x86)\Google\Cloud SDK>gsutil acl get gs://api-project-773889352370-ml
[
  {
    "entity": "project-owners-773889352370",
    "projectTeam": {
      "projectNumber": "773889352370",
      "team": "owners"
    },
    "role": "OWNER"
  },
  {
    "entity": "project-editors-773889352370",
    "projectTeam": {
      "projectNumber": "773889352370",
      "team": "editors"
    },
    "role": "OWNER"
  },
  {
    "entity": "project-viewers-773889352370",
    "projectTeam": {
      "projectNumber": "773889352370",
      "team": "viewers"
    },
    "role": "READER"
  }
]

我可以为我的服务帐户下载一个 .json 密钥并在本地激活它。

gcloud auth activate-service-account --key-file C:/Users/Ben/Dropbox/Google/MeerkatReader-9fbf10d1e30c.json

我有一个 docker 和登录

的工作集
C:\Program Files (x86)\Google\Cloud SDK>docker push bw4sz/hello-world
The push refers to a repository [docker.io/bw4sz/hello-world]
a02596fdd012: Layer already exists
latest: digest: sha256:a18ed77532f6d6781500db650194e0f9396ba5f05f8b50d4046b294ae5f83aa4 size: 524

我用主机名和项目 ID 标记我的测试图像 (hello-world) 并试一试

C:\Program Files (x86)\Google\Cloud SDK>gcloud docker --push gcr.io/api-project-773889352370/hello-world

ERROR: Docker CLI operation failed:

Error response from daemon: Get https://gcr.kubernetes.io/v1/users/: x509: certificate has expired or is not yet valid

ERROR: (gcloud.docker) Docker login failed.

好的,让我们转到建议的高级身份验证方法, here, and

文档说我可以绕过 gcloud 并直接使用 docker,只需将我的 .json 密钥文件传递给登录即可。

C:\Program Files (x86)\Google\Cloud SDK>docker login -u _json_key -p "$(cat C:/Users/Ben/Dropbox/Google/MeerkatReader-d77c0d6aa04f.json)" https://gcr.io
Error response from daemon: Get https://gcr.io/v2/: unknown: Unable to parse json key.

文档说分两步完成,让我们试试看:

C:\Program Files (x86)\Google\Cloud SDK>set /p PASS=<C:/Users/Ben/Dropbox/Google/MeerkatReader-9fbf10d1e30c.json
C:\Program Files (x86)\Google\Cloud SDK>docker login -e 1234@5678.com -u _json_key -p "%PASS%" https://gcr.io
Flag --email has been deprecated, will be removed in 1.13.
Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password

另一个建议是使用临时令牌

C:\Program Files (x86)\Google\Cloud SDK>docker login -e 1234@5678.com -u _token -p "$(gcloud auth print-access-token)" https://gcr.io
Flag --email has been deprecated, will be removed in 1.13.
Login Succeeded

太好了,让我们再试一次。

C:\Program Files (x86)\Google\Cloud SDK>docker push gcr.io/api-project-773889352370/hello-world
The push refers to a repository [gcr.io/api-project-773889352370/hello-world]
a02596fdd012: Preparing
denied: Unable to create the repository, please check that you have access to do so.

我看到有人建议只推送到桶而不是项目 ID,那只会挂起

C:\Program Files (x86)\Google\Cloud SDK>docker push gcr.io/api-project-773889352370-ml/hello-world
The push refers to a repository [gcr.io/api-project-773889352370-ml/hello-world]
a02596fdd012: Retrying in 1 second <- goes on forever.

编辑: 尝试建议解决方案

C:\Program Files (x86)\Google\Cloud SDK>gcloud auth activate-service-account --key-file C:/Users/Ben/Dropbox/Google/MeerkatReader-9fbf10d1e30c.json
Activated service account credentials for: [773889352370-compute@developer.gserviceaccount.com]

C:\Program Files (x86)\Google\Cloud SDK>gcloud docker -a -s gcr.io
Short-lived access for ['gcr.io'] configured.

C:\Program Files (x86)\Google\Cloud SDK>docker push gcr.io/api-project-773889352370/hello-world
The push refers to a repository [gcr.io/api-project-773889352370/hello-world]
a02596fdd012: Preparing
denied: Unable to create the repository, please check that you have access to do so.

感谢您报告问题!

gcloud docker 验证您 ALL of GCR's supported registries, by default。 gcr.kubernetes.io 的证书在更新前已过期,Docker 客户端不喜欢这种情况(如果 Docker 客户端正在使用凭证存储,gcloud docker 将调用 docker login 对于每个支持的注册表)。 gcr.kubernetes.io 应从 gcloud SDK v141.0.0 中支持的注册表列表中删除。

同时,您可以通过执行 gcloud docker -a -s gcr.io(and/or eu.gcr.io、us.gcr.io 等)然后使用裸 Docker 客户端执行实际命令,例如docker push gcr.io/api-project-773889352370/hello-world.

有点乱,但我能找到的唯一解决办法是

  1. 将图像推送到 dockerhub
  2. 启动一个计算引擎实例
  3. 安装 docker(注意哪个版本,我有 1.6,根据 GCR 文档,我以后需要升级到 > 1.9)
  4. 从 dockerhub
  5. 拉取图像
  6. gcloud docker 推送到 GCR

这对我有用。不是一个很好的解决方案。欢迎提出建议。