fix(ec2): preserve VPC endpoint IP address types (#5427)

* fix(ec2): preserve SDK endpoint compatibility

Return endpoint states that AWS SDK clients recognize and preserve the
requested address family, so endpoint create and describe responses
round-trip correctly. Keep documented state-filter values working.

* fix(ec2): preserve saved endpoint states and reject invalid IP types

* fix(ec2): reject unsupported endpoint IP types safely

* fix(ec2): retain endpoint states and address-type metadata

---------

Co-authored-by: Jason van Zyl <jason@vanzyl.ca>
This commit is contained in:
David PhillipsandJason van Zyl authored and GitHub committed 2026-10-11 00:34:40 -04:00
1 parent ad1fbbc9b9
commit 47d1e10e5c
7 files changed
+124 -4

No files matched your search

@@ -2797,6 +2797,7 @@ class Ec2IntegrationTest {
.formParam("VpcId", vpcId)
.formParam("ServiceName", "com.amazonaws.us-east-1.s3")
.formParam("VpcEndpointType", "Gateway")
.formParam("IpAddressType", "ipv4")
.formParam("RouteTableId.1", routeTableId)
.formParam("TagSpecification.1.ResourceType", "vpc-endpoint")
.formParam("TagSpecification.1.Tag.1.Key", "Name")
@@ -2808,6 +2809,7 @@ class Ec2IntegrationTest {
.statusCode(200)
.body("CreateVpcEndpointResponse.vpcEndpoint.vpcEndpointId", startsWith("vpce-"))
.body("CreateVpcEndpointResponse.vpcEndpoint.vpcId", equalTo(vpcId))
.body("CreateVpcEndpointResponse.vpcEndpoint.ipAddressType", equalTo("ipv4"))
.body("CreateVpcEndpointResponse.vpcEndpoint.routeTableIdSet.item",
equalTo(routeTableId))
.extract().path("CreateVpcEndpointResponse.vpcEndpoint.vpcEndpointId");
@@ -2827,7 +2829,9 @@ class Ec2IntegrationTest {
.body("DescribeVpcEndpointsResponse.vpcEndpointSet.item.vpcEndpointId",
equalTo(vpcEndpointId))
.body("DescribeVpcEndpointsResponse.vpcEndpointSet.item.serviceName",
equalTo("com.amazonaws.us-east-1.s3"));
equalTo("com.amazonaws.us-east-1.s3"))
.body("DescribeVpcEndpointsResponse.vpcEndpointSet.item.ipAddressType",
equalTo("ipv4"));
}
@Test
@@ -1,9 +1,14 @@
package io.github.hectorvent.floci.services.ec2;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.ArrayList;
import java.util.List;
@@ -18,6 +23,7 @@ import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.xml.HasXPath.hasXPath;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* ModifyVpcEndpoint. A gateway endpoint is normally declared with its route tables and
@@ -32,6 +38,9 @@ class Ec2ModifyVpcEndpointTest {
@Inject
Ec2Service service;
@Inject
ObjectMapper objectMapper;
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ec2/aws4_request";
@@ -68,6 +77,90 @@ class Ec2ModifyVpcEndpointTest {
return ec2("DescribeVpcEndpoints", "VpcEndpointId.1", endpointId);
}
@Test
void endpointStatesUseAwsWireValues() {
Fixture f = fixture("10.89.0.0/16");
assertEquals("available", xmlValue(describe(f.endpointId()), "state"));
assertEquals("deleted", service.deleteVpcEndpoints("us-east-1", List.of(f.endpointId())).getFirst().getState());
}
@Test
void savedEndpointStateAndDefaultIpTypeRemainCompatible() throws Exception {
Fixture f = fixture("10.86.0.0/16");
VpcEndpoint saved = service.describeVpcEndpoints("us-east-1", List.of(f.endpointId()), Map.of()).getFirst();
objectMapper.readerForUpdating(saved).readValue("{\"state\":\"available\"}");
assertEquals("available", xmlValue(describe(f.endpointId()), "state"));
String filtered = ec2("DescribeVpcEndpoints", "VpcEndpointId.1", f.endpointId(),
"Filter.1.Name", "vpc-endpoint-state", "Filter.1.Value.1", "available");
assertEquals(f.endpointId(), xmlValue(filtered, "vpcEndpointId"));
assertEquals("ipv4", xmlValue(filtered, "ipAddressType"));
}
@Test
void endpointStateFilterPreservesDocumentedSpelling() throws Exception {
Fixture f = fixture("10.82.0.0/16");
VpcEndpoint saved = service.describeVpcEndpoints("us-east-1", List.of(f.endpointId()), Map.of()).getFirst();
objectMapper.readerForUpdating(saved).readValue("{\"state\":\"pendingAcceptance\"}");
String filtered = ec2("DescribeVpcEndpoints", "VpcEndpointId.1", f.endpointId(),
"Filter.1.Name", "vpc-endpoint-state", "Filter.1.Value.1", "pendingAcceptance");
assertEquals(f.endpointId(), xmlValue(filtered, "vpcEndpointId"));
}
@ParameterizedTest
@NullAndEmptySource
void missingSavedEndpointStateDoesNotBreakFilters(String state) throws Exception {
Fixture f = fixture("10.84.0.0/16");
VpcEndpoint saved = service.describeVpcEndpoints("us-east-1", List.of(f.endpointId()), Map.of()).getFirst();
objectMapper.readerForUpdating(saved).readValue(state == null ? "{\"state\":null}" : "{\"state\":\"\"}");
String filtered = ec2("DescribeVpcEndpoints", "VpcEndpointId.1", f.endpointId(),
"Filter.1.Name", "vpc-endpoint-state", "Filter.1.Value.1", "available");
assertNull(xmlValue(filtered, "vpcEndpointId"));
}
@ParameterizedTest
@ValueSource(strings = {"ipv4", "ipv6", "dualstack"})
void interfaceAddressTypeRoundTripsAsMetadata(String ipAddressType) {
String vpcId = xmlValue(ec2("CreateVpc", "CidrBlock", "10.83.0.0/16"), "vpcId");
String subnetId = xmlValue(ec2("CreateSubnet", "VpcId", vpcId,
"CidrBlock", "10.83.1.0/24"), "subnetId");
String created = ec2("CreateVpcEndpoint", "VpcId", vpcId,
"ServiceName", "com.amazonaws.us-east-1.s3", "VpcEndpointType", "Interface",
"SubnetId.1", subnetId, "IpAddressType", ipAddressType);
String endpointId = xmlValue(created, "vpcEndpointId");
assertEquals(ipAddressType, xmlValue(created, "ipAddressType"));
assertEquals(ipAddressType, xmlValue(describe(endpointId), "ipAddressType"));
assertEquals(1, service.endpointNetworkInterfaces("us-east-1").stream()
.filter(networkInterface -> networkInterface.getSubnetId().equals(subnetId)).count());
}
@ParameterizedTest
@ValueSource(strings = {"ipv4", "ipv6", "dualstack"})
void endpointIpAddressTypeRoundTrips(String ipAddressType) {
String vpcId = xmlValue(ec2("CreateVpc", "CidrBlock", "10.87.0.0/16"), "vpcId");
String created = ec2("CreateVpcEndpoint", "VpcId", vpcId,
"ServiceName", "com.amazonaws.us-east-1.s3", "IpAddressType", ipAddressType);
assertEquals(ipAddressType, xmlValue(created, "ipAddressType"));
assertEquals(ipAddressType, xmlValue(describe(xmlValue(created, "vpcEndpointId")), "ipAddressType"));
}
@ParameterizedTest
@ValueSource(strings = {"bogus", "IPv4", "", " "})
void invalidEndpointIpAddressTypeDoesNotCreateResources(String ipAddressType) {
String vpcId = xmlValue(ec2("CreateVpc", "CidrBlock", "10.88.0.0/16"), "vpcId");
int before = service.describeVpcEndpoints("us-east-1", List.of(), Map.of()).size();
given().header("Authorization", AUTH_HEADER)
.formParam("Action", "CreateVpcEndpoint")
.formParam("VpcId", vpcId)
.formParam("ServiceName", "com.amazonaws.us-east-1.s3")
.formParam("IpAddressType", ipAddressType)
.formParam("TagSpecification.1.ResourceType", "vpc-endpoint")
.formParam("TagSpecification.1.Tag.1.Key", "Name")
.formParam("TagSpecification.1.Tag.1.Value", "invalid-ip-type")
.when().post("/").then().statusCode(400)
.body(hasXPath("//*[local-name()='Code']", equalTo("InvalidParameterValue")));
assertEquals(before, service.describeVpcEndpoints("us-east-1", List.of(), Map.of()).size());
}
@Test
void addRouteTableIdAssociatesTheRouteTable() {
Fixture f = fixture("10.90.0.0/16");