Skip to content

[Credential Cache Pr 3/3] Standardize refresh window configuration across all credential providers#7053

Open
alextwoods wants to merge 2 commits into
feature/master/credential_cachefrom
alexwoo/credential_cache_pr3
Open

[Credential Cache Pr 3/3] Standardize refresh window configuration across all credential providers#7053
alextwoods wants to merge 2 commits into
feature/master/credential_cachefrom
alexwoo/credential_cache_pr3

Conversation

@alextwoods

Copy link
Copy Markdown
Contributor

This PR merges to feature/master/credential_cache, NOT to master
[Credential Cache Pr 3/3].

Standardize refresh window configuration across all credential providers

Motivation and Context

This is part 3 of 3 implementing the Credential Refresh Behavior spec. With static stability enabled (PRs 1-2), this PR standardizes the refresh timing defaults and adds consistent builder configuration across all credential providers.

The SEP mandates 1-minute mandatory (stale) and 5-minute advisory (prefetch) refresh windows. Several providers previously used different values (IMDS: 1s stale; Container: 15min prefetch; Process: 15s prefetch). This PR aligns them all and exposes staleTime(Duration) / prefetchTime(Duration) builder methods for customer override.

PR chain: PR 1: CachedSupplier ALLOW enginePR 2: Enable static stability for STS, Container, SSO, and Login credential providers → PR3 (this)

Depends on: #7028 and #7031

Modifications

  • InstanceProfileCredentialsProvider: Changed default staleTime from 1 second to 1 minute. Changed prefetchTime from max(timeUntilExpiry/2, 5min) to flat 5 minutes before expiry. Added prefetchTime(Duration) builder method. Added staleTime <= prefetchTime validation.

  • ContainerCredentialsProvider: Changed prefetchTime from min(1hr, 15min-before-expiry) to flat 5 minutes before expiry. Added staleTime(Duration) and prefetchTime(Duration) builder methods. Added validation.

  • ProcessCredentialsProvider: Added staleTime(Duration) and prefetchTime(Duration) builder methods. Changed default staleTime from 0 (at-expiration) to 1 minute. Changed default prefetchTime from 15 seconds to 5 minutes. Deprecated credentialRefreshThreshold (it now sets prefetchTime under the hood for backward compatibility). Added validation.

  • WebIdentityTokenFileCredentialsProvider: Added staleTime(Duration) and prefetchTime(Duration) builder methods that pass through to the underlying STS provider.

  • StsCredentialsProvider / SsoCredentialsProvider / LoginCredentialsProvider: Added staleTime <= prefetchTime validation at construction. Updated Javadoc for staleTime, prefetchTime, and asyncCredentialUpdateEnabled to use consistent terminology (mandatory refresh window / advisory refresh window).

  • HttpCredentialsProvider: Updated asyncCredentialUpdateEnabled Javadoc for clarity.

  • Tests: Updated IMDS timing tests for new defaults, added Process provider timing tests, updated WebIdentity factory test for new builder params.

Testing

New and existing tests.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.

License

  • I confirm that this pull request can be released under the Apache 2 license

Standardize staleTime/prefetchTime defaults and add builder
configuration across all credential providers:

InstanceProfileCredentialsProvider:
- Change default staleTime from 1 second to 1 minute
- Change prefetchTime from max(timeUntilExpiry/2, 5min) to flat
  5 minutes before expiry
- Add prefetchTime(Duration) builder method
- Add staleTime <= prefetchTime validation

ContainerCredentialsProvider:
- Change prefetchTime from min(1hr, 15min-before-expiry) to flat
  5 minutes before expiry
- Add staleTime(Duration) and prefetchTime(Duration) builder methods
- Add staleTime <= prefetchTime validation

ProcessCredentialsProvider:
- Add staleTime(Duration) and prefetchTime(Duration) builder methods
- Change default staleTime from 0 (at expiration) to 1 minute
- Change default prefetchTime from 15 seconds to 5 minutes
- Deprecate credentialRefreshThreshold (now sets prefetchTime)
- Add staleTime <= prefetchTime validation

WebIdentityTokenFileCredentialsProvider:
- Add staleTime(Duration) and prefetchTime(Duration) builder methods
  (pass-through to underlying STS provider)

StsCredentialsProvider / SsoCredentialsProvider / LoginCredentialsProvider:
- Add staleTime <= prefetchTime validation
- Update Javadoc for staleTime, prefetchTime, and
  asyncCredentialUpdateEnabled to use consistent terminology
  (mandatory refresh window / advisory refresh window)

HttpCredentialsProvider:
- Update asyncCredentialUpdateEnabled Javadoc for clarity

All providers now use consistent defaults:
- staleTime: 1 minute (mandatory/blocking refresh window)
- prefetchTime: 5 minutes (advisory/proactive refresh window)
@alextwoods alextwoods requested a review from a team as a code owner June 18, 2026 20:27
@alextwoods alextwoods requested a review from S-Saranya1 June 19, 2026 15:12
* provider will block all callers until a refresh attempt completes. If the refresh attempt fails, the provider
* returns the cached credentials and will not attempt another refresh until a backoff period has elapsed.
*
* <p>This value must be less than {@link #prefetchTime(Duration)}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Should this be less than or equal to right? looks like the validation allows equality and the error message also says "less than or equal to"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah good call out! It was a later decision to allow <=, which gives users effectively a way of disabling the prefetch - I'll updated docs.

private static final JsonNodeParser PARSER = JsonNodeParser.builder()
.removeErrorLocations(true)
.build();
private static final Duration DEFAULT_STALE_TIME = Duration.ofMinutes(1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have missed the discussion here, just to double check - so we decided to change the Process staleTime default from 0 to 1 even though process doesnt use static stability ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah - the decision was based on making it consistent with other SDKs/providers and mitigating the risk of using expired (ie, when the stale time is 0, you can start signing a request before the credentials expire, but by the time the request has been signed, sent and processed the credentials are expired)

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