-
Notifications
You must be signed in to change notification settings - Fork 918
Add Ec2 metadata disabling support via profile configuration #6204
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: master
Are you sure you want to change the base?
Conversation
|
* @return true if EC2 Metadata is disabled, false otherwise. | ||
*/ | ||
public boolean isMetadataDisabled() { | ||
return metadataDisabled.getValue(); |
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 check system setting here, like how we do it in resolveMetadataV1Disabled
? I think we also need to update Ec2MetadataClient to honor this config
if (profile.isPresent()) { | ||
return profile.get().booleanProperty(ProfileProperty.EC2_METADATA_DISABLED); | ||
} | ||
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.
nit: can be shortened, see fromProfileFileServiceTimeout
assertThat(e).isInstanceOf(SdkClientException.class); | ||
assertThat(e).hasMessage("IMDS credentials have been disabled by environment variable, system property, or configuration file profile setting."); |
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.
We should use assertThatThrownBy
, see other tests in this class
@@ -158,6 +174,15 @@ private static Optional<Boolean> fromProfileFileMetadataV1Disabled(Supplier<Prof | |||
.flatMap(p -> p.booleanProperty(ProfileProperty.EC2_METADATA_V1_DISABLED)); | |||
} | |||
|
|||
// Profile file resolution for Metadata disabled |
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 add some tests? See Ec2MetadataServiceTimeoutResolverTest for reference.
} | ||
|
||
@Test | ||
void resolveCredentials_metadataEnabledThroughConfig_returnsCredentials() { |
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 a bit confusing since it's enabled by default. I think we can remove this test once we address the other test comment
Ec2 metadata disabling via profile configuration
Motivation and Context
Java SDK supports disabling EC2 metadata via environment variables and system properties, we also want to add the ability to disable EC2 metadata through profile configuration.
Modifications
disable_ec2_metadata
in the ProfileProperty.Testing
Added unit tests
Performed manual testing with the AWS config file.
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