mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(route53): fully qualify the default SOA and NS nameservers (#6450)
This commit is contained in:
1 parent
452633fe7d
commit
fad23ae0b9
7 files changed
+92
-16
No files matched your search
@@ -205,7 +205,11 @@ public class DnsLookupHelper {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private static String normalizeTarget(String s) {
|
||||
/**
|
||||
* A DNS name without surrounding whitespace and without its final dot, keeping its case. A
|
||||
* null name reads as empty.
|
||||
*/
|
||||
public static String normalizeTarget(String s) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
+2
-8
@@ -195,10 +195,7 @@ public class Route53DnsRecordSource implements DnsRecordSource {
|
||||
}
|
||||
AliasTarget alias = rrs.getAliasTarget();
|
||||
if (alias != null && alias.getDnsName() != null && !alias.getDnsName().isBlank()) {
|
||||
String cleanAlias = alias.getDnsName().trim();
|
||||
if (cleanAlias.endsWith(".")) {
|
||||
cleanAlias = cleanAlias.substring(0, cleanAlias.length() - 1);
|
||||
}
|
||||
String cleanAlias = DnsLookupHelper.normalizeTarget(alias.getDnsName());
|
||||
// An alias record has no TTL of its own; Route 53 answers with the target's.
|
||||
if (route53Service.isCoveredByPrivateZone(cleanAlias)) {
|
||||
DnsAnswer target = resolveAddresses(cleanAlias, visited, depth + 1);
|
||||
@@ -226,10 +223,7 @@ public class Route53DnsRecordSource implements DnsRecordSource {
|
||||
if (rrs.getRecords() != null && !rrs.getRecords().isEmpty()) {
|
||||
String target = rrs.getRecords().get(0).getValue();
|
||||
if (target != null && !target.isBlank()) {
|
||||
String cleanTarget = target.trim();
|
||||
if (cleanTarget.endsWith(".")) {
|
||||
cleanTarget = cleanTarget.substring(0, cleanTarget.length() - 1);
|
||||
}
|
||||
String cleanTarget = DnsLookupHelper.normalizeTarget(target);
|
||||
// The answer is flattened to A records, so it can be cached only as long
|
||||
// as the shortest-lived record in the chain.
|
||||
int cnameTtl = ttlOf(rrs);
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.DomainNames;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.core.common.dns.DnsLookupHelper;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -83,7 +84,7 @@ public class Route53Service implements Resettable {
|
||||
r53.defaultNameserver2(),
|
||||
r53.defaultNameserver3(),
|
||||
r53.defaultNameserver4()
|
||||
);
|
||||
).stream().map(Route53Service::delegationName).toList();
|
||||
this.defaultAccountId = config.defaultAccountId();
|
||||
this.regionResolver = regionResolver;
|
||||
this.ec2Service = ec2Service;
|
||||
@@ -889,6 +890,15 @@ public class Route53Service implements Resettable {
|
||||
return name.endsWith(".") ? name : name + ".";
|
||||
}
|
||||
|
||||
/**
|
||||
* A configured nameserver as the delegation set lists it: without surrounding whitespace, which
|
||||
* the config does not trim, and without the final dot, as Route 53 lists it. {@code strip()}
|
||||
* also removes the Unicode spaces that {@code trim()} keeps.
|
||||
*/
|
||||
private static String delegationName(String configured) {
|
||||
return DnsLookupHelper.normalizeTarget(configured.strip());
|
||||
}
|
||||
|
||||
public static String normalizeRecordName(String name) {
|
||||
String normalized = normalizeName(name);
|
||||
if (normalized == null) {
|
||||
@@ -932,7 +942,7 @@ public class Route53Service implements Resettable {
|
||||
soa.setType("SOA");
|
||||
soa.setTtl(900L);
|
||||
soa.setRecords(List.of(new ResourceRecord(
|
||||
nameServers.get(0) + " awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400")));
|
||||
normalizeName(nameServers.get(0)) + " awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400")));
|
||||
records.add(soa);
|
||||
|
||||
ResourceRecordSet ns = new ResourceRecordSet();
|
||||
@@ -940,7 +950,7 @@ public class Route53Service implements Resettable {
|
||||
ns.setType("NS");
|
||||
ns.setTtl(172800L);
|
||||
ns.setRecords(nameServers.stream()
|
||||
.map(n -> new ResourceRecord(n + "."))
|
||||
.map(n -> new ResourceRecord(normalizeName(n)))
|
||||
.toList());
|
||||
records.add(ns);
|
||||
|
||||
|
||||
Reference in new issue
Block a user