Created
November 26, 2025 16:33
-
-
Save JanTvrdik/fac3b7a9a878ccd2781144fd72c613ab to your computer and use it in GitHub Desktop.
Bash implementation of Docker credential helper for AWS ECR (without any storage)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Bash implementation of Docker credential helper for AWS ECR (without any storage) | |
| # https://docs.docker.com/reference/cli/docker/login/#credential-helper-protocol | |
| if [ "$1" == "get" ]; then | |
| SERVER_URL=$(cat) | |
| # Extract region from URL format: *.dkr.ecr.REGION.amazonaws.com | |
| REGION="${SERVER_URL#*.dkr.ecr.}" | |
| REGION="${REGION%.amazonaws.com}" | |
| if [[ ! "$REGION" =~ ^[a-z]{2}-[a-z]+-[0-9]+$ ]]; then | |
| echo "Error: Could not extract valid region from $SERVER_URL" >&2 | |
| exit 1 | |
| fi | |
| aws sts get-caller-identity >/dev/null 2>&1 || aws sso login --no-browser --use-device-code >&2 | |
| SECRET=$(aws ecr get-login-password --region "$REGION") | |
| jq -n --arg username "AWS" --arg secret "$SECRET" '{Username: $username, Secret: $secret}' | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment