Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

S-Saranya1
Copy link
Contributor

@S-Saranya1 S-Saranya1 commented Jun 24, 2025

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

  • Added disable_ec2_metadata in the ProfileProperty.
  • Modified Ec2MetadataConfigProvider to parse disable_ec2_metadata from profile configuration
  • Updated InstanceProfileCredentialsProvider with the new configuration to disable IMDS credential fetching.

Testing

Added unit tests
Performed manual testing with the AWS config file.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@S-Saranya1 S-Saranya1 requested a review from a team as a code owner June 24, 2025 16:52
Copy link

@S-Saranya1 S-Saranya1 added the no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required label Jun 24, 2025
* @return true if EC2 Metadata is disabled, false otherwise.
*/
public boolean isMetadataDisabled() {
return metadataDisabled.getValue();
Copy link
Contributor

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

Comment on lines +180 to +183
if (profile.isPresent()) {
return profile.get().booleanProperty(ProfileProperty.EC2_METADATA_DISABLED);
}
return Optional.empty();
Copy link
Contributor

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

Comment on lines +340 to +341
assertThat(e).isInstanceOf(SdkClientException.class);
assertThat(e).hasMessage("IMDS credentials have been disabled by environment variable, system property, or configuration file profile setting.");
Copy link
Contributor

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
Copy link
Contributor

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() {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants