Repository navigation
AWS: a profile's credential_source can be the instance or container - #114
Merged
Merged
Conversation
odgrim
force-pushed
the
track-a/aws-credential-source
branch
from
December 6, 2026 07:38
2ecd182 to
8963c80
Compare
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
force-pushed
the
track-a/aws-credential-source
branch
from
December 6, 2026 08:13
8963c80 to
d23d04c
Compare
odgrim
marked this pull request as ready for review
December 6, 2026 08:20
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.
Change
A role whose profile says
credential_source = Ec2InstanceMetadataorEcsContainernow signs in. It takes its source keys from the EC2 instance metadata service or the container credentials endpoint, as Runbooks main'sfromInidid. Before, the plugin refused both:AWS_EC2_METADATA_SERVICE_ENDPOINT,AWS_CONTAINER_CREDENTIALS_FULL_URI,AWS_CONTAINER_AUTHORIZATION_TOKENand the rest), or the default endpoints.credential_sourceis still refused, now naming the three the AWS CLI knows.network, naming the profile and the source. It never repeats the endpoint's answer or URL.Decisions
ImdsCredentialsProviderandEcsCredentialsProvideralready 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'sEnvironment.ProviderConfig::with_envandwith_fsarepub(crate)in aws-config 1.13.3 (provider_config.rs:414). In the shipped binary the environments are the same.CredentialsErrorDisplay(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.network. Telling the kinds apart needsaws-credential-typesas a direct dependency, a new direct crate. It is already inCargo.lock.rt-tokiofeature. 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.lockis unchanged.AssumeRolerequest. Production passes none.profile::Plan.baseis a newBaseenum, not two moreCredentialvariants. Detection's sources never produce these, so their matches stay exhaustive without dead arms.Gaps
AssumeRolewith the given session token, against a plain-HTTP loopback stand-in.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_FILEis 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.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.ec2_metadata_service_endpointand_modefrom theAWS_PROFILE(or default) profile, not the profile being signed in (imds/client.rs:100-126,464).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 namesprofile "container".a_role_takes_its_keys_from_the_instance_or_container_endpoint_past_the_proxy(the shipped binary):PUT /latest/api/token, bothsecurity-credentialsGETs, andGET /container container-auth;sts.us-east-1.amazonaws.com:443;localhost, so it fails withoutrt-tokio.a_source_that_gives_no_keys_never_repeats_the_endpoint(the shipped binary, new):http://user:<marker>@10.255.255.1/creds;networknaming 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 SDKCredentialscome through.a_role_is_assumed_with_the_session_token_of_the_keys_it_is_given(unit, new): theAssumeRolerequest carriesx-amz-security-tokenequal to the held keys' token.a_role_takes_its_source_keys_from_the_instance_or_containernow 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):Unexpected, notNetwork;rt-tokioremoved.Hand mutants against d23d04c (109 tests), each caught:
a_role_takes_its_source_keys_from_the_instance_or_container;sdk_credentialssends 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_keysdrops 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 checkat d23d04c:503 tests run: 503 passed, 0 skipped. The semver step reportsno 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 dependenciesis red only for the yanked pin-project-lite, as on main, until its 0.2.19 lock update.