mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(route53): serve public A and AAAA DNS records (#8926)
* feat(route53): serve public A and AAAA DNS records Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
dd0f2bfc3a
commit
74938f0e8a
3 files changed
+74
-10
No files matched your search
@@ -73,13 +73,13 @@ Floci resolves private hosted zone DNS records directly through its embedded DNS
|
||||
|
||||
## Public Authoritative DNS
|
||||
|
||||
The same embedded UDP server serves stored public `TXT`, `NS`, and `SOA` records with authoritative answers and their configured TTLs. DNS clients must be able to reach Floci on UDP port 53. The HTTP endpoint published by Testcontainers wrappers does not publish this UDP listener. Host clients need an explicit UDP port mapping; containers on the same network can query Floci's container address directly.
|
||||
The same embedded UDP server serves stored public `A`, `AAAA`, `TXT`, `NS`, and `SOA` records with authoritative answers and their configured TTLs. Address records preserve every value in the selected simple record set. DNS clients must be able to reach Floci on UDP port 53. The HTTP endpoint published by Testcontainers wrappers does not publish this UDP listener. Host clients need an explicit UDP port mapping; containers on the same network can query Floci's container address directly.
|
||||
|
||||
For a Docker host client, publish UDP separately from HTTP, for example `-p 5353:53/udp`, then query `dig @127.0.0.1 -p 5353 example.com TXT`. Configure the equivalent UDP binding explicitly when using a Testcontainers wrapper; its standard HTTP port mapping is insufficient.
|
||||
For a Docker host client, publish UDP separately from HTTP on loopback, for example `-p 127.0.0.1:5353:53/udp`, then query `dig @127.0.0.1 -p 5353 example.com TXT`. Configure the equivalent loopback UDP binding explicitly when using a Testcontainers wrapper; its standard HTTP port mapping is insufficient.
|
||||
|
||||
The longest matching public zone answers. Missing names return NXDOMAIN; existing names without the requested supported type return NOERROR with no answers. Both include the zone SOA with the smaller of its TTL and minimum field for negative caching. Changes and deletes affect DNS through the same stored record sets as the Route 53 API.
|
||||
|
||||
Public address routing, aliases, CNAME chasing, health-based or weighted record selection, and delegation referrals are not implemented. Queries for supported types that require these features, ambiguous duplicate public zones, or malformed stored records return REFUSED without claiming authority. Other query types retain the existing emulator-name and upstream resolution paths. Private-zone and VPC forwarding-rule precedence remains unchanged. UDP responses honor legacy/EDNS size limits and set truncation when necessary; TCP fallback is not implemented.
|
||||
Public aliases, CNAME chasing, health-based or weighted record selection, and delegation referrals are not implemented. Queries for supported types that require these features, ambiguous duplicate public zones, or malformed stored records return REFUSED without claiming authority. Other query types retain the existing emulator-name and upstream resolution paths. Private-zone and VPC forwarding-rule precedence remains unchanged. UDP responses honor legacy/EDNS size limits and set truncation when necessary; TCP fallback is not implemented.
|
||||
|
||||
## Default Nameservers
|
||||
|
||||
@@ -215,4 +215,4 @@ the record. DELETE still requires matching record values and routing properties.
|
||||
- Query logging configs
|
||||
- DNSSEC (key signing keys, enabling/disabling)
|
||||
- `TestDNSAnswer`
|
||||
- Public authoritative record types other than simple TXT, NS, and SOA; public routing policies, delegation referrals, and DNS-over-TCP
|
||||
- Public authoritative record types other than simple A, AAAA, TXT, NS, and SOA; public aliases, routing policies, delegation referrals, and DNS-over-TCP
|
||||
@@ -29,7 +29,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Resolves private IPv4/SRV records and public TXT/NS/SOA records for the embedded DNS server.
|
||||
* Resolves private IPv4/SRV records and public A/AAAA/TXT/NS/SOA records for the embedded DNS server.
|
||||
*
|
||||
* <p>Discovered via CDI as a {@link DnsRecordSource} implementation, keeping
|
||||
* the embedded DNS server decoupled from Route 53 service classes.
|
||||
@@ -75,7 +75,7 @@ public class Route53DnsRecordSource implements DnsRecordSource {
|
||||
|
||||
@Override
|
||||
public Optional<DnsAnswer> resolveAuthoritative(String name, int type) {
|
||||
if (name == null || name.isBlank() || (type != 2 && type != 6 && type != 16)) {
|
||||
if (name == null || name.isBlank() || (type != 1 && type != 2 && type != 6 && type != 16 && type != 28)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (route53Service.isCoveredByPrivateZone(name)) {
|
||||
@@ -107,11 +107,14 @@ public class Route53DnsRecordSource implements DnsRecordSource {
|
||||
return Optional.of(DnsAnswer.refused());
|
||||
}
|
||||
String recordType = switch (type) {
|
||||
case 1 -> "A";
|
||||
case 28 -> "AAAA";
|
||||
case 2 -> "NS";
|
||||
case 6 -> "SOA";
|
||||
default -> "TXT";
|
||||
};
|
||||
Function<String, DnsRecord> recordFactory = switch (type) {
|
||||
case 1, 28 -> value -> new DnsRecord.Address(type, value);
|
||||
case 2 -> DnsRecord.Ns::new;
|
||||
case 6 -> DnsRecord.Soa::new;
|
||||
default -> DnsRecord.Txt::new;
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.floci.aws.services.route53.Route53Service;
|
||||
import io.floci.aws.services.route53.model.ResourceRecord;
|
||||
import io.floci.aws.services.route53.model.ResourceRecordSet;
|
||||
import io.floci.aws.services.route53.model.VpcAssociation;
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
@@ -15,6 +16,8 @@ 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 software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.route53.Route53Client;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
@@ -157,6 +160,63 @@ class Route53DnsPacketIntegrationTest {
|
||||
assertNegative(query(DnsTestQuery.query(endpoint, 16, 0x1234)), name, 3, 900);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"A,1,192.0.2.7,192.0.2.8", "AAAA,28,2001:db8::7,2001:db8::8"})
|
||||
void sdkAddressChangesAndDeletesReachAuthoritativeDns(
|
||||
String recordType, int type, String first, String second) throws Exception {
|
||||
String name = uniqueName() + ".amazonaws.com";
|
||||
String id = createZone(name);
|
||||
String endpoint = "address." + name;
|
||||
try (Route53Client client = AwsTestClients.create(Route53Client.builder(), "test", Region.US_EAST_1)) {
|
||||
for (String value : List.of(first, second)) {
|
||||
client.changeResourceRecordSets(request -> request.hostedZoneId(id).changeBatch(batch -> batch
|
||||
.changes(change -> change.action("UPSERT").resourceRecordSet(record -> record
|
||||
.name(endpoint).type(recordType).ttl(17L)
|
||||
.resourceRecords(resource -> resource.value(value))))));
|
||||
byte[] request = DnsTestQuery.query(endpoint, type, 0x1234);
|
||||
byte[] response = query(request);
|
||||
assertHeader(response, 0, true, 1, 0);
|
||||
assertEquals(type, ByteBuffer.wrap(response).getShort(request.length + 2));
|
||||
assertEquals(17, ByteBuffer.wrap(response).getInt(request.length + 6));
|
||||
assertArrayEquals(new DnsRecord.Address(type, value).data(),
|
||||
Arrays.copyOfRange(response, request.length + 12, response.length));
|
||||
}
|
||||
client.changeResourceRecordSets(request -> request.hostedZoneId(id).changeBatch(batch -> batch
|
||||
.changes(change -> change.action("DELETE").resourceRecordSet(record -> record
|
||||
.name(endpoint).type(recordType).ttl(17L)
|
||||
.resourceRecords(resource -> resource.value(second))))));
|
||||
}
|
||||
assertNegative(query(DnsTestQuery.query(endpoint, type, 0x1234)), name, 3, 900);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"A,1,192.0.2.7,192.0.2.8", "AAAA,28,2001:db8::7,2001:db8::8"})
|
||||
void publicAddressSetsRetainValuesTtlAndNegativeAuthority(
|
||||
String recordType, int type, String first, String second) throws Exception {
|
||||
String name = uniqueName() + ".example";
|
||||
String id = createZone(name);
|
||||
String endpoint = "address." + name;
|
||||
change(id, "CREATE", record(endpoint, recordType, 23, first, second));
|
||||
byte[] request = DnsTestQuery.query(endpoint, type, 0x1234);
|
||||
byte[] response = query(request);
|
||||
assertHeader(response, 0, true, 2, 0);
|
||||
ByteBuffer packet = ByteBuffer.wrap(response);
|
||||
packet.position(request.length);
|
||||
for (String value : List.of(first, second)) {
|
||||
assertEquals(endpoint, EmbeddedDnsServer.readName(packet, response));
|
||||
assertEquals(type, packet.getShort());
|
||||
assertEquals(1, packet.getShort());
|
||||
assertEquals(23, packet.getInt());
|
||||
byte[] address = new byte[Short.toUnsignedInt(packet.getShort())];
|
||||
packet.get(address);
|
||||
assertArrayEquals(new DnsRecord.Address(type, value).data(), address);
|
||||
}
|
||||
assertEquals(0, packet.remaining());
|
||||
int otherAddressType = type == 1 ? 28 : 1;
|
||||
assertNegative(query(DnsTestQuery.query(endpoint, otherAddressType, 0x1234)), name, 0, 900);
|
||||
assertNegative(query(DnsTestQuery.query("missing." + name, type, 0x1234)), name, 3, 900);
|
||||
}
|
||||
|
||||
@Test
|
||||
void delegationNamesAndSoaUseTheStoredZone() throws Exception {
|
||||
String name = uniqueName() + ".example";
|
||||
@@ -224,14 +284,13 @@ class Route53DnsPacketIntegrationTest {
|
||||
change(id, "CREATE", weighted);
|
||||
change(id, "CREATE", record("alias." + name, "CNAME", 60, "target.example."));
|
||||
change(id, "CREATE", record("delegated." + name, "NS", 60, "other.example."));
|
||||
for (int type : List.of(1, 28, 15, 5)) {
|
||||
for (int type : List.of(15, 5)) {
|
||||
assertTrue(source.resolveAuthoritative(name, type).isEmpty());
|
||||
}
|
||||
String awsName = uniqueName() + ".amazonaws.com";
|
||||
createZone(awsName);
|
||||
byte[] address = query(DnsTestQuery.query(awsName, 1, 0x1234));
|
||||
assertArrayEquals(new byte[]{127, 0, 0, 1},
|
||||
Arrays.copyOfRange(address, address.length - 4, address.length));
|
||||
assertNegative(address, awsName, 0, 900);
|
||||
for (String label : List.of("weighted", "alias", "leaf.delegated")) {
|
||||
assertHeader(query(DnsTestQuery.query(label + "." + name, 16, 0x1234)), 5, false, 0, 0);
|
||||
}
|
||||
@@ -266,10 +325,12 @@ class Route53DnsPacketIntegrationTest {
|
||||
void malformedStoredValuesAndTtlsStayRefused() throws Exception {
|
||||
String name = uniqueName() + ".example";
|
||||
String id = createZone(name);
|
||||
for (String type : List.of("TXT", "NS", "SOA")) {
|
||||
for (String type : List.of("A", "AAAA", "TXT", "NS", "SOA")) {
|
||||
String owner = "bad-" + type.toLowerCase() + "." + name;
|
||||
change(id, "UPSERT", record(owner, type, 60, (String) null));
|
||||
int queryType = switch (type) {
|
||||
case "A" -> 1;
|
||||
case "AAAA" -> 28;
|
||||
case "NS" -> 2;
|
||||
case "SOA" -> 6;
|
||||
default -> 16;
|
||||
|
||||
Reference in new issue
Block a user