2023-11-03 00:11:13 +02:00
|
|
|
{ cluster, config, depot, lib, pkgs, ... }:
|
2022-08-07 20:58:37 +03:00
|
|
|
|
|
|
|
let
|
2023-03-07 02:26:07 +02:00
|
|
|
inherit (depot.reflection) interfaces;
|
2023-08-31 01:55:45 +03:00
|
|
|
inherit (depot.lib.meta) domain;
|
2023-03-23 00:00:29 +02:00
|
|
|
inherit (config.networking) hostName;
|
2022-08-07 20:58:37 +03:00
|
|
|
|
2023-03-23 00:00:29 +02:00
|
|
|
link = cluster.config.hostLinks.${hostName}.dnsAuthoritative;
|
2022-08-07 20:58:37 +03:00
|
|
|
patroni = cluster.config.links.patroni-pg-access;
|
|
|
|
|
2023-08-31 01:55:45 +03:00
|
|
|
otherDnsServers = lib.pipe (with cluster.config.services.dns.otherNodes; (master hostName) ++ (slave hostName)) [
|
2023-03-23 00:00:29 +02:00
|
|
|
(map (node: cluster.config.hostLinks.${node}.dnsAuthoritative.tuple))
|
|
|
|
(lib.concatStringsSep " ")
|
|
|
|
];
|
|
|
|
|
2022-08-07 20:58:37 +03:00
|
|
|
translateConfig = cfg: let
|
|
|
|
configList = lib.mapAttrsToList (n: v: "${n}=${v}") cfg;
|
|
|
|
in lib.concatStringsSep "\n" configList;
|
2023-11-03 00:11:13 +02:00
|
|
|
|
2023-11-03 00:40:43 +02:00
|
|
|
rewriteRecords = lib.filterAttrs (_: record: record.rewrite.target != null) cluster.config.dns.records;
|
2023-11-03 00:11:13 +02:00
|
|
|
|
2023-11-03 00:40:43 +02:00
|
|
|
rewrites = lib.mapAttrsToList (_: record: let
|
2023-11-03 00:58:49 +02:00
|
|
|
maybeEscapeRegex = str: if record.rewrite.type == "regex" then "${lib.escapeRegex str}$" else str;
|
2023-11-03 00:40:43 +02:00
|
|
|
in "rewrite stop name ${record.rewrite.type} ${record.name}${maybeEscapeRegex ".${record.root}."} ${record.rewrite.target}. answer auto") rewriteRecords;
|
2023-11-03 00:11:13 +02:00
|
|
|
|
|
|
|
rewriteConf = pkgs.writeText "coredns-rewrites.conf" (lib.concatStringsSep "\n" rewrites);
|
2022-08-07 20:58:37 +03:00
|
|
|
in {
|
2023-03-05 23:00:18 +02:00
|
|
|
links.localAuthoritativeDNS = {};
|
|
|
|
|
2022-08-07 20:58:37 +03:00
|
|
|
age.secrets = {
|
|
|
|
pdns-db-credentials = {
|
|
|
|
file = ./pdns-db-credentials.age;
|
|
|
|
mode = "0400";
|
|
|
|
owner = "pdns";
|
|
|
|
group = "pdns";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = {
|
|
|
|
allowedTCPPorts = [ 53 ];
|
|
|
|
allowedUDPPorts = [ 53 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.powerdns = {
|
|
|
|
enable = true;
|
|
|
|
extraConfig = translateConfig {
|
|
|
|
launch = "gpgsql";
|
2023-03-05 23:00:18 +02:00
|
|
|
local-address = config.links.localAuthoritativeDNS.tuple;
|
2022-08-07 20:58:37 +03:00
|
|
|
gpgsql-host = patroni.ipv4;
|
|
|
|
gpgsql-port = patroni.portStr;
|
|
|
|
gpgsql-dbname = "powerdns";
|
|
|
|
gpgsql-user = "powerdns";
|
|
|
|
gpgsql-extra-connection-parameters = "passfile=${config.age.secrets.pdns-db-credentials.path}";
|
|
|
|
version-string = "Private Void DNS";
|
2023-03-06 19:28:55 +02:00
|
|
|
enable-lua-records = "yes";
|
2023-03-06 22:10:22 +02:00
|
|
|
expand-alias = "yes";
|
2023-03-06 22:52:17 +02:00
|
|
|
resolver = "127.0.0.1:8600";
|
2022-08-07 20:58:37 +03:00
|
|
|
};
|
|
|
|
};
|
2023-03-05 23:00:18 +02:00
|
|
|
|
|
|
|
services.coredns = {
|
|
|
|
enable = true;
|
|
|
|
config = ''
|
2023-03-23 00:00:29 +02:00
|
|
|
.:${link.portStr} {
|
2023-03-05 23:00:18 +02:00
|
|
|
bind ${interfaces.primary.addr}
|
|
|
|
chaos "Private Void DNS" info@privatevoid.net
|
|
|
|
cache {
|
|
|
|
success 4000 86400
|
|
|
|
denial 0
|
|
|
|
prefetch 3
|
|
|
|
serve_stale 86400s
|
|
|
|
}
|
2023-11-04 04:59:27 +02:00
|
|
|
trace zipkin ${cluster.config.links.tempo-zipkin-http.tuple} {
|
|
|
|
every 100
|
|
|
|
client_server
|
|
|
|
}
|
2023-03-05 23:16:06 +02:00
|
|
|
forward service.eu-central.sd-magic.${domain} 127.0.0.1:8600
|
2023-03-06 01:49:44 +02:00
|
|
|
forward addr.eu-central.sd-magic.${domain} 127.0.0.1:8600
|
2023-11-03 00:11:13 +02:00
|
|
|
import ${rewriteConf}
|
2023-03-23 00:00:29 +02:00
|
|
|
forward . ${config.links.localAuthoritativeDNS.tuple} ${otherDnsServers} {
|
|
|
|
policy sequential
|
|
|
|
}
|
2023-03-05 23:00:18 +02:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.coredns = {
|
|
|
|
after = [ "pdns.service" ];
|
|
|
|
};
|
2023-03-06 00:50:50 +02:00
|
|
|
|
|
|
|
consul.services.pdns = {
|
|
|
|
mode = "external";
|
2023-03-06 17:42:14 +02:00
|
|
|
definition = {
|
2023-03-06 00:50:50 +02:00
|
|
|
name = "authoritative-dns-backend";
|
|
|
|
address = config.links.localAuthoritativeDNS.ipv4;
|
|
|
|
port = config.links.localAuthoritativeDNS.port;
|
|
|
|
checks = lib.singleton {
|
|
|
|
interval = "60s";
|
|
|
|
tcp = config.links.localAuthoritativeDNS.tuple;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-08-07 20:58:37 +03:00
|
|
|
}
|