mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(route53): resolve private SRV records with stored values (#7587)
This commit is contained in:
1 parent
44565360e2
commit
5058163409
6 files changed
+265
-46
No files matched your search
@@ -64,9 +64,9 @@ 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 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.
|
||||
- **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. Simple private `SRV` record sets also resolve, preserving each value's priority, weight (including zero), port, target, and the record set TTL. The target `.` encodes an unavailable service. Malformed SRV values and SRV sets requiring routing policies or health evaluation return REFUSED; SRV CNAME chasing is not implemented.
|
||||
- **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 the requested record type (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) provide IPv4 and SRV 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.
|
||||
- **Kubernetes and external-dns Compatibility**: In-cluster controllers like `external-dns` provisioning Route 53 private records for Services or Ingresses are immediately resolvable.
|
||||
|
||||
@@ -157,8 +157,15 @@ public sealed interface DnsRecord {
|
||||
}
|
||||
}
|
||||
|
||||
record Srv(int port, String target) implements DnsRecord {
|
||||
record Srv(int priority, int weight, int port, String target) implements DnsRecord {
|
||||
public Srv(int port, String target) {
|
||||
this(1, 1, port, target);
|
||||
}
|
||||
|
||||
public Srv {
|
||||
if (priority < 0 || priority > 65535 || weight < 0 || weight > 65535) {
|
||||
throw new IllegalArgumentException("SRV priority and weight must fit unsigned 16-bit fields");
|
||||
}
|
||||
if (port < 0 || port > 65535) {
|
||||
throw new IllegalArgumentException("Invalid SRV port: " + port);
|
||||
}
|
||||
@@ -171,8 +178,8 @@ public sealed interface DnsRecord {
|
||||
|
||||
@Override
|
||||
public byte[] data() {
|
||||
byte[] name = encodeName(target);
|
||||
return ByteBuffer.allocate(6 + name.length).putShort((short) 1).putShort((short) 1)
|
||||
byte[] name = ".".equals(target) ? new byte[]{0} : encodeName(target);
|
||||
return ByteBuffer.allocate(6 + name.length).putShort((short) priority).putShort((short) weight)
|
||||
.putShort((short) port).put(name).array();
|
||||
}
|
||||
}
|
||||
|
||||
+83
-36
@@ -23,11 +23,13 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.ToIntFunction;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Resolves private IPv4 records and public TXT/NS/SOA records for the embedded DNS server.
|
||||
* Resolves private IPv4/SRV records and public 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.
|
||||
@@ -101,42 +103,29 @@ public class Route53DnsRecordSource implements DnsRecordSource {
|
||||
if (soaSet == null || soaSet.getRecords() == null || soaSet.getRecords().size() != 1) {
|
||||
return Optional.of(DnsAnswer.refused());
|
||||
}
|
||||
List<DnsRecord> answers = new ArrayList<>();
|
||||
int ttl = Integer.MAX_VALUE;
|
||||
String recordType = switch (type) {
|
||||
case 2 -> "NS";
|
||||
case 6 -> "SOA";
|
||||
default -> "TXT";
|
||||
};
|
||||
Function<String, DnsRecord> recordFactory = switch (type) {
|
||||
case 2 -> DnsRecord.Ns::new;
|
||||
case 6 -> DnsRecord.Soa::new;
|
||||
default -> DnsRecord.Txt::new;
|
||||
};
|
||||
DnsAnswer answer = buildRecords(name, zone.matchingRecords().stream()
|
||||
.filter(record -> record.getType().equals(recordType)).toList(),
|
||||
recordFactory, Route53DnsRecordSource::publicTtlOf);
|
||||
if (answer.responseCode() != 0) {
|
||||
return Optional.of(answer);
|
||||
}
|
||||
boolean exists = !zone.matchingRecords().isEmpty() || zone.records().stream()
|
||||
.anyMatch(record -> Route53Service.normalizeName(record.getName()).toLowerCase(Locale.ROOT)
|
||||
.endsWith("." + normalized));
|
||||
if (answer.isEmpty()) {
|
||||
answer = exists ? DnsAnswer.noData() : DnsAnswer.nxDomain();
|
||||
}
|
||||
try {
|
||||
for (ResourceRecordSet record : zone.matchingRecords()) {
|
||||
if (!record.getType().equals(switch (type) {
|
||||
case 2 -> "NS";
|
||||
case 6 -> "SOA";
|
||||
default -> "TXT";
|
||||
})) {
|
||||
continue;
|
||||
}
|
||||
if (record.getSetIdentifier() != null || record.getAliasTarget() != null
|
||||
|| record.getWeight() != null || record.getRegion() != null
|
||||
|| record.getFailover() != null || record.getHealthCheckId() != null
|
||||
|| record.getRecords() == null) {
|
||||
return Optional.of(DnsAnswer.refused());
|
||||
}
|
||||
for (ResourceRecord value : record.getRecords()) {
|
||||
if (value == null || value.getValue() == null) {
|
||||
return Optional.of(DnsAnswer.refused());
|
||||
}
|
||||
DnsRecord answer = switch (type) {
|
||||
case 2 -> new DnsRecord.Ns(value.getValue());
|
||||
case 6 -> new DnsRecord.Soa(value.getValue());
|
||||
default -> new DnsRecord.Txt(value.getValue());
|
||||
};
|
||||
answer.data();
|
||||
answers.add(answer);
|
||||
}
|
||||
ttl = Math.min(ttl, publicTtlOf(record));
|
||||
}
|
||||
boolean exists = !zone.matchingRecords().isEmpty() || zone.records().stream()
|
||||
.anyMatch(record -> Route53Service.normalizeName(record.getName()).toLowerCase(Locale.ROOT)
|
||||
.endsWith("." + normalized));
|
||||
DnsAnswer answer = answers.isEmpty() ? (exists ? DnsAnswer.noData() : DnsAnswer.nxDomain())
|
||||
: DnsAnswer.typedRecords(answers, ttl);
|
||||
ResourceRecord soaValue = soaSet.getRecords().getFirst();
|
||||
if (soaValue == null || soaValue.getValue() == null) {
|
||||
return Optional.of(DnsAnswer.refused());
|
||||
@@ -150,6 +139,64 @@ public class Route53DnsRecordSource implements DnsRecordSource {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DnsAnswer> resolve(String name, int type) {
|
||||
if (type != 33) {
|
||||
return DnsRecordSource.super.resolve(name, type);
|
||||
}
|
||||
if (name == null || name.isBlank() || !route53Service.isCoveredByPrivateZone(name)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
List<ResourceRecordSet> sets = route53Service.findPrivateRecordsForName(name);
|
||||
DnsAnswer answer = buildRecords(name, sets.stream()
|
||||
.filter(set -> "SRV".equalsIgnoreCase(set.getType())).toList(),
|
||||
Route53DnsRecordSource::srvRecord, Route53DnsRecordSource::ttlOf);
|
||||
if (answer.responseCode() != 0 || !answer.isEmpty()) {
|
||||
return Optional.of(answer);
|
||||
}
|
||||
return Optional.of(!sets.isEmpty() || route53Service.hasPrivateRecordsBeneath(name)
|
||||
? DnsAnswer.noData() : DnsAnswer.nxDomain());
|
||||
}
|
||||
|
||||
private static DnsRecord srvRecord(String value) {
|
||||
String[] fields = value.trim().split("\\s+");
|
||||
if (fields.length != 4) {
|
||||
throw new IllegalArgumentException("SRV record must contain priority, weight, port and target");
|
||||
}
|
||||
return new DnsRecord.Srv(Integer.parseInt(fields[0]), Integer.parseInt(fields[1]),
|
||||
Integer.parseInt(fields[2]), fields[3]);
|
||||
}
|
||||
|
||||
private static DnsAnswer buildRecords(String name, List<ResourceRecordSet> sets,
|
||||
Function<String, DnsRecord> recordFactory,
|
||||
ToIntFunction<ResourceRecordSet> ttlReader) {
|
||||
List<DnsRecord> records = new ArrayList<>();
|
||||
int ttl = Integer.MAX_VALUE;
|
||||
try {
|
||||
for (ResourceRecordSet set : sets) {
|
||||
if (set.getSetIdentifier() != null || set.getAliasTarget() != null
|
||||
|| set.getWeight() != null || set.getRegion() != null
|
||||
|| set.getFailover() != null || set.getHealthCheckId() != null
|
||||
|| set.getRecords() == null) {
|
||||
return DnsAnswer.refused();
|
||||
}
|
||||
for (ResourceRecord value : set.getRecords()) {
|
||||
if (value == null || value.getValue() == null) {
|
||||
return DnsAnswer.refused();
|
||||
}
|
||||
DnsRecord record = recordFactory.apply(value.getValue());
|
||||
record.data();
|
||||
records.add(record);
|
||||
}
|
||||
ttl = Math.min(ttl, ttlReader.applyAsInt(set));
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.debugv("Cannot encode DNS records for {0}: {1}", name, e.getMessage());
|
||||
return DnsAnswer.refused();
|
||||
}
|
||||
return records.isEmpty() ? DnsAnswer.noData() : DnsAnswer.typedRecords(records, ttl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DnsAnswer> resolveIpv4(String name) {
|
||||
if (name == null || name.isBlank()) {
|
||||
|
||||
@@ -32,6 +32,31 @@ class DnsRecordTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> new DnsRecord.Srv(65536, "task.api.internal"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void srvPreservesUnsignedFieldsAndCloudMapDefaults() {
|
||||
for (int value : List.of(0, 100, 65535)) {
|
||||
ByteBuffer data = ByteBuffer.wrap(new DnsRecord.Srv(value, value, value, "task.example.").data());
|
||||
assertEquals(value, Short.toUnsignedInt(data.getShort()));
|
||||
assertEquals(value, Short.toUnsignedInt(data.getShort()));
|
||||
assertEquals(value, Short.toUnsignedInt(data.getShort()));
|
||||
byte[] target = new byte[data.remaining()];
|
||||
data.get(target);
|
||||
assertArrayEquals(new byte[]{4, 't', 'a', 's', 'k', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, target);
|
||||
}
|
||||
assertArrayEquals(new DnsRecord.Srv(1, 1, 8080, "task.example").data(),
|
||||
new DnsRecord.Srv(8080, "task.example").data());
|
||||
assertArrayEquals(new byte[7], new DnsRecord.Srv(0, 0, 0, ".").data());
|
||||
}
|
||||
|
||||
@Test
|
||||
void srvRejectsOutOfRangePriorityWeightAndPort() {
|
||||
for (int value : List.of(-1, 65536)) {
|
||||
assertThrows(IllegalArgumentException.class, () -> new DnsRecord.Srv(value, 0, 0, "task.example"));
|
||||
assertThrows(IllegalArgumentException.class, () -> new DnsRecord.Srv(0, value, 0, "task.example"));
|
||||
assertThrows(IllegalArgumentException.class, () -> new DnsRecord.Srv(0, 0, value, "task.example"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void namesEncodeLabelsAndIgnoreOneTrailingDot() {
|
||||
assertArrayEquals(new byte[]{1, 'a', 1, 'b', 0}, DnsRecord.encodeName("a.b."));
|
||||
|
||||
+48
-4
@@ -42,6 +42,43 @@ class Route53DnsPacketIntegrationTest {
|
||||
|
||||
private final List<String> zoneIds = new ArrayList<>();
|
||||
|
||||
@Test
|
||||
void privateSrvPreservesEveryFieldAndTtlAcrossTheWire() throws Exception {
|
||||
String zone = uniqueName() + ".example";
|
||||
String id = route53.createHostedZone(zone, UUID.randomUUID().toString(), null,
|
||||
new VpcAssociation("vpc-srv", "us-east-1")).zone().getId();
|
||||
zoneIds.add(id);
|
||||
String name = "_api._tcp." + zone;
|
||||
change(id, "CREATE", record(name, "SRV", 17,
|
||||
"20 0 8080 first." + zone + ".", "10 100 65535 second." + zone));
|
||||
|
||||
byte[] request = request(name, 33);
|
||||
byte[] response = query(request);
|
||||
assertPrivateHeader(response, 0, 2);
|
||||
ByteBuffer packet = ByteBuffer.wrap(response);
|
||||
packet.position(request.length);
|
||||
List<String> values = new ArrayList<>();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertEquals(name, EmbeddedDnsServer.readName(packet, response));
|
||||
assertEquals(33, packet.getShort());
|
||||
assertEquals(1, packet.getShort());
|
||||
assertEquals(17, packet.getInt());
|
||||
int length = Short.toUnsignedInt(packet.getShort());
|
||||
int start = packet.position();
|
||||
values.add(Short.toUnsignedInt(packet.getShort()) + " "
|
||||
+ Short.toUnsignedInt(packet.getShort()) + " "
|
||||
+ Short.toUnsignedInt(packet.getShort()) + " "
|
||||
+ EmbeddedDnsServer.readName(packet, response));
|
||||
assertEquals(start + length, packet.position());
|
||||
}
|
||||
assertEquals(List.of("10 100 65535 second." + zone, "20 0 8080 first." + zone),
|
||||
values.stream().sorted().toList());
|
||||
|
||||
assertPrivateHeader(query(request(name, 1)), 0, 0);
|
||||
assertPrivateHeader(query(request("_tcp." + zone, 33)), 0, 0);
|
||||
assertPrivateHeader(query(request("absent." + zone, 33)), 3, 0);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"1,1", "2,1", "1,28", "2,28"})
|
||||
void privateCnamePreservesMissingTargetResponseAcrossTheWire(int depth, int type) throws Exception {
|
||||
@@ -231,7 +268,7 @@ class Route53DnsPacketIntegrationTest {
|
||||
String id = createZone(name);
|
||||
for (String type : List.of("TXT", "NS", "SOA")) {
|
||||
String owner = "bad-" + type.toLowerCase() + "." + name;
|
||||
change(id, "UPSERT", record(owner, type, 60, null));
|
||||
change(id, "UPSERT", record(owner, type, 60, (String) null));
|
||||
int queryType = switch (type) {
|
||||
case "NS" -> 2;
|
||||
case "SOA" -> 6;
|
||||
@@ -243,7 +280,7 @@ class Route53DnsPacketIntegrationTest {
|
||||
change(id, "UPSERT", record("ttl." + name, "TXT", ttl, "\"value\""));
|
||||
assertHeader(query(request("ttl." + name, 16)), 5, false, 0, 0);
|
||||
}
|
||||
change(id, "UPSERT", record(name, "SOA", 60, null));
|
||||
change(id, "UPSERT", record(name, "SOA", 60, (String) null));
|
||||
assertHeader(query(request("missing." + name, 16)), 5, false, 0, 0);
|
||||
}
|
||||
|
||||
@@ -279,12 +316,12 @@ class Route53DnsPacketIntegrationTest {
|
||||
route53.changeResourceRecordSets(id, List.of(Map.of("action", action, "rrs", record)), null);
|
||||
}
|
||||
|
||||
private static ResourceRecordSet record(String name, String type, long ttl, String value) {
|
||||
private static ResourceRecordSet record(String name, String type, long ttl, String... values) {
|
||||
ResourceRecordSet record = new ResourceRecordSet();
|
||||
record.setName(name);
|
||||
record.setType(type);
|
||||
record.setTtl(ttl);
|
||||
record.setRecords(List.of(new ResourceRecord(value)));
|
||||
record.setRecords(Arrays.stream(values).map(ResourceRecord::new).toList());
|
||||
return record;
|
||||
}
|
||||
|
||||
@@ -299,6 +336,13 @@ class Route53DnsPacketIntegrationTest {
|
||||
.put(encoded).putShort((short) type).putShort((short) 1).array();
|
||||
}
|
||||
|
||||
private static void assertPrivateHeader(byte[] response, int rcode, int answers) {
|
||||
ByteBuffer packet = ByteBuffer.wrap(response);
|
||||
assertEquals(rcode, packet.getShort(2) & 15);
|
||||
assertEquals(answers, packet.getShort(6));
|
||||
assertEquals(0, packet.getShort(8));
|
||||
}
|
||||
|
||||
private static void assertHeader(byte[] response, int rcode, boolean authoritative, int answers, int authorities) {
|
||||
ByteBuffer packet = ByteBuffer.wrap(response);
|
||||
assertEquals(rcode, packet.getShort(2) & 15);
|
||||
|
||||
+96
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.route53;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.dns.DnsAnswer;
|
||||
import io.github.hectorvent.floci.core.common.dns.DnsLookupHelper;
|
||||
import io.github.hectorvent.floci.core.common.dns.DnsRecord;
|
||||
import io.github.hectorvent.floci.services.route53.model.AliasTarget;
|
||||
import io.github.hectorvent.floci.services.route53.model.ResourceRecord;
|
||||
import io.github.hectorvent.floci.services.route53.model.ResourceRecordSet;
|
||||
@@ -11,6 +12,10 @@ import io.quarkus.test.junit.QuarkusTest;
|
||||
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 org.junit.jupiter.params.provider.NullSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@@ -408,6 +413,97 @@ class Route53DnsResolutionTest {
|
||||
assertEquals(List.of("10.0.0.5"), result.get().addresses());
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateSrvParsesWhitespaceAndUnsignedLimits() {
|
||||
String zone = uniqueZone();
|
||||
String id = createPrivateZone(zone);
|
||||
String name = "_api._tcp." + zone;
|
||||
addRecord(id, name, "SRV", " \t65535\t 65535 65535\tTarget." + zone + ". \t", 0L);
|
||||
DnsAnswer answer = dnsRecordSource.resolve(name.toUpperCase() + ".", 33).orElseThrow();
|
||||
assertEquals(0, answer.ttlSeconds());
|
||||
assertEquals(List.of(new DnsRecord.Srv(65535, 65535, 65535, "Target." + zone + ".")), answer.records());
|
||||
addRecord(id, "_unavailable._tcp." + zone, "SRV", "0 0 0 .");
|
||||
assertEquals(List.of(new DnsRecord.Srv(0, 0, 0, ".")),
|
||||
dnsRecordSource.resolve("_unavailable._tcp." + zone, 33).orElseThrow().records());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({", 60", "-1, 60", "0, 0", "42, 42", "2147483647, 2147483647", "2147483648, 2147483647"})
|
||||
void privateSrvPreservesDefaultAndClampedTtls(Long ttl, int expectedTtl) {
|
||||
String zone = uniqueZone();
|
||||
String id = createPrivateZone(zone);
|
||||
String name = "_api._tcp." + zone;
|
||||
ResourceRecordSet set = new ResourceRecordSet();
|
||||
set.setName(name);
|
||||
set.setType("SRV");
|
||||
set.setTtl(ttl);
|
||||
set.setRecords(List.of(new ResourceRecord("0 0 8080 target." + zone)));
|
||||
route53Service.changeResourceRecordSets(id, List.of(Map.of("action", "CREATE", "rrs", set)), null);
|
||||
|
||||
DnsAnswer answer = dnsRecordSource.resolve(name, 33).orElseThrow();
|
||||
assertEquals(0, answer.responseCode());
|
||||
assertEquals(expectedTtl, answer.ttlSeconds());
|
||||
assertEquals(List.of(new DnsRecord.Srv(0, 0, 8080, "target." + zone)), answer.records());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {"", "0 1 80", "0 1 80 target.example extra", "bad 1 80 target.example",
|
||||
"-1 1 80 target.example", "65536 1 80 target.example", "0 -1 80 target.example",
|
||||
"0 65536 80 target.example", "0 1 -1 target.example", "0 1 65536 target.example",
|
||||
"999999999999 1 80 target.example", "0 1 80 invalid..example"})
|
||||
void privateSrvRefusesMalformedValuesWithoutReturningPartialAnswers(String value) {
|
||||
String zone = uniqueZone();
|
||||
String id = createPrivateZone(zone);
|
||||
String name = "_api._tcp." + zone;
|
||||
List<String> values = new ArrayList<>();
|
||||
values.add("0 100 8080 valid." + zone);
|
||||
values.add(value);
|
||||
addRecords(id, name, "SRV", values);
|
||||
DnsAnswer answer = dnsRecordSource.resolve(name, 33).orElseThrow();
|
||||
assertEquals(5, answer.responseCode());
|
||||
assertTrue(answer.isEmpty());
|
||||
Mockito.verifyNoInteractions(dnsLookupHelper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateSrvPreservesOwnershipAndPublicFallthrough() {
|
||||
String zone = uniqueZone();
|
||||
String id = createPrivateZone(zone);
|
||||
addRecord(id, "address." + zone, "A", "192.0.2.1");
|
||||
assertEquals(DnsAnswer.noData(), dnsRecordSource.resolve("address." + zone, 33).orElseThrow());
|
||||
assertEquals(DnsAnswer.noData(), dnsRecordSource.resolve(zone, 33).orElseThrow());
|
||||
assertEquals(DnsAnswer.nxDomain(), dnsRecordSource.resolve("absent." + zone, 33).orElseThrow());
|
||||
assertEquals(List.of("192.0.2.1"), dnsRecordSource.resolve("address." + zone, 1).orElseThrow().addresses());
|
||||
|
||||
String publicZone = uniqueZone();
|
||||
String publicId = route53Service.createHostedZone(publicZone, UUID.randomUUID().toString(),
|
||||
null, null).zone().getId();
|
||||
createdZoneIds.add(publicId);
|
||||
String publicName = "_api._tcp." + publicZone;
|
||||
addRecord(publicId, publicName, "SRV", "0 100 8080 target." + publicZone);
|
||||
assertTrue(dnsRecordSource.resolve(publicName, 33).isEmpty());
|
||||
assertTrue(dnsRecordSource.resolveAuthoritative(publicName, 33).isEmpty());
|
||||
assertTrue(dnsRecordSource.resolve(null, 33).isEmpty());
|
||||
assertTrue(dnsRecordSource.resolve(" ", 33).isEmpty());
|
||||
Mockito.verifyNoInteractions(dnsLookupHelper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateSrvRefusesUnsupportedRoutingPolicies() {
|
||||
String zone = uniqueZone();
|
||||
String id = createPrivateZone(zone);
|
||||
ResourceRecordSet set = new ResourceRecordSet();
|
||||
set.setName("_api._tcp." + zone);
|
||||
set.setType("SRV");
|
||||
set.setTtl(60L);
|
||||
set.setSetIdentifier("weighted");
|
||||
set.setWeight(100L);
|
||||
set.setRecords(List.of(new ResourceRecord("0 100 8080 target." + zone)));
|
||||
route53Service.changeResourceRecordSets(id, List.of(Map.of("action", "CREATE", "rrs", set)), null);
|
||||
assertEquals(5, dnsRecordSource.resolve(set.getName(), 33).orElseThrow().responseCode());
|
||||
}
|
||||
|
||||
private String createPrivateZone(String name) {
|
||||
String zoneName = name.endsWith(".") ? name : name + ".";
|
||||
String id = route53Service.createHostedZone(
|
||||
|
||||
Reference in new issue
Block a user