Skip to content

AWS: a profile's credential_source can be the instance or container - #114

Merged
odgrim merged 3 commits into
mainfrom
track-a/aws-credential-source
Dec 6, 2026
Merged

odgrim merged 3 commits into
mainfrom
track-a/aws-credential-source

Conversation

@odgrim

@odgrim odgrim commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Change

A role whose profile says credential_source = Ec2InstanceMetadata or EcsContainer now signs in. It takes its source keys from the EC2 instance metadata service or the container credentials endpoint, as Runbooks main's fromIni did. Before, the plugin refused both:

profile "x" takes its keys from credential_source "Ec2InstanceMetadata", which this block cannot reach
  • Endpoints: the keys come from the endpoint and token the process environment names (AWS_EC2_METADATA_SERVICE_ENDPOINT, AWS_CONTAINER_CREDENTIALS_FULL_URI, AWS_CONTAINER_AUTHORIZATION_TOKEN and the rest), or the default endpoints.
  • No proxy: those calls never go through the proxy, since the endpoints are the machine's own. The role's STS call still does.
  • Unknown sources: any other credential_source is still refused, now naming the three the AWS CLI knows.
  • Errors: a source that gives no keys fails the sign-in as network, naming the profile and the source. It never repeats the endpoint's answer or URL.

Decisions

  • aws-config's providers, not a hand-written fetch. ImdsCredentialsProvider and EcsCredentialsProvider already do IMDSv2's session token, retries, and the container endpoint's host allow-list. The cost: they read the endpoint, token and token file from the real process environment and filesystem, not the plugin's Environment. ProviderConfig::with_env and with_fs are pub(crate) in aws-config 1.13.3 (provider_config.rs:414). In the shipped binary the environments are the same.
  • A source failure says only aws-config's fixed words for its kind, its top-level CredentialsError Display (aws-credential-types 1.3.1, provider/error.rs:137-158): "the credential provider was not enabled", "credentials provider timed out after N seconds", "the credentials provider was not properly configured", "an error occurred while loading credentials", or "unexpected credentials error". Its sources carried the endpoint's message and a full URI with any password in it.
  • Every source failure is network. Telling the kinds apart needs aws-credential-types as a direct dependency, a new direct crate. It is already in Cargo.lock.
  • aws-config gains its rt-tokio feature. It gives the container provider the DNS resolver it uses to check that a full URI's host is loopback (ecs.rs:493-500). It adds no crate: Cargo.lock is unchanged.
  • The STS client takes the test endpoint, as the other three clients do, so a unit test sees the signed AssumeRole request. Production passes none.
  • profile::Plan.base is a new Base enum, not two more Credential variants. Detection's sources never produce these, so their matches stay exhaustive without dead arms.

