Support AWS IAM authentication for ECR image pulls - #121
Open
GoldenAnpu wants to merge 5 commits into
Open
Conversation
Implement ECR IAM authentication fallback and enhance docker pull logic
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.
Problem
The agent resolved registry credentials only from
DOCKER_LOGIN/DOCKER_PASSWORD/DOCKER_REGISTRY(env vars or agent options from the instance UI). Any authentication configured on the host — e.g. the Amazon ECR credential helper used by the docker CLI — was never picked up, because pull authentication in Docker is always client-side (X-Registry-Authheader) and the agent is a separate docker-py client running inside its own container. As a result,docker pullworked on the host while the agent failed to pull the same ECR image.Solution
All image pulls (
_docker_pull,_docker_pull_progress, net-client update check) now go through a single resolverdocker_utils.resolve_auth(registry, logger).Credential resolution order
DOCKER_LOGIN/DOCKER_PASSWORD/DOCKER_REGISTRY(env or agent options). If the image registry is listed there, these credentials are used — existing setups keep working unchanged.<account>.dkr.ecr.<region>.amazonaws.com, incl. FIPS / China / GovCloud endpoints), the agent obtains an authorization token viaboto3using the standard AWS credential chain: EC2 instance role (IMDS),AWS_*env vars, or a mounted~/.aws. Tokens are cached per registry and refreshed 15 minutes before expiration.auth_config=Noneis passed to docker-py, which then resolves credentials from the Docker config file (~/.docker/config.jsonor$DOCKER_CONFIG) and credential helpers — the same way the docker CLI does. Mounting a config file into the agent container is enough for staticdocker logincredentials.If the AWS token request fails (e.g. IMDS unreachable from containers — IMDSv2 hop limit must be ≥ 2), the agent logs a warning with a hint and falls through to step 3 instead of failing the pull.
Other changes
DOCKER_*values no longer produce a bogus"": {...}auth entry._hide_credentialshelper).boto3(imported lazily, only when the image is hosted on ECR).