mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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:
1 parent
ad1fbbc9b9
commit
47d1e10e5c
7 files changed
+124
-4
No files matched your search
@@ -1027,6 +1027,8 @@ class Ec2Tests {
|
||||
.securityGroupIds(ownGroupId)
|
||||
.build());
|
||||
endpointId = created.vpcEndpoint().vpcEndpointId();
|
||||
assertThat(created.vpcEndpoint().ipAddressType()).isEqualTo(IpAddressType.IPV4);
|
||||
assertThat(created.vpcEndpoint().stateAsString()).isEqualTo("available");
|
||||
|
||||
// Asserted on the CREATE response and again on DESCRIBE, because Terraform
|
||||
// reads the ids from one and then re-reads them from the other between plan
|
||||
@@ -1039,6 +1041,8 @@ class Ec2Tests {
|
||||
DescribeVpcEndpointsResponse described = ec2.describeVpcEndpoints(
|
||||
DescribeVpcEndpointsRequest.builder().vpcEndpointIds(endpointId).build());
|
||||
VpcEndpoint ep = described.vpcEndpoints().get(0);
|
||||
assertThat(ep.ipAddressType()).isEqualTo(IpAddressType.IPV4);
|
||||
assertThat(ep.stateAsString()).isEqualTo("available");
|
||||
|
||||
assertThat(ep.networkInterfaceIds())
|
||||
.as("DescribeVpcEndpoints response")
|
||||
|
||||
@@ -222,8 +222,8 @@ Floci seeds the following resources on first use in each region so Terraform, th
|
||||
| ModifyVpcAttribute | Updates supported VPC attributes. |
|
||||
| DescribeVpcAttribute | Returns a supported VPC attribute. |
|
||||
| DescribeVpcEndpointServices | Lists common AWS interface endpoint services and S3 (gateway and interface) in every availability zone, named per partition (see [Partitions](../configuration/partitions.md)). A `ServiceName` filter is echoed back as asked. |
|
||||
| CreateVpcEndpoint | Creates a VPC endpoint record, including its `PolicyDocument` and the per-subnet IPv4 and IPv6 addresses named by `SubnetConfiguration.N`. An `Ipv4` value outside the named subnet's CIDR, or among the first four or the last address AWS reserves in it, is rejected with `InvalidParameterValue`. |
|
||||
| DescribeVpcEndpoints | Lists or returns stored VPC endpoints. |
|
||||
| CreateVpcEndpoint | Creates a VPC endpoint record, including its `PolicyDocument` and the per-subnet IPv4 and IPv6 addresses named by `SubnetConfiguration.N`. `IpAddressType` defaults to `ipv4`. Interface and gateway address types are stored as metadata. Synthesized endpoint interfaces still carry IPv4 only; IPv6 networking is not emulated. An `Ipv4` value outside the named subnet's CIDR, or among the first four or the last address AWS reserves in it, is rejected with `InvalidParameterValue`. |
|
||||
| DescribeVpcEndpoints | Lists or returns stored VPC endpoints, including their IP address type. |
|
||||
| ModifyVpcEndpoint | Associates or disassociates route tables, subnets and security groups, and sets or resets the endpoint policy. `SubnetConfiguration.N` replaces the addresses pinned for a subnet, under the same address validation as CreateVpcEndpoint. `DnsOptions` and `IpAddressType` are accepted and ignored. |
|
||||
| DeleteVpcEndpoints | Deletes VPC endpoint records. |
|
||||
| DescribeVpnGateways | Validates filters and returns empty discovery results; explicit IDs return not-found errors. |
|
||||
|
||||
@@ -2190,7 +2190,7 @@ public class Ec2QueryHandler {
|
||||
p.getFirst("PrivateDnsEnabled") != null ? Boolean.valueOf(p.getFirst("PrivateDnsEnabled")) : null,
|
||||
p.getFirst("PolicyDocument"),
|
||||
parseTagsForResource(p, "vpc-endpoint"),
|
||||
parseSubnetConfigurations(p));
|
||||
parseSubnetConfigurations(p), p.getFirst("IpAddressType"));
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("CreateVpcEndpointResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
@@ -5829,6 +5829,7 @@ public class Ec2QueryHandler {
|
||||
.elem("vpcId", endpoint.getVpcId())
|
||||
.elem("serviceName", endpoint.getServiceName())
|
||||
.elem("state", endpoint.getState())
|
||||
.elem("ipAddressType", endpoint.getIpAddressType())
|
||||
.elem("privateDnsEnabled", String.valueOf(endpoint.isPrivateDnsEnabled()));
|
||||
if (endpoint.getCreationTimestamp() != null) {
|
||||
xml.elem("creationTimestamp", ISO_FMT.format(endpoint.getCreationTimestamp()));
|
||||
|
||||
@@ -4867,6 +4867,19 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
List<String> securityGroupIds, Boolean privateDnsEnabled,
|
||||
String policyDocument, List<Tag> endpointTags,
|
||||
List<VpcEndpointSubnetConfiguration> subnetConfigurations) {
|
||||
return createVpcEndpoint(region, vpcId, serviceName, endpointType, routeTableIds, subnetIds,
|
||||
securityGroupIds, privateDnsEnabled, policyDocument, endpointTags, subnetConfigurations, null);
|
||||
}
|
||||
|
||||
public VpcEndpoint createVpcEndpoint(String region, String vpcId, String serviceName, String endpointType,
|
||||
List<String> routeTableIds, List<String> subnetIds,
|
||||
List<String> securityGroupIds, Boolean privateDnsEnabled,
|
||||
String policyDocument, List<Tag> endpointTags,
|
||||
List<VpcEndpointSubnetConfiguration> subnetConfigurations, String ipAddressType) {
|
||||
if (ipAddressType != null && !Set.of("ipv4", "ipv6", "dualstack").contains(ipAddressType)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"IpAddressType must be ipv4, ipv6, or dualstack.", 400);
|
||||
}
|
||||
ensureDefaultResources(region);
|
||||
getRequiredVpc(region, vpcId);
|
||||
for (String routeTableId : routeTableIds) {
|
||||
@@ -4895,6 +4908,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
endpoint.setVpcId(vpcId);
|
||||
endpoint.setServiceName(serviceName);
|
||||
endpoint.setVpcEndpointType(endpointType != null && !endpointType.isBlank() ? endpointType : "Gateway");
|
||||
endpoint.setIpAddressType(ipAddressType != null ? ipAddressType : "ipv4");
|
||||
boolean isInterface = "Interface".equalsIgnoreCase(endpoint.getVpcEndpointType());
|
||||
endpoint.setPrivateDnsEnabled(privateDnsEnabled != null ? privateDnsEnabled : isInterface);
|
||||
endpoint.setCreationTimestamp(Instant.now());
|
||||
|
||||
@@ -16,6 +16,7 @@ public class VpcEndpoint {
|
||||
private String serviceName;
|
||||
private String vpcEndpointType = "Gateway";
|
||||
private String state = "available";
|
||||
private String ipAddressType = "ipv4";
|
||||
private Instant creationTimestamp;
|
||||
private String region;
|
||||
private List<String> routeTableIds = new ArrayList<>();
|
||||
@@ -49,6 +50,9 @@ public class VpcEndpoint {
|
||||
public String getState() { return state; }
|
||||
public void setState(String state) { this.state = state; }
|
||||
|
||||
public String getIpAddressType() { return ipAddressType; }
|
||||
public void setIpAddressType(String ipAddressType) { this.ipAddressType = ipAddressType; }
|
||||
|
||||
public Instant getCreationTimestamp() { return creationTimestamp; }
|
||||
public void setCreationTimestamp(Instant creationTimestamp) { this.creationTimestamp = creationTimestamp; }
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user