LoginSignup
8
4

More than 3 years have passed since last update.

MacからGoogleContainerRegistryアクセスでエラー

Last updated at Posted at 2020-01-15

概要

  • ローカルで作成したDockerイメージをGCR(GoogleContainerRegistry)にPUSHしたい
  • MacからGCRにDockerImageをPULL/PUSHできない(Winは試していない)
  • CloudShellからはPULL/PUSH可能
  • どうやら権限周りが原因っぽい
  • 以下のようなエラーで弾かれる
  • 解決したのでメモしておく
$ docker pull asia.gcr.io/[project-id]/[repository]:latest
Error response from daemon: pull access denied for asia.gcr.io/[project-id]/[repository], repository does not exist or may require 'docker login': denied: Permission denied for "latest" from request "/v2/[project-id]/[repository]/manifests/latest".

詳細

Docker認証ヘルパーとしてgcloudコマンド発行
$ gcloud auth configure-docker

※アップデートを促されるメッセージが出た場合は"gcloud components update"を実行してから

  • GCRの実態はGoogleCloudStorageなのでこれに権限を与えてみる
  • 「ストレージオブジェクト閲覧者」権限のみ与えてみる

image.png

PULLしてみる
$ docker pull asia.gcr.io/[project-id]/[repository]:latest
latest: Pulling from [project-id]/[repository]
Digest: sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Status: Downloaded newer image for asia.gcr.io/[project-id]/[repository]:latest
asia.gcr.io/[project-id]/[repository]:latest
確認
$ docker images asia.gcr.io/[project-id]/[repository]
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
asia.gcr.io/[project-id]/[repository]   latest              f7bb5701a33c        2 weeks ago         126MB

PULLできてる

PUSHもしてみる
$ docker image push asia.gcr.io/[project-id]/[repository]
The push refers to repository [asia.gcr.io/[project-id]/[repository]]
75248c0d5438: Preparing
49434cc20e95: Preparing
556c5fb0d91b: Preparing
denied: Token exchange failed for project '[project-id]'. Caller does not have permission 'storage.buckets.get'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control

やはり閲覧権限だけではPUSHできない様子

「ストレージオブジェクト作成者権限」を付与してみる

image.png

PUSHしてみる
$ docker image push asia.gcr.io/[project-id]/[repository]
The push refers to repository [asia.gcr.io/[project-id]/[repository]]
75248c0d5438: Preparing
49434cc20e95: Preparing
556c5fb0d91b: Preparing
denied: Token exchange failed for project '[project-id]'. Caller does not have permission 'storage.buckets.get'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control

ダメらしい。。

「ストレージオブジェクト管理者」を付与してみる

image.png

PUSHしてみる
$ docker image push asia.gcr.io/[project-id]/[repository]:latest
The push refers to repository [asia.gcr.io/[project-id]/[repository]]
75248c0d5438: Preparing
49434cc20e95: Preparing
556c5fb0d91b: Preparing
denied: Token exchange failed for project '[project-id]'. Caller does not have permission 'storage.buckets.get'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control

ダメらしい

「ストレージ管理者」権限を付与してみる

image.png

PUSHしてみる
$ docker image push asia.gcr.io/[project-id]/[repository]:latest
The push refers to repository [asia.gcr.io/[project-id]/[repository]]
75248c0d5438: Layer already exists
49434cc20e95: Layer already exists
556c5fb0d91b: Layer already exists
latest: digest: sha256:36b77d8bb27ffca25c7f6f53cadd059aca2747d46fb6ef34064e31727325784e size: 948

PUSHできた

結論

  • MacなどからGCRへのアクセスにはGCSの権限を変更する必要がある
  • GCRへのPULLには「ストレージオブジェクトの閲覧者」権限が必要
  • GCRへのPUSHには「ストレージの管理者」権限が必要
  • gcloudの認証は予め済ませておく

参考

公式:権限
公式:認証

8
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4