Skip to content

fix(libstore/aws-creds): use S3 URL region as STS WebIdentity fallback - #15594

Merged
lovesegfault merged 1 commit into
NixOS:masterfrom
lovesegfault:beme/aws-fix-sso
Apr 3, 2026
Merged

lovesegfault merged 1 commit into
NixOS:masterfrom
lovesegfault:beme/aws-fix-sso

Conversation

@lovesegfault

@lovesegfault lovesegfault commented Mar 29, 2026 •

Copy link
Copy Markdown
Member

Motivation

When authenticating to an S3 binary cache via STS WebIdentity (EKS IRSA, GitHub Actions OIDC), aws-c-auth's aws_credentials_provider_new_sts_web_identity needs a region to select an STS endpoint. It resolves this from, in order:

  1. options.region (not currently set by Nix)
  2. AWS_REGION / AWS_DEFAULT_REGION env vars
  3. the profile config file

In IRSA setups that export AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN but no region — and additionally set AWS_CONFIG_FILE=/dev/null to suppress SSO/profile interference — all three sources are absent. The provider returns nullptr, the credential chain silently skips it, and the user sees a misleading error:

AWS authentication error: 'Valid credentials could not be sourced by the IMDS provider' (6153)

Meanwhile the S3 URL itself already carries the region as ?region=us-east-1, which Nix parses into ParsedS3URL::region but doesn't pass to the credential chain.

Changes

  • Thread url.region through getCredentials → getCredentialsRaw → createProviderForProfile → createSTSWebIdentityProvider.
  • Only set options.region when neither AWS_REGION nor AWS_DEFAULT_REGION is present. aws-c-auth gives options.region precedence over env vars, so unconditional setting would mask a user-supplied region.
  • Change the credential-provider cache key from profile to (profile, region) since the region is baked into the provider at construction time.

Context

Ran into this on an EKS dev environment where a wrapper script forces IRSA by exporting the token file and role ARN while nulling out the config file. Any regional STS endpoint can assume a role in any region, so using the bucket's region as the STS endpoint is a reasonable fallback.

Checklist

  • Release note added
  • Tests — no existing unit tests for aws-creds.cc

When authenticating to an S3 binary cache via STS WebIdentity (EKS IRSA,
GitHub Actions OIDC), the aws-c-auth provider needs a region to select an
STS endpoint. It looks in AWS_REGION, AWS_DEFAULT_REGION, then the profile
config. In IRSA setups that export AWS_WEB_IDENTITY_TOKEN_FILE and
AWS_ROLE_ARN but no region — and additionally set AWS_CONFIG_FILE=/dev/null
to suppress SSO/profile interference — all three sources are absent. The
provider returns nullptr, the credential chain silently skips it, and the
user sees a misleading 'IMDS provider' failure.

Thread the ?region= parameter from the parsed S3 URL through to the STS
WebIdentity provider as a last-resort fallback. aws-c-auth gives
options.region precedence over env vars, so we only set it when neither
AWS_REGION nor AWS_DEFAULT_REGION is present, preserving existing
behaviour for users who do set a region.

The credential-provider cache key changes from profile to (profile, region)
since the region is baked into the provider at construction time.
Comment thread src/libstore/aws-creds.cc
Comment on lines +341 to +342
boost::
concurrent_flat_map<std::pair<std::string, std::string>, std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider>>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line break seems odd?

Suggested change
boost::
concurrent_flat_map<std::pair<std::string, std::string>, std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider>>
boost::concurrent_flat_map<std::pair<std::string, std::string>, std::shared_ptr<Aws::Crt::Auth::ICredentialsProvider>>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format is adamant that this is right, can't get it to budge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants