fix: ensure AWS credentials are resolved fresh on each request#3
Merged
stephaneberle9 merged 3 commits intostephaneberle9:mainfrom Feb 2, 2026
Merged
Conversation
…port automatic refresh
… support credential refresh
Owner
|
Thanks a lot for this contribution. This addresses and fixes a critical issue. Before merging it, we'd need to get over this test failure: https://github.com/stephaneberle9/jclouds/actions/runs/21396283792/job/61843076287?pr=3 Maybe just a missing dependency in the test project? |
38e1129 to
e257596
Compare
Author
|
Should be fixed now. It seems to test |
… load without aws sdk
e257596 to
6f2109e
Compare
stephaneberle9
pushed a commit
that referenced
this pull request
Feb 2, 2026
…ic refresh (#3) Fixes credential expiration issue in long-living BlobStoreContext instances by removing credential caching and ensuring fresh credential resolution on each request. Problem: - AWS credentials were cached in an instance field after first resolution - Temporary credentials (IAM roles, STS tokens) would expire after 1 hour but were never refreshed - Long-running applications using jclouds would fail with expired credentials Solution: - Removed the awsCredentials instance field that was caching credentials - Modified getCredentials() to call resolveAwsCredentials() on every invocation - AWS SDK v2's DefaultCredentialsProvider automatically refreshes credentials, but only when resolveCredentials() is called each time - Cached the AwsCredentialsProvider instance instead to balance performance with credential freshness Changes: - common/aws: Removed credential caching from AWSCredentialsProvider - common/aws: Added regression test to verify credentials are not cached - providers/aws-s3: Fixed class loading to work without AWS SDK present in test environments This enables automatic credential refresh for applications using IAM roles, IRSA (EKS), or other temporary credential mechanisms without requiring context recreation.
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.
In our product, we're having a long-living
BlobStoreContextandBlobStoreinstance. We're facing the issue that credentials expire after a while without being refreshed. This PR attempts to fix that (I have no means though to test it right now).Do you think, this could fix the issue we are facing?
Analysis
In AWSCredentialsProvider.java:
The bug: awsCredentials is resolved once and then cached in an instance field. When temporary credentials expire (typically after 1 hour for IAM roles, 15 minutes for some STS tokens), jclouds keeps using the expired ones.
What SHOULD Happen (According to the Code Comments)
The code has this comment:
However, this is misleading! The AWS SDK DefaultCredentialsProvider DOES auto-refresh, but only if you call .resolveCredentials() each time. By caching the result, jclouds bypasses the refresh mechanism.
Fix
Modified
common/aws/src/main/java/org/jclouds/aws/credentials/AWSCredentialsProvider.java:awsCredentialsinstance field that was caching credentialsgetCredentials()method - Now callsresolveAwsCredentials()on every request instead of caching the resultAdded regression test in
common/aws/src/test/java/org/jclouds/aws/credentials/AWSCredentialsProviderTest.java:testCredentialsAreNotCachedIndefinitely()- Verifies that credentials are resolved fresh on each call rather than being cached