Add Ec2 metadata disabling support via profile configuration#6204
Add Ec2 metadata disabling support via profile configuration#6204S-Saranya1 wants to merge 2 commits intomasterfrom
Conversation
|
| * @return true if EC2 Metadata is disabled, false otherwise. | ||
| */ | ||
| public boolean isMetadataDisabled() { | ||
| return metadataDisabled.getValue(); |
There was a problem hiding this comment.
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.
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.
We should use assertThatThrownBy, see other tests in this class
| .flatMap(p -> p.booleanProperty(ProfileProperty.EC2_METADATA_V1_DISABLED)); | ||
| } | ||
|
|
||
| // Profile file resolution for Metadata disabled |
There was a problem hiding this comment.
Can we add some tests? See Ec2MetadataServiceTimeoutResolverTest for reference.
| } | ||
|
|
||
| @Test | ||
| void resolveCredentials_metadataEnabledThroughConfig_returnsCredentials() { |
There was a problem hiding this comment.
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
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |



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_metadatain the ProfileProperty.Testing
Added unit tests
Performed manual testing with the AWS config file.
Screenshots (if appropriate)
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