diff options
| author | tv <tv@krebsco.de> | 2026-12-03 17:03:11 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-03 22:07:23 +0000 |
| commit | 0a6cd0eb5379e985edd825f02b0f7bc4cff710a1 (patch) | |
| tree | 4820644d9fdd4cc71dcd31f871958001faf7a6d4 | |
| parent | 793bac5bebc98209e7a6574ebb78183e32a9479a (diff) | |
ne: knot, authoritative for viljetic.de
The zones come from hrm.dns.zones, a new module that writes zone files
from records by owner name, checked by kzonecheck.
| -rw-r--r-- | configs/knot/default.nix | 52 | ||||
| -rw-r--r-- | configs/knot/viljetic.de.nix | 111 | ||||
| -rw-r--r-- | modules/dns.nix | 77 | ||||
| -rw-r--r-- | systems/ne/acme.nix | 2 | ||||
| -rw-r--r-- | systems/ne/config.nix | 1 |
5 files changed, 242 insertions, 1 deletions
diff --git a/configs/knot/default.nix b/configs/knot/default.nix new file mode 100644 index 00000000..39e1025b --- /dev/null +++ b/configs/knot/default.nix @@ -0,0 +1,52 @@ +{ config, ... }: { + imports = [ + ./viljetic.de.nix + ]; + + hrm.nftables.input.internet.udp = [ "domain" ]; + hrm.nftables.input.internet.tcp = [ "domain" ]; # AXFR + + systemd.services.knot.restartIfCredentialsChange = true; + systemd.services.knot.serviceConfig.LoadCredential = [ + "acme.key.conf:${config.krebs.secret.directory}/knot/acme.key.conf" + ]; + + services.knot = { + enable = true; + keyFiles = [ + "/run/credentials/knot.service/acme.key.conf" + ]; + settings = { + server = { + udp-max-payload = 4096; + listen = + [ "127.0.0.53@2" ] ++ + map (addr: "${addr}@53") config.krebs.build.host.nets.internet.addrs; + }; + log = { + syslog = { + any = "info"; + }; + }; + mod-rrl = { + default = { + rate-limit = "200"; # Allow 200 resp/s for each flow + slip = "2"; # Every other response slips + }; + }; + policy = { + rsa2k = { + algorithm = "rsasha256"; + ksk-size = "4096"; + zsk-size = "2048"; + }; + }; + template = { + default = { + semantic-checks = "true"; + global-module = "mod-rrl/default"; + }; + }; + }; + }; +} diff --git a/configs/knot/viljetic.de.nix b/configs/knot/viljetic.de.nix new file mode 100644 index 00000000..34f2849f --- /dev/null +++ b/configs/knot/viljetic.de.nix @@ -0,0 +1,111 @@ +{ config, lib, ... }: +let + ne = config.krebs.hosts.ne.nets.internet; + addresses = net: [ "A ${net.ip4.addr}" "AAAA ${net.ip6.addr}" ]; +in +{ + hrm.dns.zones."viljetic.de" = { + soa = { + nameserver = "ns2"; + email = "dns-admin@viljetic.de"; + serial = 1681911034; + }; + records = { + "@" = [ + "3600 NS ns2" + "3600 NS ns2.he.net." + "3600 NS ns3.he.net." + "3600 NS ns4.he.net." + "MX 10 ne" + ''TXT "v=spf1 ip4:159.195.31.38 ip6:2a0a:4cc0:c1:5eb0::/64 -all"'' + ''CAA 0 issue "letsencrypt.org"'' + ''CAA 0 iodef "mailto:security@viljetic.de"'' + ] ++ addresses ne; + ns2 = addresses ne; + www = addresses ne; + ne = addresses ne; + cgit = addresses ne; + matrix = addresses ne; + _dmarc = [ + ''TXT "v=DMARC1; p=quarantine; sp=quarantine; rua=mailto:dmarc-reports@viljetic.de; ruf=mailto:dmarc-reports@viljetic.de"'' + ]; + _domainkey = [ ''TXT "o=-; r=postmaster@viljetic.de"'' ]; + "default._domainkey" = [ + ''TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIDxqrdnYOzOyf9b+o9ps2SA1lvBTWnclqWFsFbD5iKomyC4hJ/2qDP8PQdtKH4YfvPw4QyzaRJTsqkr69i3VO26ZrYhmMXckWuFbrhcH1x64Zk/983bOlBthb651XRQlm5PvmlJSuRD8ECA3JOwrY4OPmbY7uYN0sT57LGOTKOwIDAQAB"'' + ]; + _acme-challenge = [ "NS ns2" ]; + }; + }; + + hrm.dns.zones."_acme-challenge.viljetic.de" = { + soa = { + nameserver = "ns2.viljetic.de."; + email = "dns-admin@viljetic.de"; + serial = 1660990874; + }; + records."@" = [ "NS ns2.viljetic.de." ]; + }; + + services.knot.settings = { + remote = { + he_ip4 = { + address = "216.218.130.2"; + }; + hostingde_ip4 = { + address = + # https://www.hosting.de/helpdesk/produkte/dns/dns-master-ips/ + "134.0.30.178"; + }; + }; + # To generate a TSIG key: keymgr -t NAME + acl = { + acme_acl = { + key = "acme"; + action = "update"; + }; + he_acl = { + # The key he.net's secondaries use, set in https://dns.he.net/. + key = "b727c275-0552-413e-81d0-4f9858b6133c"; + action = "transfer"; + }; + hostingde_acl = { + # https://www.hosting.de/helpdesk/produkte/dns/dns-master-ips/ + address = [ "134.0.30.178" "194.126.196.2" "2a03:2900:3:1::2" "2a03:2902:3:1::2" ]; + action = "transfer"; + }; + }; + template = { + internet-notify-he = { + semantic-checks = "on"; + dnssec-signing = "on"; + dnssec-policy = "rsa2k"; + notify = [ "hostingde_ip4" "he_ip4" ]; + acl = [ "hostingde_acl" "he_acl" ]; + zonefile-sync = "-1"; + zonefile-load = "difference-no-serial"; + journal-content = "all"; + }; + acme = { + semantic-checks = "on"; + dnssec-signing = "on"; + dnssec-policy = "rsa2k"; + acl = [ "acme_acl" ]; + zonefile-sync = "-1"; + zonefile-load = "difference-no-serial"; + journal-content = "all"; + }; + }; + zone = { + "viljetic.de" = { + file = config.hrm.dns.zones."viljetic.de".file; + template = lib.getAttr config.krebs.build.host.name { + ne = "internet-notify-he"; + }; + }; + "_acme-challenge.viljetic.de" = { + file = config.hrm.dns.zones."_acme-challenge.viljetic.de".file; + template = "acme"; + }; + }; + }; +} diff --git a/modules/dns.nix b/modules/dns.nix new file mode 100644 index 00000000..276e9f81 --- /dev/null +++ b/modules/dns.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: { + options.hrm.dns.zones = lib.mkOption { + default = {}; + description = '' + DNS zones, written as zone files for an authoritative server. + ''; + type = lib.types.attrsOf (lib.types.submodule ({ config, name, ... }: { + options = { + ttl = lib.mkOption { + type = lib.types.ints.unsigned; + default = 60; + }; + soa = { + nameserver = lib.mkOption { + type = lib.types.str; + }; + email = lib.mkOption { + type = lib.types.str; + }; + serial = lib.mkOption { + type = lib.types.ints.unsigned; + }; + refresh = lib.mkOption { + type = lib.types.ints.between 3600 86400; + default = 3600; + }; + retry = lib.mkOption { + type = lib.types.ints.unsigned; + default = 900; + }; + expire = lib.mkOption { + type = lib.types.ints.between 604800 3600000; + default = 604800; + }; + minimum = lib.mkOption { + type = lib.types.ints.between 180 86400; + default = 180; + }; + }; + records = lib.mkOption { + type = lib.types.attrsOf (lib.types.listOf lib.types.str); + default = {}; + description = '' + Records by owner name, each written after its name in the zone + file, e.g. "MX 10 ne" or "3600 NS ns2". + ''; + }; + file = lib.mkOption { + type = lib.types.package; + readOnly = true; + }; + }; + config.file = pkgs.runCommand "${name}.zone" { + nativeBuildInputs = [ pkgs.knot-dns ]; + preferLocalBuild = true; + passAsFile = [ "text" ]; + text = lib.concatLines ([ + "$TTL ${toString config.ttl}" + "@ SOA ${lib.concatStringsSep " " [ + config.soa.nameserver + (lib.replaceStrings [ "@" ] [ "." ] config.soa.email + ".") + (toString config.soa.serial) + (toString config.soa.refresh) + (toString config.soa.retry) + (toString config.soa.expire) + (toString config.soa.minimum) + ]}" + ] ++ lib.concatLists (lib.mapAttrsToList + (owner: map (record: "${owner} ${record}")) + config.records)); + } '' + kzonecheck --origin ${lib.escapeShellArg name} "$textPath" + cp "$textPath" "$out" + ''; + })); + }; +} diff --git a/systems/ne/acme.nix b/systems/ne/acme.nix index c54d487d..fba183cf 100644 --- a/systems/ne/acme.nix +++ b/systems/ne/acme.nix @@ -15,7 +15,7 @@ dnsProvider = "rfc2136"; environmentFile = # format: - # RFC2136_NAMESERVER=ns1.viljetic.de + # RFC2136_NAMESERVER=ns2.viljetic.de # RFC2136_TSIG_ALGORITHM=hmac-sha256. # RFC2136_TSIG_KEY=acme # RFC2136_TSIG_SECRET=<base64-encoded-secret> diff --git a/systems/ne/config.nix b/systems/ne/config.nix index 16d5933a..44983565 100644 --- a/systems/ne/config.nix +++ b/systems/ne/config.nix @@ -3,6 +3,7 @@ ./base.nix ./acme.nix { services.nginx.enable = true; } # acme currently uses nginx (but doesn't need it) + ../../configs/knot ../../configs/retiolum.nix ../../configs/btrfs-scrub.nix |
