Google 云容器 Registry/Artifact 注册表权限

Google Cloud Container Registry/Artifact Registry Permissions

我正在尝试使用 Google Cloud SDK 将容器推送到 Google Cloud Container Registry 或 Windows 10 上的 Google Cloud Artifact Registry。我从这两种服务中都收到了类似的权限错误,但我似乎无法弄清楚原因。对于 Container Registry,推送时我得到:

> docker push us.gcr.io/{PROJECT}/{PATH}/{CONTAINER}:{TAG}
unauthorized: You don't have the needed permissions to perform this operation, 
and you may have invalid credentials. To authenticate your request, follow the 
steps in: https://cloud.google.com/container-registry/docs/advanced-authentication

对于 Artifact Registry,推送时我得到:

> docker push northamerica-northeast1-docker.pkg.dev/{PROJECT}/{REPOSITORY}/{CONTAINER}:{TAG}
denied: Permission "artifactregistry.repositories.downloadArtifacts" denied on resource 
"projects/opallabs/locations/northamerica-northeast1/repositories/domar" (or it may not exist)

我已经 运行 gcloud initgcloud auth configure-docker 几次了。我可以使用 gcloud 从命令行轻松创建和编辑 Google 云资源。我是 Google Cloud 项目的所有者,但为了安全起见,我给自己分配了存储管理员、Artifact Registry 管理员、Artifact Registry 存储库管理员。但是,当我 运行 gcloud auth print-access-token 并使用 https://www.googleapis.com/oauth2/v1/tokeninfo 端点分析令牌时,唯一出现的范围是:

{
  ...
  "scope": "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",
  ...
}

缺少 https://www.googleapis.com/auth/devstorage.read_writehttps://www.googleapis.com/auth/devstorage.full_control 范围,根据 troubleshooting link,,它们可能应该存在,但我不确定为什么它们会丢失。我按照设置说明在我的最后一台 Windows 10 机器上进行了此操作,但我的新机器上的相同设置似乎不起作用。

我的 docker 凭证助手条目:

{
  "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",
    "northamerica-northeast1-docker.pkg.dev": "gcloud",
    "us-central1-docker.pkg.dev": "gcloud"
  }
}
> docker-credential-gcloud list
{
  "https://asia.gcr.io": "_dcgcloud_token",
  "https://eu.gcr.io": "_dcgcloud_token",
  "https://gcr.io": "_dcgcloud_token",
  "https://marketplace.gcr.io": "_dcgcloud_token",
  "https://staging-k8s.gcr.io": "_dcgcloud_token",
  "https://us.gcr.io": "_dcgcloud_token"
}

gcloud -v
Google 云 SDK 311.0.0
测试版 2020.09.18
bq 2.0.60
核心 2020.09.18
gsutil 4.53

docker -v
Docker 版本 19.03.13,内部版本 4484c46d9d

感谢 provided by Muss Rahman I've been able to authenticate by going to "Settings" -> "Command Line" in Docker Desktop and unchecking the "Enable cloud experience" switch. The setting seems to be absent from the docker manual 所以我不确定它如何影响身份验证,我所知道的是 Docker 版本 19.03.13,在 Windows 上构建 4484c46d9d,如果您想使用 gcloud 进行身份验证,则需要禁用它。

尝试配置:

gcloud auth configure-docker northamerica-northeast1-docker.pkg.dev

我在拼错项目名称时遇到了这个问题。仔细检查您的路径是否与 https://cloud.google.com/artifact-registry/docs/docker/pushing-and-pulling#auth

中的说明相符

您必须提供 project-specific 或 repo-specific 权限。经过大量研究,我才知道。

https://cloud.google.com/artifact-registry/docs/access-control#grant-repo

您可以提供您的 IAM 电子邮件并提供工件注册表编写器。

注意:即使您将 IAM 的所有者权限授予整个项目,它也不会工作,因为 Artifact 注册表本身有自己的权限系统。这需要一段时间才能识别

以防其他人遇到这个问题。我的问题是你必须使用 PROJECT-ID 这与项目名称不同

例如,如果您的项目名为 example,您可能有:

  • 标签:docker tag image:tag northamerica-northeast1-docker.pkg.dev/example/repo-name/image:tag
  • 推送:docker push northamerica-northeast1-docker.pkg.dev/example/repo-name/image:tag

这看起来很愚蠢,但很可能是您的问题。如果是那么

  1. 列出项目以获取PROJECT-IDgcloud projects list注意:这是第一列值,而不是最后一列中的“项目编号”)
  2. 标签:docker tag image:tag northamerica-northeast1-docker.pkg.dev/<PROJECT-ID>/repo-name/image:tag
  3. 推送:docker push northamerica-northeast1-docker.pkg.dev/<PROJECT-ID>/repo-name/image:tag

我在 CircleCi 上遇到这个问题 docker 推送到 google 云工件注册表并收到此错误。

denied: Permission "artifactregistry.repositories.downloadArtifacts" denied on resource

经过数小时的努力,我找到了解决方案,问题是新的 docker 的 BuildKit 功能 google 云工件注册表目前不支持这种新的图像架构,并且需要关闭。

DOCKER_BUILDKIT=0 docker push <IMAGE-NAME>