mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cloudmap): create the Route 53 hosted zone behind a DNS namespace (#7042)
* fix(cloudmap): create the Route 53 hosted zone behind a DNS namespace Private and public DNS namespaces reported a random HostedZoneId that no Route 53 zone backed. They now create a real zone (private with the namespace VPC and region, or public) via Route53Service, and DeleteNamespace deletes it; a zone holding user records refuses with HostedZoneNotEmpty and the namespace is kept. A private zone now covers the namespace's names, and the Route 53 DNS source answers NXDOMAIN for names it has no record for. EmbeddedDnsServer took the first present answer across sources, so bean order could hide Cloud Map instances. An NXDOMAIN from one source no longer wins over another source's real answer. Reset: zones and namespaces live in separate stores; Route53Service.clear() only drops in-memory counters, so no Cloud Map reset hook was added. * test(cloudmap): select the user's zone now that namespaces own a real one A private DNS namespace now creates a real Route 53 hosted zone, as AWS does, so the compat projects hold two zones named floci-compat.internal: the namespace's private zone and the public aws_route53_zone. The bats lookups took the first zone by name, which picked the namespace zone whenever its id sorted first, so the record and tag assertions read the wrong zone. They now select the public zone. The CloudFormation test pinned the namespace HostedZoneId to 14 characters, the length of Cloud Map's old placeholder. The id now comes from Route 53, which, like AWS, does not use a fixed length; the test checks for a bare Z-prefixed id instead. * fix(dns): let a record source with records win over another's NODATA Two sources can own one zone (a Cloud Map namespace and its Route 53 zone). An empty NOERROR from the first consulted source was returned before the other was asked, so a TXT record in the zone hid Cloud Map's A record at the same name. Empty answers are now fallbacks, an existing name preferred over NXDOMAIN. * fix(cloudmap): log a namespace zone that was already deleted * docs(cloudmap): describe the real hosted zone in the operations table * test(dns): pin how record sources combine REFUSED and negative answers Another source's records now beat a REFUSED, and REFUSED beats NXDOMAIN in either source order; nothing pinned either, so returning REFUSED immediately went unnoticed. Also pin, as current behaviour, that a plain NODATA beats an NXDOMAIN carrying an SOA authority. The packet test now deletes the TXT records it adds to the namespace's hosted zone, so the zone is left deletable. --------- Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
1 parent
b3d9f2f576
commit
f41f794337
9 files changed
+256
-28
No files matched your search
@@ -405,11 +405,22 @@ public class EmbeddedDnsServer {
|
||||
if (recordSources == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
// Two sources can own the same zone (a Cloud Map namespace and the Route 53 zone behind it),
|
||||
// and bean order is unspecified. An empty answer (NXDOMAIN, or NODATA for a name holding only
|
||||
// other types) only speaks for that source, so it must not win over another source's records;
|
||||
// it is returned only if no source has any, an existing name preferred over NXDOMAIN.
|
||||
Optional<DnsAnswer> empty = Optional.empty();
|
||||
for (DnsRecordSource source : recordSources) {
|
||||
try {
|
||||
Optional<DnsAnswer> answer = authoritative ? source.resolveAuthoritative(name, type)
|
||||
: source.resolve(name, type);
|
||||
if (answer != null && answer.isPresent()) {
|
||||
if (answer.get().isEmpty()) {
|
||||
if (empty.isEmpty() || (!empty.get().nameExists() && answer.get().nameExists())) {
|
||||
empty = answer;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -417,7 +428,7 @@ public class EmbeddedDnsServer {
|
||||
source.getClass().getSimpleName(), name, e.getMessage());
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
return empty;
|
||||
}
|
||||
|
||||
byte[] buildEmptyResponse(byte[] query, short txId, int questionOffset, int questionEnd, int responseCode) {
|
||||
|
||||
@@ -22,6 +22,8 @@ import io.github.hectorvent.floci.services.cloudmap.model.Instance;
|
||||
import io.github.hectorvent.floci.services.cloudmap.model.Namespace;
|
||||
import io.github.hectorvent.floci.services.cloudmap.model.Operation;
|
||||
import io.github.hectorvent.floci.services.cloudmap.model.Service;
|
||||
import io.github.hectorvent.floci.services.route53.Route53Service;
|
||||
import io.github.hectorvent.floci.services.route53.model.VpcAssociation;
|
||||
import io.netty.util.NetUtil;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -69,13 +71,15 @@ public class CloudMapService {
|
||||
private final StorageBackend<String, Instance> instanceStore;
|
||||
private final StorageBackend<String, Operation> operationStore;
|
||||
private final RegionResolver regionResolver;
|
||||
private final Route53Service route53Service;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final int completionDelaySeconds;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
|
||||
@Inject
|
||||
public CloudMapService(StorageFactory storageFactory, EmulatorConfig config,
|
||||
RegionResolver regionResolver, ObjectMapper objectMapper) {
|
||||
RegionResolver regionResolver, ObjectMapper objectMapper,
|
||||
Route53Service route53Service) {
|
||||
this.namespaceStore = storageFactory.create("cloudmap", "cloudmap-namespaces.json",
|
||||
new TypeReference<Map<String, Namespace>>() {});
|
||||
this.serviceStore = storageFactory.create("cloudmap", "cloudmap-services.json",
|
||||
@@ -85,6 +89,7 @@ public class CloudMapService {
|
||||
this.operationStore = storageFactory.create("cloudmap", "cloudmap-operations.json",
|
||||
new TypeReference<Map<String, Operation>>() {});
|
||||
this.regionResolver = regionResolver;
|
||||
this.route53Service = route53Service;
|
||||
this.objectMapper = objectMapper;
|
||||
this.completionDelaySeconds = config.services().cloudmap().operationCompletionDelaySeconds();
|
||||
this.scheduler = completionDelaySeconds > 0
|
||||
@@ -115,7 +120,7 @@ public class CloudMapService {
|
||||
public Operation createPublicDnsNamespace(String name, String creatorRequestId,
|
||||
String description, Map<String, String> tags, String region) {
|
||||
Namespace ns = newNamespace(name, "DNS_PUBLIC", description, creatorRequestId, tags, region);
|
||||
ns.setHostedZoneId(generateHostedZoneId());
|
||||
ns.setHostedZoneId(createZone(ns, null));
|
||||
namespaceStore.put(ns.getId(), ns);
|
||||
return submitOperation("CREATE_NAMESPACE", "NAMESPACE", ns.getId(), region);
|
||||
}
|
||||
@@ -127,7 +132,7 @@ public class CloudMapService {
|
||||
}
|
||||
Namespace ns = newNamespace(name, "DNS_PRIVATE", description, creatorRequestId, tags, region);
|
||||
ns.setVpc(vpc);
|
||||
ns.setHostedZoneId(generateHostedZoneId());
|
||||
ns.setHostedZoneId(createZone(ns, new VpcAssociation(vpc, region)));
|
||||
namespaceStore.put(ns.getId(), ns);
|
||||
return submitOperation("CREATE_NAMESPACE", "NAMESPACE", ns.getId(), region);
|
||||
}
|
||||
@@ -192,6 +197,20 @@ public class CloudMapService {
|
||||
throw new AwsException("ResourceInUse",
|
||||
"The namespace contains existing services and cannot be deleted.", 400);
|
||||
}
|
||||
if (ns.getHostedZoneId() != null) {
|
||||
// The zone goes with the namespace. A zone holding records beyond the default NS/SOA
|
||||
// is refused (HostedZoneNotEmpty) and the namespace is kept, rather than orphaning records.
|
||||
try {
|
||||
route53Service.deleteHostedZone(ns.getHostedZoneId());
|
||||
} catch (AwsException e) {
|
||||
if (!"NoSuchHostedZone".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
// Already deleted through Route 53; nothing is orphaned, so the namespace still goes.
|
||||
LOG.debugv("Hosted zone {0} of Cloud Map namespace {1} was already deleted",
|
||||
ns.getHostedZoneId(), id);
|
||||
}
|
||||
}
|
||||
namespaceStore.delete(id);
|
||||
return submitOperation("DELETE_NAMESPACE", "NAMESPACE", id, region);
|
||||
}
|
||||
@@ -938,12 +957,9 @@ public class CloudMapService {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String generateHostedZoneId() {
|
||||
StringBuilder sb = new StringBuilder("Z");
|
||||
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
for (int i = 0; i < 13; i++) {
|
||||
sb.append(chars.charAt(random.nextInt(chars.length())));
|
||||
}
|
||||
return sb.toString();
|
||||
/** Creates the Route 53 zone behind a DNS namespace (private when a VPC association is given). */
|
||||
private String createZone(Namespace ns, VpcAssociation vpc) {
|
||||
return route53Service.createHostedZone(ns.getName(), "cloudmap-" + ns.getId(),
|
||||
"Created by Cloud Map namespace " + ns.getId(), vpc).zone().getId();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user