-
Notifications
You must be signed in to change notification settings - Fork 917
Add ec2InstanceProfileName configuration #6208
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
base: feature/master/IMDS-AccountID-Support
Are you sure you want to change the base?
Add ec2InstanceProfileName configuration #6208
Conversation
- Refactor the code to resolve profile name
@@ -118,6 +121,13 @@ private InstanceProfileCredentialsProvider(BuilderImpl builder) { | |||
.orElseGet(() -> ProfileFileSupplier.fixedProfileFile(ProfileFile.defaultProfileFile())); | |||
this.profileName = Optional.ofNullable(builder.profileName) | |||
.orElseGet(ProfileFileSystemSetting.AWS_PROFILE::getStringValueOrThrow); | |||
this.ec2InstanceProfileName = builder.ec2InstanceProfileName; | |||
|
|||
if (isBlank(ec2InstanceProfileName) && ec2InstanceProfileName != null) { |
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.
This can be simplified to StringUtils.isWhitespace(ec2InstanceProfileName)
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.
Hmm, the StringUtils(software.amazon.awssdk.utils.StringUtils) doesn't have "isWhitespace" method, it only has "isBlank" method.
Apache Commons Lang StringUtils (from org.apache.commons.lang3.StringUtils) does have an isWhitespace method, but it's not available for this module.
if (apiVersion == ApiVersion.UNKNOWN) { | ||
apiVersion = ApiVersion.EXTENDED; | ||
} |
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.
What is the purpose of this change?
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.
Initially, apiVersion is set to UNKNOWN. When ec2InstanceProfileName is set by the user, we skip the first GET request to IMDS in the getSecurityCredentials() method. In refreshCredentials(), the code attempts to load credentials using the extended API endpoint first. If successful, we update apiVersion to EXTENDED. This serves two purposes - It records that the extended API is supported for future reference so it prevents unnecessary attempts to use the legacy API in subsequent calls, as we now know the extended API works.(This is from IMDS SEP 2.1)
throw SdkClientException.builder() | ||
.message("Invalid profile name") | ||
.cause(e) | ||
.build(); |
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 expand on this error message a bit? Specifically, what's the invalid value and what should they do about it?
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.
Updated it.
} catch (Exception e) { | ||
return Optional.empty(); | ||
} |
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.
What case is this guarding against?
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.
This is guarding against exceptions from aggregated profile suppliers, particularly NoSuchElementException like when there are invalid profiles or when suppliers throw exceptions during normal operation.
|
Adding ec2InstanceProfileName configuration to specify IMDS instance profile.
Motivation and Context
Adding ec2InstanceProfileName configuration to specify IMDS instance profile for retrieving credentials. This improves performance by skipping the profile discovery step, eliminating one IMDS call.
Modifications
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License