Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fetch list images from GCR via service account
#!/usr/bin/env bash
set -euo pipefail
######################
# Script that fetches a list of all images from GCR
# uses 3 different users in GCR
######################
keyfile="gcr-svc-acc-keyfile.json"
projectName="example-project"
imageName="alpine"
token=$(oauth2l fetch --credentials $keyfile --scope cloud-platform.read-only --cache="")
jwt=$(curl -sSL "https://gcr.io/v2/token?service=gcr.io&scope=repository:$projectName/$imageName:pull" -u _token:$token | jq --raw-output '.token')
curl -sSL -H "Authorization: Bearer $jwt" "https://gcr.io/v2/$projectName/$imageName/tags/list"
# use oauth2 access token instead of JWT from docker registry
token=$(oauth2l fetch --credentials $keyfile --scope cloud-platform.read-only --cache="")
curl -sSL -u "oauth2accesstoken:$token" "https://gcr.io/v2/$projectName/$imageName/tags/list"
# use service account key instead of oauth2 access key
curl -sSL -u "_json_key:$(cat $keyfile)" "https://gcr.io/v2/$projectName/$imageName/tags/list"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.