Skip to content

Share S3 credentials provider across Context and fix anonymous-fallback caching - #297

Open
BrianMichell wants to merge 4 commits into
google:masterfrom
BrianMichell:fix/s3-credentials-share-and-cache
Open

BrianMichell wants to merge 4 commits into
google:masterfrom
BrianMichell:fix/s3-credentials-share-and-cache

Conversation

@BrianMichell

Copy link
Copy Markdown
Contributor

Summary

Two related fixes to how the S3 kvstore resolves AWS credentials.

1. Don't cache the anonymous fallback of the default chain

MakeAwsCredentialsProvider wrapped every provider in aws_credentials_provider_new_cached. For default, the chain falls back to anonymous credentials, which never expire, so the outer cache kept the anonymous result forever: credentials that became available later (env vars, IMDS, profile) were never picked up.

  • MakeCache is now applied per arm (environment, imds, profile, ecs_role). default (which already caches internally) and anonymous are no longer wrapped.
  • AsProvider, MakeCache, and MakeDefaultWithAnonymous return nullptr when aws-c-auth fails to construct a provider, instead of dereferencing NULL. MakeAwsCredentialsProvider reports this as an error.

2. Share one credentials provider per aws_credentials context resource

Before, AwsCredentialsResource was config_only and each S3KeyValueStore opened its own provider, so every store re-ran credential resolution (for example IMDS and STS calls). The resource now creates the provider once and every store bound to it reuses it.

Visible effects of removing config_only:

  • When a spec is unbound, the default aws_credentials resource is emitted as a context reference instead of inline. Explicit inline specs still round-trip inline.
  • S3 driver cache keys now tell apart stores bound to different aws_credentials resource instances.
  • Provider construction errors now surface when the context resource is resolved instead of when the store is opened.

- Only wrap leaf credential providers (Environment, Imds, Profile, EcsRole) in
  MakeCache in MakeAwsCredentialsProvider; MakeDefault already wraps its
  internal chain in aws_credentials_provider_new_cached, whereas wrapping the
  outer [MakeDefault, MakeAnonymous] chain in MakeCache permanently cached
  UINT64_MAX-expiration anonymous credentials after any initial fallback.
- Guard AsProvider, MakeCache, and MakeDefaultWithAnonymous against null
  aws_credentials_provider pointers.
- Add DefaultDoesNotCacheAnonymousFallback unit test.
- Change AwsCredentialsResource from config_only = true to own the live
  AwsCredentialsProvider in AwsCredentialsResource::Resource, created once
  per Context resource in AwsCredentialsResource::Create.
- Use data_.aws_credentials->credentials_provider in
  S3KeyValueStoreSpec::DoOpen instead of creating a new provider per open.
- Add unit tests verifying provider sharing within a Context and across
  parent/child Contexts.
@google-cla

google-cla Bot commented Oct 22, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@BrianMichell
BrianMichell force-pushed the fix/s3-credentials-share-and-cache branch from 4e409a1 to f3e4980 Compare October 23, 2026 13:43

This branch has not been deployed

No deployments
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