Repository navigation
Conversation
ECR Public answers Basic auth on registry API requests with a 400
("Your Authorization Token is invalid") instead of a 401 challenge, so
TokenTransport never starts the token flow and requests to public.ecr.aws
fail, or fall back to anonymous pulls and hit rate limits.
Per the ECR Public HTTP API docs, registry requests take the
GetAuthorizationToken token, base64("AWS:<password>"), as a bearer token.
For public.ecr.aws /v2 requests, build that token from the configured
username and password (as returned by `aws ecr-public get-login-password`)
and set it directly. Other paths such as /token keep the existing Basic
token flow.
Fixes dependabot#157
docker_registry credentials for public.ecr.aws with a username other than AWS are now treated as an AWS access key pair, as for private ECR. The proxy exchanges them for a token with ecr-public:GetAuthorizationToken in us-east-1, so the token no longer has to be rotated by hand every 12 hours. If the exchange fails, the request is sent anonymously rather than with the secret key. getECRCredentials now checks for a private ECR host before returning a cached token, so an ECR Public token is never sent as private ECR Basic auth. Adds github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.47.0, matching the vendored aws-sdk-go-v2 core version.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
Fixes #157.
docker_registrycredentials forpublic.ecr.aws(Amazon ECR Public) currently fail: ECR Public answers Basic auth on registry requests with a 400 (Your Authorization Token is invalid) instead of a 401 challenge, soTokenTransportnever starts the token exchange flow, and requests topublic.ecr.awsnever succeed.This change:
public.ecr.aws/v2requests, built from theGetAuthorizationTokentoken (base64("AWS:<password>")), instead of going through the Basic/token-challenge flow. Other paths such as/tokenkeep the existing flow. This is exactly the scheme documented under "Using HTTP API authentication" (curl -H "Authorization: Bearer $TOKEN" https://public.ecr.aws/v2/...), and was also confirmed against the live registry (see below).docker_registrycredential forpublic.ecr.awswith a username other thanAWSas an AWS access key pair, as already done for private ECR, and exchanges it for a token viaecr-public:GetAuthorizationToken. This call is only available inus-east-1, so the region is hardcoded for it (the AWS docs likewise instruct--region us-east-1for bothget-login-passwordandget-authorization-tokenagainst ECR Public).Anything you want to highlight for special attention from reviewers?
An alternative would be to have
TokenTransporttreat ECR Public's 400 as a challenge, but the 400 carries noWWW-Authenticateheader to drive the token exchange (confirmed against the live registry), so there's nothing for that flow to key off of. The bearer scheme is also exactly what AWS documents for direct HTTP API access, so sending it directly is simpler and doesn't change behavior for any other registry.internal/handlers/docker_registry.goauthenticateWithCredential: added a bearer-auth path forpublic.ecr.awsregistry (/v2) requests. Private ECR and all other registries keep going through the existing Basic/token-challengeBasicTransportpath unchanged.getECRCredentials(defensive fix): now checks for a private ECR host before returning a cached token, so a credential whose cache happens to hold an ECR Public token (ecrUsername/ecrPassword) is never sent as private ECR Basic auth. A single credential only ever matches one of the two host patterns today, so this doesn't change behavior; it just keeps the two token caches from being cross-used if that assumption ever changes.getECRPublicCredentialsto exchange an AWS access key pair for an ECR Public authorization token, caching it the same waygetECRCredentialsdoes for private ECR. The cached token isn't proactively refreshed before its ~12h expiry; the proxy process is short-lived (one dependabot-core job), so this mirrors the existing private ECR behavior and isn't expected to hit the expiry in practice.github.com/aws/aws-sdk-go-v2/service/ecrpublic(go.mod/go.sum/vendor/).Most of the diff is the vendored
ecrpublicSDK client that comes from runninggo mod vendorafter adding that dependency (same pattern as #195, which vendored the AWS SDK v2 migration). The actual logic change is confined tointernal/handlers/docker_registry.go(+91/-10 lines) and its test file (+176 lines). Reviewers can skipvendor/and focus on those two files.No documentation update is needed:
docker_registrycredential configuration isn't documented in this repo, and the new behavior (treating a non-AWSusername forpublic.ecr.awsas an access key) follows the same convention already used for private ECR hosts.How will you know you've accomplished your goal?
go mod tidy -diff(no diff),gofmt -l(clean),go build ./...,go vet ./....go test ./...passes, including newTestDockerRegistryHandlerECRPublic/TestDockerRegistryHandlerECRPublicAccessKeycases.docker_registrytests still pass unchanged, so this doesn't affect their behavior.public.ecr.awsregistry: reproduced the reported 400 onmain, and confirmed a 200 on this branch for both a pre-generated token (aws ecr-public get-login-password) and an AWS access key credential.Live proxy logs (before/after)
main(before):This branch (after):
(Credentials, tokens and account identifiers redacted / not reproduced above; both runs used the same pre-generated-token (
username: AWS)docker_registrycredential forpublic.ecr.aws. The AWS access key credential case was verified separately and also produced a 200.)Checklist