Gaps

  • Not end to end through the binary. The binary's STS call needs TLS, and the refusing proxy stops it at CONNECT. A plugin test checks the fake receives the source's keys. A unit test checks the SDK signs AssumeRole with the given session token, against a plain-HTTP loopback stand-in.
  • Every source failure reads alike. A disabled metadata service, a bad full URI, a missing token file and a refusal all give aws-config's fixed words, with no variable named. Naming the variable per kind needs the kinds, so the direct dependency above.
  • No test pins CredentialsError's words. Its enum is #[non_exhaustive], and a test can only build the variants it knows, so it can't catch a new variant whose words hold input.
  • AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE is read by aws-config with no size bound and no regular-file check: a 5 MB file goes out as a header, and a FIFO hangs the sign-in. Only the process environment names it.
  • A disabled metadata service (AWS_EC2_METADATA_DISABLED=true) is honoured, with no request, but its error reads "(the credential provider was not enabled): check the network connection and proxy". Every source error ends that way, though these calls skip the proxy.
  • IMDSv2 only. aws-config has no IMDSv1 fallback.
  • aws-config reads ec2_metadata_service_endpoint and _mode from the AWS_PROFILE (or default) profile, not the profile being signed in (imds/client.rs:100-126,464).
  • Tested against loopback fakes only, through a full URI. Not tested: AWS_CONTAINER_CREDENTIALS_RELATIVE_URI (its host, 169.254.170.2, can't be faked) and the IPv6 metadata endpoint.

Evidence

  • a_role_takes_its_source_keys_from_the_instance_or_container (plugin, fake AWS): the roles are assumed with the instance's and the container's keys, and an unreachable container names profile "container".

  • a_role_takes_its_keys_from_the_instance_or_container_endpoint_past_the_proxy (the shipped binary):

    • a loopback server sees PUT /latest/api/token, both security-credentials GETs, and GET /container container-auth;
    • the refusing proxy sees only sts.us-east-1.amazonaws.com:443;
    • the container's full URI names localhost, so it fails without rt-tokio.
  • a_source_that_gives_no_keys_never_repeats_the_endpoint (the shipped binary, new):

    • the metadata service refuses with a message holding a marker;
    • the container's full URI is http://user:<marker>@10.255.255.1/creds;
    • both sign-ins are network naming their source, and neither message holds the marker or the address.

    It failed before the fix with "... (the credentials provider was not properly configured: Incorrect IMDS/IAM configuration: [AssumeRoleUnauthorizedAccess] endpoint-said-this denied. Hint: ...)".

  • source_keys_are_held_as_read (unit, new): the key id, secret, session token and expiry of an SDK Credentials come through.

  • a_role_is_assumed_with_the_session_token_of_the_keys_it_is_given (unit, new): the AssumeRole request carries x-amz-security-token equal to the held keys' token.

  • a_role_takes_its_source_keys_from_the_instance_or_container now also checks each role is assumed with its source's key id, secret and session token.

  • Hand mutants, each failing one test (107 passed, 1 failed):

    • session token dropped;
    • secret replaced;
    • expiry dropped;
    • the whole error chain in the message;
    • the kind Unexpected, not Network;
    • rt-tokio removed.
  • Hand mutants against d23d04c (109 tests), each caught:

    • the plugin drops the source's session token, or swaps its secret: a_role_takes_its_source_keys_from_the_instance_or_container;
    • sdk_credentials sends no session token, or the STS client ignores the endpoint: a_role_is_assumed_with_the_session_token_of_the_keys_it_is_given;
    • held_keys drops the token: both unit tests.

    Earlier, each of these also failed one test: no source known; sources swapped in the profile; the error without the profile; the local client through the proxy; the providers swapped in the backend.

  • mise run check at d23d04c: 503 tests run: 503 passed, 0 skipped. The semver step reports no publishable crates.

  • CI at 8963c80 (before the token tests): tests pass on Linux, macOS and Windows. Mutation test: 13 mutants tested in 5m: 5 caught, 8 unviable.

  • Audit dependencies is red only for the yanked pin-project-lite, as on main, until its 0.2.19 lock update.

A role whose profile says credential_source = Ec2InstanceMetadata or
EcsContainer now takes its source keys from the EC2 instance metadata
service or the container credentials endpoint. The plugin refused both
before.

The keys come through aws-config's providers, on an HTTP client with no
proxy: those endpoints are the machine's own. Any other credential_source
is still refused, now naming the three the AWS CLI knows.
A credential_source failure now says only aws-config's fixed words for
its kind, never its causes, which repeat the endpoint's answer and URL.
The source keys' conversion is its own function, tested with each field.
The container test reaches its endpoint by host name, which needs
aws-config's rt-tokio resolver.
The STS client takes the test endpoint as the other clients do, so a
unit test sees the signed AssumeRole request. The fake records the keys
each AssumeRole is signed with.
@odgrim
odgrim force-pushed the track-a/aws-credential-source branch from 8963c80 to d23d04c Compare December 6, 2026 08:13
@odgrim
odgrim marked this pull request as ready for review December 6, 2026 08:20
@odgrim
odgrim merged commit 303b921 into main Dec 6, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant