Skip to content

Instantly share code, notes, and snippets.

@northtyphoon
Last active February 6, 2026 08:55
Show Gist options
  • Select an option

  • Save northtyphoon/d76f57a0fe58ce1d38800529a62ca36b to your computer and use it in GitHub Desktop.

Select an option

Save northtyphoon/d76f57a0fe58ce1d38800529a62ca36b to your computer and use it in GitHub Desktop.
# Prerequisite
# 1) Install azure-cli, curl
# 2) Grant the identity AcrPull role on the registry

az login --identity

registry="myregistry.azurecr.io"
 
aad_access_token=$(az account get-access-token --resource-type arm --query accessToken --output tsv)
# aad_access_token=$(az account get-access-token --resource=https://containerregistry.azure.net --query accessToken --output tsv)
tenant=$(az account show --query tenantId -o tsv)
acr_username="00000000-0000-0000-0000-000000000000"
acr_refresh_token=$(curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=access_token&service=$registry&tenant=$tenant&access_token=$aad_access_token" https://$registry/oauth2/exchange | jq -r ".refresh_token")
 
docker login -u $acr_username -p "$acr_refresh_token" $registry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment