Skip to content

Reuse default STS client across web identity credential refreshes - #3425

Merged
stobrien89 merged 2 commits into
aws:masterfrom
nathanblogs:fix-web-identity-sts-client-reuse
Nov 27, 2026
Merged

stobrien89 merged 2 commits into
aws:masterfrom
nathanblogs:fix-web-identity-sts-client-reuse

Conversation

@nathanblogs

@nathanblogs nathanblogs commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available: #3424

Description of changes:

  • assumeRoleWithWebIdentityCredentialProvider() now creates its default StsClient once per region and reuses it across refreshes, instead of building a new one each time.
  • Stops ~1 MB per refresh of cyclic garbage (including curl/OpenSSL state) from building up in long-running processes that use IRSA through the default chain.
  • The cached client is built by AssumeRoleWithWebIdentityCredentialProvider::createDefaultStsClient(), now public static and @internal, so both paths share one factory.
  • With no region, the client is cached under FALLBACK_REGION. The region notice now fires once per provider instead of on every refresh.
  • An explicit stsClient still takes precedence.
  • Adds regression tests (configured and fallback region) and a changelog entry.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

🤖 Generated with Claude Code

@stobrien89 stobrien89 left a comment

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.

Thanks for the contribution @nathanblogs. Just a couple of comments

Comment thread src/Credentials/CredentialProvider.php Outdated
return null;
}

return $clients[$region] ??= new StsClient([

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 duplicates the client config from AssumeRoleWithWebIdentityCredentialProvider::createDefaultStsClient(). If those drift (e.g. #3399 adds timeouts there), the cached client won't pick them up. Can we share one factory?

Comment thread src/Credentials/CredentialProvider.php Outdated
array &$clients
): ?StsClient
{
$region = $region ?: getenv(self::ENV_REGION);

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.

Returning null here means the no-region case still builds a new client every refresh. Could we cache under FALLBACK_REGION and keep the notice?

nathanblogs and others added 2 commits November 24, 2026 22:11
assumeRoleWithWebIdentityCredentialProvider() built a new StsClient on
every refresh. The discarded clients sit in reference cycles, so
long-running processes grow native memory by ~1 MB per refresh until
the cycle collector runs.

Fixes aws#3424

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build the cached web identity STS client through
AssumeRoleWithWebIdentityCredentialProvider::createDefaultStsClient() so it
picks up future client settings, and cache it under FALLBACK_REGION when no
region is configured. The region notice now fires once per provider instead
of on every refresh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nathanblogs
nathanblogs force-pushed the fix-web-identity-sts-client-reuse branch from e0aa2aa to 8191e4d Compare November 24, 2026 14:13
@stobrien89

Copy link
Copy Markdown
Member

Thanks for the fixes @nathanblogs. I think this is ready for review unless you planned on adding to it more

@stobrien89
stobrien89 marked this pull request as ready for review November 25, 2026 16:45
@stobrien89
stobrien89 requested a review from a team as a code owner November 25, 2026 16:45
@stobrien89
stobrien89 merged commit e0d6922 into aws:master Nov 27, 2026
21 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.

2 participants