Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

feat(ec2): report DnsEntries for interface VPC endpoints (#3895)

Matthew Ingleb10b81d253ec
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java
index 616f389f22..f96ea84606 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisioner.java
@@ -12,6 +12,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
/**
* CloudFormation provisioning for {@code AWS::EC2::VPCEndpoint}.
@@ -68,6 +69,9 @@ public class Ec2VpcEndpointCfnProvisioner implements CfnResourceProvisioner {
if (endpoint.getCreationTimestamp() != null) {
r.getAttributes().put("CreationTimestamp", ISO_FMT.format(endpoint.getCreationTimestamp()));
}
+ r.getAttributes().put("DnsEntries", ec2Service.endpointDnsEntries(endpoint).stream()
+ .map(entry -> entry.hostedZoneId() + ":" + entry.dnsName())
+ .collect(Collectors.joining(",")));
if (previousEndpointId != null && !previousEndpointId.equals(endpoint.getVpcEndpointId())) {
deleteReplacedEndpoint(previousEndpointId, ctx.region());
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java
index 2b9c6f1043..1ab5cb2445 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java
@@ -5489,6 +5489,17 @@ public class Ec2QueryHandler {
xml.start("item").elem("groupId", securityGroupId).end("item");
}
xml.end("groupSet");
+ List<VpcEndpointDnsEntry> dnsEntries = service.endpointDnsEntries(endpoint);
+ if (!dnsEntries.isEmpty()) {
+ xml.start("dnsEntrySet");
+ for (VpcEndpointDnsEntry entry : dnsEntries) {
+ xml.start("item")
+ .elem("dnsName", entry.dnsName())
+ .elem("hostedZoneId", entry.hostedZoneId())
+ .end("item");
+ }
+ xml.end("dnsEntrySet");
+ }
xml.raw(tagSetXml(endpoint.getTags()));
return xml.build();
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
index febf7b4973..7e294ce65b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2Service.java
@@ -13,11 +13,13 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
+import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiPredicate;
@@ -103,6 +105,7 @@ import io.github.hectorvent.floci.services.ec2.model.Vpc;
import io.github.hectorvent.floci.services.ec2.model.VpcCidrBlockAssociation;
import io.github.hectorvent.floci.services.ec2.model.VpcIpv6CidrBlockAssociation;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpoint;
+import io.github.hectorvent.floci.services.ec2.model.VpcEndpointDnsEntry;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpointSubnetConfiguration;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnection;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnectionStateReason;
@@ -143,6 +146,18 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
Pattern.compile("^tgw-attach-[0-9a-f]{8}([0-9a-f]{9})?$");
private static final Set<String> ROUTE_TABLE_MEMBERSHIP_FILTER_NAMES =
Set.of("resource-id", "resource-type", "transit-gateway-attachment-id");
+ /**
+ * Private DNS names that are not the token in the endpoint service name, empty for the
+ * services AWS serves no private name for.
+ */
+ private static final Map<String, String> PRIVATE_DNS_NAMES = Map.of(
+ "kinesis-streams", "kinesis",
+ "kinesis-firehose", "firehose",
+ "dkr.ecr", "*.dkr.ecr",
+ "execute-api", "*.execute-api",
+ "ecs-agent", "ecs-a",
+ "ecs-telemetry", "ecs-t",
+ "data.iot", "");
// A first launch may need to pull a large AMI-backed image. Keep a finite CloudFormation
// bound, but allow enough time for that legitimate cold-start path before cancellation.
private static final Duration CONTAINER_LAUNCH_TIMEOUT = Duration.ofMinutes(5);
@@ -4012,6 +4027,82 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
return "eni-" + hex.substring(0, 17);
}
+ /**
+ * The {@code DnsEntries} an interface endpoint reports. The names and zones are synthesized
+ * deterministically rather than persisted, so a restart keeps answering with what the caller
+ * first saw, and the private-DNS entry carries its own zone because AWS creates one per
+ * endpoint. One class AWS also serves is not modelled, needing per-service metadata floci
+ * does not hold: the several private names a service such as S3 answers to.
+ */
+ public List<VpcEndpointDnsEntry> endpointDnsEntries(VpcEndpoint endpoint) {
+ if (!"Interface".equalsIgnoreCase(endpoint.getVpcEndpointType())) {
+ return List.of();
+ }
+ String region = endpoint.getRegion();
+ String serviceToken = endpointServiceToken(endpoint.getServiceName(), region);
+ String name = endpoint.getVpcEndpointId() + "-" + endpointDnsDiscriminator(endpoint.getVpcEndpointId());
+ String dnsSuffix = AwsRegions.dnsSuffixFor(region);
+ String domain = serviceToken + "." + region + ".vpce." + dnsSuffix;
+ String hostedZoneId = vpceHostedZoneId(region);
+
+ List<VpcEndpointDnsEntry> entries = new ArrayList<>();
+ entries.add(new VpcEndpointDnsEntry(name + "." + domain, hostedZoneId));
+ endpoint.getSubnetIds().stream()
+ .map(subnetId -> subnets.get(key(region, subnetId)).orElse(null))
+ .filter(Objects::nonNull)
+ .map(Subnet::getAvailabilityZone)
+ .filter(az -> az != null && !az.isBlank())
+ .distinct()
+ .sorted()
+ .forEach(az -> entries.add(new VpcEndpointDnsEntry(name + "-" + az + "." + domain, hostedZoneId)));
+ if (endpoint.isPrivateDnsEnabled() && !serviceToken.startsWith("vpce-svc-")) {
+ String privateName = PRIVATE_DNS_NAMES.getOrDefault(serviceToken, serviceToken);
+ if (!privateName.isEmpty()) {
+ entries.add(new VpcEndpointDnsEntry(privateName + "." + region + "." + dnsSuffix,
+ privateDnsHostedZoneId(endpoint.getVpcEndpointId())));
+ }
+ }
+ return entries;
+ }
+
+ private static String endpointDnsDiscriminator(String endpointId) {
+ String hex = UUID.nameUUIDFromBytes(("vpce-dns|" + endpointId).getBytes(StandardCharsets.UTF_8))
+ .toString().replace("-", "");
+ return hex.substring(0, 8);
+ }
+
+ /**
+ * The service segment of the name. AWS drops the {@code com.amazonaws.<region>} prefix and
+ * reverses what is left, so {@code com.amazonaws.us-east-1.ecr.api} is reached at
+ * {@code api.ecr.<region>.vpce.amazonaws.com}. An endpoint service carries its
+ * {@code vpce-svc-*} identifier as the one trailing segment, which the same rule returns.
+ */
+ private static String endpointServiceToken(String serviceName, String region) {
+ if (serviceName == null || serviceName.isBlank()) {
+ return "unknown";
+ }
+ List<String> parts = List.of(serviceName.split("\\."));
+ int regionAt = region == null ? -1 : parts.indexOf(region);
+ if (regionAt < 0 || regionAt == parts.size() - 1) {
+ return parts.get(parts.size() - 1);
+ }
+ List<String> serviceParts = new ArrayList<>(parts.subList(regionAt + 1, parts.size()));
+ Collections.reverse(serviceParts);
+ return String.join(".", serviceParts);
+ }
+
+ private static String vpceHostedZoneId(String region) {
+ String hex = UUID.nameUUIDFromBytes(("vpce-zone|" + region).getBytes(StandardCharsets.UTF_8))
+ .toString().replace("-", "").toUpperCase(Locale.ROOT);
+ return "Z" + hex.substring(0, 13);
+ }
+
+ private static String privateDnsHostedZoneId(String endpointId) {
+ String hex = UUID.nameUUIDFromBytes(("vpce-private-zone|" + endpointId).getBytes(StandardCharsets.UTF_8))
+ .toString().replace("-", "").toUpperCase(Locale.ROOT);
+ return "Z" + hex.substring(0, 13);
+ }
+
/**
* The interface address for one of the endpoint's subnets. An address the caller pinned
* through {@code SubnetConfiguration} wins outright: AWS fixes that address on the interface,
diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/model/VpcEndpointDnsEntry.java b/src/main/java/io/github/hectorvent/floci/services/ec2/model/VpcEndpointDnsEntry.java
new file mode 100644
index 0000000000..83084f5b8b
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/model/VpcEndpointDnsEntry.java
@@ -0,0 +1,12 @@
+package io.github.hectorvent.floci.services.ec2.model;
+
+/**
+ * One {@code DnsEntry} of an interface VPC endpoint: a name the endpoint answers to, and the
+ * zone holding that name.
+ *
+ * @see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DnsEntry.html">AWS EC2 DnsEntry</a>
+ */
+public record VpcEndpointDnsEntry(
+ String dnsName,
+ String hostedZoneId
+) {}
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java
index 5ce4776448..62f88fcae8 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationVpcEndpointIntegrationTest.java
@@ -6,6 +6,10 @@ import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* End-to-end check that CloudFormation provisions AWS::EC2::VPCEndpoint for
@@ -67,9 +71,9 @@ class CloudFormationVpcEndpointIntegrationTest {
.then()
.statusCode(200)
.extract().asString();
- org.junit.jupiter.api.Assertions.assertTrue(stackDescription.contains("<StackStatus>CREATE_COMPLETE</StackStatus>"));
+ assertTrue(stackDescription.contains("<StackStatus>CREATE_COMPLETE</StackStatus>"));
String endpointId = XmlParser.extractFirst(stackDescription, "OutputValue", null);
- org.junit.jupiter.api.Assertions.assertNotNull(endpointId);
+ assertNotNull(endpointId);
given()
.contentType("application/x-www-form-urlencoded")
@@ -89,6 +93,80 @@ class CloudFormationVpcEndpointIntegrationTest {
.then()
.statusCode(200)
.extract().asString();
- org.junit.jupiter.api.Assertions.assertFalse(endpointsAfterDelete.contains(endpointId));
+ assertFalse(endpointsAfterDelete.contains(endpointId));
+ }
+
+ @Test
+ void createStackPublishesTheDnsEntriesAttribute() {
+ String stackName = "cfn-vpce-dns-" + Long.toString(System.nanoTime(), 36);
+
+ String template = """
+ {
+ "Resources": {
+ "Vpc": {"Type": "AWS::EC2::VPC", "Properties": {"CidrBlock": "10.62.0.0/16"}},
+ "Subnet": {
+ "Type": "AWS::EC2::Subnet",
+ "Properties": {
+ "VpcId": {"Ref": "Vpc"},
+ "CidrBlock": "10.62.1.0/24",
+ "AvailabilityZone": "us-east-1a"
+ }
+ },
+ "Endpoint": {
+ "Type": "AWS::EC2::VPCEndpoint",
+ "Properties": {
+ "VpcId": {"Ref": "Vpc"},
+ "ServiceName": "com.amazonaws.us-east-1.ecr.api",
+ "VpcEndpointType": "Interface",
+ "SubnetIds": [{"Ref": "Subnet"}]
+ }
+ }
+ },
+ "Outputs": {
+ "Entries": {"Value": {"Fn::GetAtt": ["Endpoint", "DnsEntries"]}}
+ }
+ }
+ """;
+
+ given()
+ .contentType("application/x-www-form-urlencoded")
+ .header("Authorization", CFN_AUTH)
+ .formParam("Action", "CreateStack")
+ .formParam("StackName", stackName)
+ .formParam("TemplateBody", template)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ String stackDescription = given()
+ .contentType("application/x-www-form-urlencoded")
+ .header("Authorization", CFN_AUTH)
+ .formParam("Action", "DescribeStacks")
+ .formParam("StackName", stackName)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().asString();
+
+ String entries = XmlParser.extractFirst(stackDescription, "OutputValue", null);
+ assertNotNull(entries);
+ String[] pairs = entries.split(",");
+ assertEquals(3, pairs.length, "regional, one zone, then private DNS, got " + entries);
+ assertTrue(pairs[0].matches("Z[0-9A-Z]+:vpce-[0-9a-f]+-[0-9a-f]+\\.api\\.ecr\\.us-east-1\\.vpce\\.amazonaws\\.com"),
+ "first entry should be hostedZoneId:regionalName, got " + pairs[0]);
+ assertTrue(pairs[1].contains("-us-east-1a."),
+ "second entry should be the zonal name, got " + pairs[1]);
+
+ given()
+ .contentType("application/x-www-form-urlencoded")
+ .header("Authorization", CFN_AUTH)
+ .formParam("Action", "DeleteStack")
+ .formParam("StackName", stackName)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java
index d4688df301..3b1ee980b4 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2VpcEndpointCfnProvisionerTest.java
@@ -9,6 +9,7 @@ import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplate
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpoint;
+import io.github.hectorvent.floci.services.ec2.model.VpcEndpointDnsEntry;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -125,6 +126,26 @@ class Ec2VpcEndpointCfnProvisionerTest {
assertEquals("vpce-123", r.getPhysicalId());
assertEquals("vpce-123", r.getAttributes().get("Id"));
assertEquals("2026-08-13T10:15:30.000Z", r.getAttributes().get("CreationTimestamp"));
+ assertEquals("", r.getAttributes().get("DnsEntries"));
+ }
+
+ @Test
+ void dnsEntriesPairTheZoneWithTheNameAndJoinOnCommas() {
+ when(ec2.createVpcEndpoint(anyString(), anyString(), anyString(), anyString(),
+ anyList(), anyList(), anyList(), any(), any(), anyList()))
+ .thenReturn(endpoint("vpce-entries"));
+ when(ec2.endpointDnsEntries(any())).thenReturn(List.of(
+ new VpcEndpointDnsEntry("vpce-entries-ab12cd34.s3.us-east-1.vpce.amazonaws.com", "ZREGIONAL"),
+ new VpcEndpointDnsEntry("s3.us-east-1.amazonaws.com", "ZPRIVATE")));
+ StackResource r = resource();
+
+ provisioner.provision(r, mapper.createObjectNode()
+ .put("VpcId", "vpc-1")
+ .put("ServiceName", "com.amazonaws.us-east-1.s3")
+ .put("VpcEndpointType", "Interface"), ctx());
+
+ assertEquals("ZREGIONAL:vpce-entries-ab12cd34.s3.us-east-1.vpce.amazonaws.com,"
+ + "ZPRIVATE:s3.us-east-1.amazonaws.com", r.getAttributes().get("DnsEntries"));
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2VpcEndpointDnsEntriesIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2VpcEndpointDnsEntriesIntegrationTest.java
new file mode 100644
index 0000000000..a17ebacb86
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2VpcEndpointDnsEntriesIntegrationTest.java
@@ -0,0 +1,248 @@
+package io.github.hectorvent.floci.services.ec2;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.path.xml.XmlPath;
+import io.restassured.specification.RequestSpecification;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The {@code DnsEntries} an interface endpoint reports, which is how a caller finds the name to
+ * point a Route 53 alias at. AWS orders them by class: regional, zonal, then the private-DNS
+ * name. Terraform's aws_vpc_endpoint exposes the list positionally as {@code dns_entry}, so the
+ * first entry has to be the regional one.
+ *
+ * <p>The service segment is not the last segment of the service name: AWS drops
+ * {@code com.amazonaws.<region>} and reverses what is left, so an {@code ecr.api} endpoint is
+ * reached at {@code api.ecr.<region>.vpce.amazonaws.com}.
+ *
+ * @see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpoints.html">DescribeVpcEndpoints</a>
+ */
+@QuarkusTest
+class Ec2VpcEndpointDnsEntriesIntegrationTest {
+
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ec2/aws4_request";
+
+ private static final String CN_AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=test/20260205/cn-north-1/ec2/aws4_request";
+
+ private static final String ENTRIES =
+ "DescribeVpcEndpointsResponse.vpcEndpointSet.item.dnsEntrySet.item";
+
+ private String ec2Value(String action, String element, String... formParams) {
+ return ec2ValueWithHeader(AUTH_HEADER, action, element, formParams);
+ }
+
+ private String ec2ValueWithHeader(String authHeader, String action, String element, String... formParams) {
+ RequestSpecification req = given().formParam("Action", action)
+ .header("Authorization", authHeader);
+ for (int i = 0; i < formParams.length; i += 2) {
+ req = req.formParam(formParams[i], formParams[i + 1]);
+ }
+ return req.when().post("/").then().statusCode(200).extract().path(element);
+ }
+
+ private String createVpc(String cidr) {
+ return ec2Value("CreateVpc", "CreateVpcResponse.vpc.vpcId", "CidrBlock", cidr);
+ }
+
+ private String createSubnet(String vpcId, String cidr, String availabilityZone) {
+ return ec2Value("CreateSubnet", "CreateSubnetResponse.subnet.subnetId",
+ "VpcId", vpcId, "CidrBlock", cidr, "AvailabilityZone", availabilityZone);
+ }
+
+ private XmlPath describeEndpoint(String endpointId) {
+ return given()
+ .formParam("Action", "DescribeVpcEndpoints")
+ .formParam("VpcEndpointId.1", endpointId)
+ .header("Authorization", AUTH_HEADER)
+ .when().post("/")
+ .then().statusCode(200)
+ .extract().xmlPath();
+ }
+
+ private List<String> dnsNamesOf(String endpointId) {
+ return describeEndpoint(endpointId).getList(ENTRIES + ".dnsName", String.class);
+ }
+
+ private List<String> hostedZoneIdsOf(String endpointId) {
+ return describeEndpoint(endpointId).getList(ENTRIES + ".hostedZoneId", String.class);
+ }
+
+ @Test
+ void anInterfaceEndpointReportsTheRegionalNameThenEachZoneThenThePrivateDnsName() {
+ String vpcId = createVpc("10.70.0.0/16");
+ String subnetA = createSubnet(vpcId, "10.70.1.0/24", "us-east-1a");
+ String subnetB = createSubnet(vpcId, "10.70.2.0/24", "us-east-1b");
+
+ String endpointId = ec2Value("CreateVpcEndpoint",
+ "CreateVpcEndpointResponse.vpcEndpoint.vpcEndpointId",
+ "VpcId", vpcId, "ServiceName", "com.amazonaws.us-east-1.ecr.api",
+ "VpcEndpointType", "Interface", "SubnetId.1", subnetA, "SubnetId.2", subnetB);
+
+ List<String> names = dnsNamesOf(endpointId);
+ assertEquals(4, names.size(), "regional, one per zone, then private DNS, got " + names);
+ assertThat(names.get(0), startsWith(endpointId + "-"));
+ assertThat(names.get(0), endsWith(".api.ecr.us-east-1.vpce.amazonaws.com"));
+ assertThat(names.get(1), endsWith("-us-east-1a.api.ecr.us-east-1.vpce.amazonaws.com"));
+ assertEquals("api.ecr.us-east-1.amazonaws.com", names.get(3));
+
+ List<String> zones = hostedZoneIdsOf(endpointId);
+ assertEquals(zones.get(0), zones.get(1), "the regional and zonal names share one zone");
+ assertThat(zones.get(3), not(zones.get(0)));
+
+ assertEquals(names, dnsNamesOf(endpointId));
+ }
+
+ @Test
+ void anEndpointServiceReportsItsOwnIdentifierAndNoPrivateDnsName() {
+ String vpcId = createVpc("10.72.0.0/16");
+ String subnetId = createSubnet(vpcId, "10.72.1.0/24", "us-east-1a");
+
+ String endpointId = ec2Value("CreateVpcEndpoint",
+ "CreateVpcEndpointResponse.vpcEndpoint.vpcEndpointId",
+ "VpcId", vpcId, "ServiceName", "com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0",
+ "VpcEndpointType", "Interface", "SubnetId.1", subnetId);
+
+ List<String> names = dnsNamesOf(endpointId);
+ assertEquals(2, names.size(), "regional and one zonal name, no private DNS, got " + names);
+ assertThat(names.get(0), endsWith(".vpce-svc-0123456789abcdef0.us-east-1.vpce.amazonaws.com"));
+ assertThat(names.get(1),
+ endsWith("-us-east-1a.vpce-svc-0123456789abcdef0.us-east-1.vpce.amazonaws.com"));
+ }
+
+ /**
+ * What AWS puts in front of {@code .<region>.amazonaws.com} in each advertised service's
+ * private DNS name, empty for a service with no private name. S3 is absent deliberately:
+ * it answers to several, the one class {@code endpointDnsEntries} does not model.
+ */
+ private static final Map<String, String> PRIVATE_DNS_PREFIX_BY_SERVICE = Map.ofEntries(
+ Map.entry("ec2", "ec2"),
+ Map.entry("ec2messages", "ec2messages"),
+ Map.entry("ssm", "ssm"),
+ Map.entry("ssmmessages", "ssmmessages"),
+ Map.entry("logs", "logs"),
+ Map.entry("monitoring", "monitoring"),
+ Map.entry("sts", "sts"),
+ Map.entry("secretsmanager", "secretsmanager"),
+ Map.entry("kms", "kms"),
+ Map.entry("ecr.api", "api.ecr"),
+ Map.entry("ecr.dkr", "*.dkr.ecr"),
+ Map.entry("ecs", "ecs"),
+ Map.entry("ecs-agent", "ecs-a"),
+ Map.entry("ecs-telemetry", "ecs-t"),
+ Map.entry("elasticloadbalancing", "elasticloadbalancing"),
+ Map.entry("sns", "sns"),
+ Map.entry("sqs", "sqs"),
+ Map.entry("kinesis-streams", "kinesis"),
+ Map.entry("kinesis-firehose", "firehose"),
+ Map.entry("states", "states"),
+ Map.entry("events", "events"),
+ Map.entry("lambda", "lambda"),
+ Map.entry("glue", "glue"),
+ Map.entry("athena", "athena"),
+ Map.entry("iot.data", ""),
+ Map.entry("execute-api", "*.execute-api"));
+
+ static Stream<Arguments> advertisedServicePrivateDnsNames() {
+ return PRIVATE_DNS_PREFIX_BY_SERVICE.entrySet().stream()
+ .sorted(Map.Entry.comparingByKey())
+ .map(entry -> Arguments.of(
+ "com.amazonaws.us-east-1." + entry.getKey(),
+ entry.getValue().isEmpty() ? "" : entry.getValue() + ".us-east-1.amazonaws.com"));
+ }
+
+ @Test
+ void everyAdvertisedServiceHasAPrivateDnsNameDecision() {
+ List<String> advertised = given()
+ .formParam("Action", "DescribeVpcEndpointServices")
+ .header("Authorization", AUTH_HEADER)
+ .when().post("/")
+ .then().statusCode(200)
+ .extract().xmlPath()
+ .getList("DescribeVpcEndpointServicesResponse.serviceNameSet.item", String.class);
+
+ List<String> undecided = advertised.stream()
+ .map(name -> name.replace("com.amazonaws.us-east-1.", ""))
+ .filter(name -> !name.equals("s3"))
+ .filter(name -> !PRIVATE_DNS_PREFIX_BY_SERVICE.containsKey(name))
+ .toList();
+ assertEquals(List.of(), undecided,
+ "add these to PRIVATE_DNS_PREFIX_BY_SERVICE with the prefix AWS answers for them");
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("advertisedServicePrivateDnsNames")
+ void thePrivateDnsNameIsTheOneAwsAnswersFor(String serviceName, String expectedPrivateName) {
+ String vpcId = createVpc("10.76.0.0/16");
+ String subnetId = createSubnet(vpcId, "10.76.1.0/24", "us-east-1a");
+
+ String endpointId = ec2Value("CreateVpcEndpoint",
+ "CreateVpcEndpointResponse.vpcEndpoint.vpcEndpointId",
+ "VpcId", vpcId, "ServiceName", serviceName,
+ "VpcEndpointType", "Interface", "SubnetId.1", subnetId);
+
+ List<String> names = dnsNamesOf(endpointId);
+ if (expectedPrivateName.isEmpty()) {
+ assertEquals(2, names.size(), "regional and one zone, no private name, got " + names);
+ } else {
+ assertEquals(3, names.size(), "regional, one zone, then private name, got " + names);
+ assertEquals(expectedPrivateName, names.get(2));
+ }
+ }
+
+ @Test
+ void aChinaRegionEndpointUsesItsPartitionDnsSuffix() {
+ String vpcId = ec2ValueWithHeader(CN_AUTH_HEADER, "CreateVpc", "CreateVpcResponse.vpc.vpcId",
+ "CidrBlock", "10.95.0.0/16");
+ String subnetId = ec2ValueWithHeader(CN_AUTH_HEADER, "CreateSubnet", "CreateSubnetResponse.subnet.subnetId",
+ "VpcId", vpcId, "CidrBlock", "10.95.1.0/24", "AvailabilityZone", "cn-north-1a");
+
+ List<String> names = given()
+ .formParam("Action", "CreateVpcEndpoint")
+ .formParam("VpcId", vpcId)
+ .formParam("ServiceName", "com.amazonaws.cn-north-1.monitoring")
+ .formParam("VpcEndpointType", "Interface")
+ .formParam("SubnetId.1", subnetId)
+ .header("Authorization", CN_AUTH_HEADER)
+ .when().post("/")
+ .then().statusCode(200)
+ .extract().xmlPath()
+ .getList("CreateVpcEndpointResponse.vpcEndpoint.dnsEntrySet.item.dnsName", String.class);
+
+ assertEquals(3, names.size(), "regional, one zone, then private DNS, got " + names);
+ assertThat(names, everyItem(endsWith(".amazonaws.com.cn")));
+ }
+
+ @Test
+ void aGatewayEndpointReportsNoDnsEntries() {
+ String vpcId = createVpc("10.71.0.0/16");
+ String endpointId = ec2Value("CreateVpcEndpoint",
+ "CreateVpcEndpointResponse.vpcEndpoint.vpcEndpointId",
+ "VpcId", vpcId, "ServiceName", "com.amazonaws.us-east-1.s3", "VpcEndpointType", "Gateway");
+
+ String body = given()
+ .formParam("Action", "DescribeVpcEndpoints")
+ .formParam("VpcEndpointId.1", endpointId)
+ .header("Authorization", AUTH_HEADER)
+ .when().post("/")
+ .then().statusCode(200).extract().asString();
+ assertThat(body, not(containsString("dnsEntrySet")));
+ }
+}
diff --git a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv
index 4d5428b8fe..3bca27a4d1 100644
--- a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv
+++ b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv
@@ -16,7 +16,6 @@ AWS::EC2::Subnet NetworkAclAssociationId the subnet's default network ACL associ
AWS::EC2::VPC CidrBlockAssociations needs association ids Floci's VPC model does not track
AWS::EC2::VPC DefaultNetworkAcl needs a default network ACL Floci does not create with the VPC
AWS::EC2::VPC Ipv6CidrBlocks IPv6 CIDR association is not emulated
-AWS::EC2::VPCEndpoint DnsEntries endpoint DNS entries are not emulated
AWS::EC2::VPCEndpoint NetworkInterfaceIds endpoint ENIs are not created
AWS::EC2::VPCGatewayAttachment AttachmentType the exact literal AWS returns (internet vs vpn gateway) is not given by the schema
AWS::Kinesis::Stream WarmThroughputObject warm throughput is not an emulated Kinesis feature