-
Notifications
You must be signed in to change notification settings - Fork 970
Token caching for IMDS Client #3543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Javadoc and clean-up.
Javadoc and clean-up.
- safe async client closing - Ec2MetadataEndpointProvider singleton instance - default attribute map for IMDS - Fix javadoc <p> tag
core/imds/src/main/java/software/amazon/awssdk/imds/Ec2MetadataRetryPolicy.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/Ec2MetadataRetryPolicy.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/internal/BaseEc2MetadataClient.java
Show resolved
Hide resolved
core/imds/src/test/java/software/amazon/awssdk/imds/internal/CachedTokenAsyncClientTest.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/Ec2MetadataClientBuilder.java
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/TokenCacheStrategy.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/internal/DefaultEc2MetadataAsyncClient.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/internal/DefaultEc2MetadataAsyncClient.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/internal/DefaultEc2MetadataAsyncClient.java
Outdated
Show resolved
Hide resolved
- upgrade to Junit 5 - TokenCacheStrategy as an interface - added Token class - Improved Asynchronous request retry and caching logic
core/imds/src/main/java/software/amazon/awssdk/imds/internal/StringResponseHandler.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/internal/StringResponseHandler.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/BlockingTokenCache.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/NoCache.java
Outdated
Show resolved
Hide resolved
| CompletableFutureUtils.forwardExceptionTo(tokenFuture, tokenValueFuture); | ||
| return tokenFuture; | ||
| }; | ||
| this.tokenCache = tokenCacheStrategy.getCachedSupplier(valueSupplier, this.tokenTtl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the token TTL from the response header X-aws-ec2-metadata-token-ttl-seconds? Do we know what happens if the token TTL provided is greater than the max token TTL allowed on the server side? Does it fail or succeed with the max token TTL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we track this somewhere if we haven't done so already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a TODO or add a backlog item?
core/imds/src/main/java/software/amazon/awssdk/imds/internal/DefaultEc2MetadataAsyncClient.java
Outdated
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/internal/Token.java
Outdated
Show resolved
Hide resolved
| ThreadFactory threadFactory = new ThreadFactoryBuilder().threadNamePrefix("IMDS-ScheduledExecutor").build(); | ||
| return Executors.newScheduledThreadPool(DEFAULT_RETRY_THREAD_POOL_SIZE, threadFactory); | ||
| }); | ||
| TokenCacheStrategy tokenCacheStrategy = Validate.getOrDefault(builder.tokenCacheStrategy, () -> TokenCacheStrategy.NONE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we cache it by default? Let's discuss it in the API surface area review meeting
core/imds/src/main/java/software/amazon/awssdk/imds/BlockingTokenCache.java
Show resolved
Hide resolved
core/imds/src/main/java/software/amazon/awssdk/imds/internal/DefaultEc2MetadataAsyncClient.java
Outdated
Show resolved
Hide resolved
|
SonarCloud Quality Gate failed. |








Implements token caching for both the Ec2MetadataClient and its Async version.
Motivation and Context
Required as part of the v2 parity.
Modifications
Add an opt-in option to use a CachedSupplier to prevent sending a token request for every MetadataRequest. The token is cached until the token time to live has expired.
Testing
Added unit tests for token caching, both for regular and async clients.
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License