authoritative_dns: configure primary/secondary zone replication #890

Merged
JakeHillion merged 1 commits from jj/nxyzposzrolo into main 2026-02-08 21:13:02 +00:00
5 changed files with 120 additions and 14 deletions

No files matched your search

@@ -69,6 +69,11 @@
# Disable systemd-timesyncd since we're using chrony
services.timesyncd.enable = false;
## Knot DNS - public listen address
services.knot.settings.server.listen = [
"185.240.111.53@53"
];
## Web services and KVM reverse proxies
services.caddy = {
enable = true;
@@ -25,6 +25,11 @@
];
};
# Knot DNS - public listen address
services.knot.settings.server.listen = [
"10.0.0.24@53"
];
# Networking
networking = {
interfaces.eth0 = {
@@ -38,8 +43,11 @@
firewall = {
allowedTCPPorts = lib.mkForce [
22 # SSH
53 # DNS
];
allowedUDPPorts = lib.mkForce [
53 # DNS
];
allowedUDPPorts = lib.mkForce [ ];
};
};
};
+2
View File
@@ -22,6 +22,8 @@ in
acme_dns_api = "boron.cx.${config.ogygia.domain}";
authoritative_dns = [
"boron.cx.${config.ogygia.domain}"
"cyclone.gw.${config.ogygia.domain}"
"slider.pop.${config.ogygia.domain}"
];
blackmagic-cam-importer = "phoenix.st.${config.ogygia.domain}";
downloads = "phoenix.st.${config.ogygia.domain}";
+90 -13
View File
@@ -7,6 +7,32 @@ let
locations = config.custom.locations.locations;
makeRecords = type: s: (lib.concatStringsSep "\n" (lib.collect builtins.isString (lib.mapAttrsRecursive (path: value: "${lib.concatStringsSep "." (lib.reverseList path)} 86400 ${type} ${value}") s)));
# Role derivation from locations
allHosts = locations.services.authoritative_dns;
primaryHost = builtins.head allHosts;
secondaryHosts = builtins.tail allHosts;
isPrimary = config.networking.fqdn == primaryHost;
isSecondary = builtins.elem config.networking.fqdn secondaryHosts;
# Nebula IP lookup (same pattern as zookeeper.nix)
lookupFqdn = fqdn:
lib.attrsets.attrByPath
(lib.reverseList (lib.splitString "." fqdn))
null
config.custom.dns.authoritative.ipv4;
primaryNebulaIp = lookupFqdn primaryHost;
secondaryNebulaIps = map lookupFqdn secondaryHosts;
# Generate remote definitions for secondaries (used on primary)
secondaryRemotes = lib.imap0
(i: ip: {
id = "secondary${toString i}";
address = "${ip}@53";
})
secondaryNebulaIps;
secondaryRemoteIds = map (r: r.id) secondaryRemotes;
zoneContent = ''
$ORIGIN ${domain}.
$TTL 86400
@@ -20,6 +46,8 @@ let
)
@ 86400 NS ns1.jakehillion.me.
@ 86400 NS ns2.jakehillion.me.
@ 86400 NS ns3.jakehillion.me.
ca 21600 CNAME warlock.cx.${domain}.
frigate 21600 CNAME ${locations.services.frigate}.
@@ -64,18 +92,42 @@ in
};
};
config = lib.mkIf cfg.enable {
custom.impermanence.extraDirs = lib.mkIf config.custom.impermanence.enable [ "/var/lib/knot" ];
config = lib.mkIf cfg.enable (lib.mkMerge [
# Common config (both primary and secondary)
{
custom.impermanence.extraDirs = lib.mkIf config.custom.impermanence.enable [ "/var/lib/knot" ];
services.knot = {
enable = true;
services.knot = {
enable = true;
settings = {
acl = [{
id = "localhost";
address = [ "127.0.0.1" "::1" ];
action = [ "update" ];
}];
settings = {
server.listen = [ "${config.custom.dns.nebula.ipv4}@53" ];
};
};
systemd.services.knot = {
after = [ "nebula@jakehillion.service" ];
requires = [ "nebula@jakehillion.service" ];
};
}
# Primary config
(lib.mkIf isPrimary {
services.knot.settings = {
remote = secondaryRemotes;
acl = [
{
id = "localhost";
address = [ "127.0.0.1" "::1" ];
action = [ "update" ];
}
{
id = "transfer_secondaries";
address = secondaryNebulaIps;
action = [ "transfer" ];
}
];
policy = [{
id = "default";
@@ -87,7 +139,8 @@ in
zone = [{
domain = domain;
file = zoneFile;
acl = [ "localhost" ];
acl = [ "localhost" "transfer_secondaries" ];
notify = secondaryRemoteIds;
# Don't sync changes back to the zone file (it's in the read-only Nix store)
# Dynamic updates are kept in journal only
zonefile-sync = -1;
@@ -97,6 +150,30 @@ in
dnssec-policy = "default";
}];
};
};
};
})
# Secondary config
(lib.mkIf isSecondary {
services.knot.settings = {
remote = [{
id = "primary";
address = "${primaryNebulaIp}@53";
}];
acl = [{
id = "notify_primary";
address = [ primaryNebulaIp ];
action = [ "notify" ];
}];
zone = [{
domain = domain;
master = [ "primary" ];
acl = [ "notify_primary" ];
zonefile-sync = -1;
journal-content = "all";
}];
};
})
]);
}
+14
View File
@@ -310,6 +310,20 @@
internalIP = "10.64.50.1";
protocol = "tcp";
}
{
description = "DNS (TCP)";
externalPort = 53;
internalIP = "10.64.50.1";
protocol = "tcp";
loopbackEnabled = false;
}
{
description = "DNS (UDP)";
externalPort = 53;
internalIP = "10.64.50.1";
protocol = "udp";
loopbackEnabled = false;
}
{
description = "Nebula Lighthouse";
externalPort = 4242;