From a796e2e58fc6247912de0e993ec03893a720b28f Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Tue, 3 Nov 2026 19:33:10 -0600 Subject: [PATCH] fix(route53): preserve negative answers through private CNAME chains (#7460) Preserve the target's negative DNS answer while chasing a private CNAME. Cover missing and TXT-only targets, creation/deletion, and positive TTLs. Signed-off-by: Andre Kurait (cherry picked from commit da2e197f93113312212d502ee303e94ac4aa87c7) Co-authored-by: Andre Kurait --- docs/services/route53.md | 2 +- .../route53/Route53DnsRecordSource.java | 3 ++ .../dns/Route53DnsPacketIntegrationTest.java | 39 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/services/route53.md b/docs/services/route53.md index b99fcbb9b7..331f42a63a 100644 --- a/docs/services/route53.md +++ b/docs/services/route53.md @@ -65,7 +65,7 @@ Route53 emulation supporting hosted zones, reusable delegation sets, resource re Floci resolves private hosted zone DNS records directly through its embedded DNS server on port 53. Cluster containers (such as EKS k3s containers) and workloads wired to embedded DNS automatically query Floci as their primary resolver. - **Record Types**: Resolves IPv4 `A` records (including `CNAME` and `ALIAS` target chasing across private zones, EC2 internal names, and external hostnames). When a private CNAME targets a public hostname, Floci resolves the target addresses off the event loop so container stub resolvers succeed. Multiple values are returned as separate answers. -- **TTL and Negative Answers**: Answers carry the record set's `TTL`. A chased `CNAME` chain is flattened to `A` records, so it answers with the shortest TTL in the chain; an alias answers with its target's TTL, and an alias or `CNAME` to a name outside the private zones answers with at most 60 seconds, since Floci cannot see that target's TTL. A name absent from the zone receives NXDOMAIN; a name that exists without an `A` record (only `TXT`, for example, or only records beneath it) receives NOERROR with no answers. A wildcard record such as `*.example.internal` answers only when neither the name nor an ancestor closer than the wildcard exists, so a record at `api.team.example.internal` keeps the wildcard from answering for `team.example.internal` or anything beneath it. +- **TTL and Negative Answers**: Answers carry the record set's `TTL`. A chased `CNAME` chain is flattened to `A` records, so it answers with the shortest TTL in the chain; an alias answers with its target's TTL, and an alias or `CNAME` to a name outside the private zones answers with at most 60 seconds, since Floci cannot see that target's TTL. A name absent from the zone receives NXDOMAIN; a name that exists without an `A` record (only `TXT`, for example, or only records beneath it) receives NOERROR with no answers. A private `CNAME` chain preserves that distinction from its target, including after the target is created or deleted. A wildcard record such as `*.example.internal` answers only when neither the name nor an ancestor closer than the wildcard exists, so a record at `api.team.example.internal` keeps the wildcard from answering for `team.example.internal` or anything beneath it. - **Zone Visibility and Fallthrough**: Private hosted zones (created with a VPC association) retain IPv4 resolution. Public zones support the authoritative record types described below; unowned external domains fall through to upstream forwarders. Because the standard DNS wire protocol carries no caller VPC identifier, Floci resolves across private zones without filtering by account or VPC ID. - **Resolver Rule Precedence**: A Route 53 Resolver rule associated with the querying container's VPC takes precedence over a private hosted zone that matches the same name, as it does in AWS: the query is forwarded to the rule's targets instead of answered from the zone. See [Route 53 Resolver](route53resolver.md#resolver-rules-and-dns-resolution). - **Zero-Restart Propagation**: Record changes via `ChangeResourceRecordSets` take effect immediately without restarts. diff --git a/src/main/java/io/github/hectorvent/floci/services/route53/Route53DnsRecordSource.java b/src/main/java/io/github/hectorvent/floci/services/route53/Route53DnsRecordSource.java index 2902deed2e..f9f4a9f4e1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/route53/Route53DnsRecordSource.java +++ b/src/main/java/io/github/hectorvent/floci/services/route53/Route53DnsRecordSource.java @@ -229,6 +229,9 @@ public class Route53DnsRecordSource implements DnsRecordSource { int cnameTtl = ttlOf(rrs); if (route53Service.isCoveredByPrivateZone(cleanTarget)) { DnsAnswer targetAnswer = resolveAddresses(cleanTarget, visited, depth + 1); + if (targetAnswer.isEmpty()) { + return targetAnswer; + } return DnsAnswer.records(targetAnswer.addresses(), Math.min(cnameTtl, targetAnswer.ttlSeconds())); } diff --git a/src/test/java/io/github/hectorvent/floci/core/common/dns/Route53DnsPacketIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/common/dns/Route53DnsPacketIntegrationTest.java index 60b34754b7..541883ee6a 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/dns/Route53DnsPacketIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/dns/Route53DnsPacketIntegrationTest.java @@ -13,6 +13,8 @@ import io.vertx.core.datagram.DatagramSocketOptions; import jakarta.inject.Inject; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -40,6 +42,43 @@ class Route53DnsPacketIntegrationTest { private final List zoneIds = new ArrayList<>(); + @ParameterizedTest + @CsvSource({"1,1", "2,1", "1,28", "2,28"}) + void privateCnamePreservesMissingTargetResponseAcrossTheWire(int depth, int type) throws Exception { + String name = uniqueName() + ".example"; + String id = route53.createHostedZone(name, UUID.randomUUID().toString(), null, + new VpcAssociation("vpc-cname-negative", "us-east-1")).zone().getId(); + zoneIds.add(id); + String missing = "missing." + name; + for (int hop = 0; hop < depth; hop++) { + String target = hop + 1 == depth ? missing : "alias" + (hop + 1) + "." + name; + change(id, "CREATE", record("alias" + hop + "." + name, "CNAME", 30, target + ".")); + } + + assertEquals(3, ByteBuffer.wrap(query(request(missing, type))).getShort(2) & 15); + byte[] response = query(request("alias0." + name, type)); + assertEquals(3, ByteBuffer.wrap(response).getShort(2) & 15, + "A private CNAME must preserve its target's NXDOMAIN response"); + assertEquals(0, ByteBuffer.wrap(response).getShort(6)); + + ResourceRecordSet text = record(missing, "TXT", 60, "\"present\""); + change(id, "CREATE", text); + byte[] noData = query(request("alias0." + name, type)); + assertEquals(0, ByteBuffer.wrap(noData).getShort(2) & 15); + assertEquals(0, ByteBuffer.wrap(noData).getShort(6)); + change(id, "DELETE", text); + assertEquals(3, ByteBuffer.wrap(query(request("alias0." + name, type))).getShort(2) & 15); + + change(id, "CREATE", record(missing, "A", 600, "192.0.2.17")); + byte[] request = request("alias0." + name, 1); + byte[] restored = query(request); + assertEquals(0, ByteBuffer.wrap(restored).getShort(2) & 15); + assertEquals(1, ByteBuffer.wrap(restored).getShort(6)); + assertEquals(30, ByteBuffer.wrap(restored).getInt(request.length + 6)); + assertArrayEquals(new DnsRecord.Address(1, "192.0.2.17").data(), + Arrays.copyOfRange(restored, restored.length - 4, restored.length)); + } + @AfterEach void deleteOwnedZones() { for (String id : zoneIds.reversed()) {