Skip to content

Commit e22c1cd

Browse files
committed
fix: allow IPv6 EKS Pod Identity host regardless of IMDS endpoint mode
ContainerCredentialsProvider rejects the EKS Pod Identity IPv6 endpoint (http://[fd00:ec2::23]/v1/credentials) unless AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE was explicitly set to IPV6. That variable configures the EC2 IMDS endpoint (169.254.169.254 vs [fd00:ec2::254]) which is (I believe?) a separate subsystem from the container credentials endpoint and EKS Pod Identity never sets it, so it defaults to the IPv4 allowlist. This behavior rejects valid IPv6 loopback hosts. This change aligns the Java SDK with the C++, Python (botocore), Go v2, and JS v3 SDKs, all of which allow the EKS IPv6 host unconditionally. Related issue: aws/containers-roadmap#2683.
1 parent 8a6a76c commit e22c1cd

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ContainerCredentialsProvider.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,7 @@ private boolean matchesAllowedHostRules(InetAddress inetAddress) {
307307
}
308308

309309
public boolean isMetadataServiceEndpoint(String host) {
310-
String mode = SdkSystemSetting.AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE.getStringValueOrThrow();
311-
if ("IPV6".equalsIgnoreCase(mode)) {
312-
return VALID_LOOP_BACK_IPV6.contains(host);
313-
}
314-
return VALID_LOOP_BACK_IPV4.contains(host);
310+
return VALID_LOOP_BACK_IPV4.contains(host) || VALID_LOOP_BACK_IPV6.contains(host);
315311
}
316312
}
317313

core/auth/src/test/java/software/amazon/awssdk/auth/credentials/ContainerCredentialsEndpointProviderTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ private static Stream<Arguments> requestConstruction() {
164164
.headers(new HashMap<>())
165165
.build())),
166166

167+
// EKS Pod Identity sets the IPv6 container URI but does NOT set
168+
// AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE (that controls IMDS, not the
169+
// container credentials endpoint). The IPv6 host must be allowed with the
170+
// mode left at its IPv4 default.
171+
Arguments.of("http link-local EKS URI with IPv6, default endpoint mode",
172+
Collections.singletonList(Pair.of(FULL_URI_ENV, EKS_CONTAINER_HOST_IPV6 + "/credentials")),
173+
EKS_CONTAINER_HOST_IPV6 + "/credentials",
174+
new Result().type("success").sdkRequest(
175+
SdkHttpFullRequest.builder()
176+
.uri(URI.create(EKS_CONTAINER_HOST_IPV6 + "/credentials"))
177+
.method(SdkHttpMethod.GET)
178+
.headers(new HashMap<>())
179+
.build())),
180+
167181
Arguments.of("complex full URI",
168182
Collections.singletonList(Pair.of(FULL_URI_ENV, COMPLEX_URI)),
169183
COMPLEX_URI,

0 commit comments

Comments
 (0)