Files
automations/deployments/knot-dns/knotdns-aliases.sh
T
57_WolveandClaude Opus 5 54a5c0931a feat(knot-dns): authoritative Knot DNS node deployment
Native Alpine deployment for the anycast DNS estate -- no Docker, no Caddy,
alongside squid and openbao as an exception to the repo norm. Knot binds :53
directly, needs real client addresses for RRL and DNS cookies, and its DNSSEC
key store must live on the host filesystem.

Deploys a NODE. Zone data lives in the separate dns repo and arrives from its
pipeline. The split is /etc/knot/knot.conf: written here once as a skeleton of
include: lines covering only what belongs to a box (identity, NSID, storage
paths, listen, logging, control socket); everything that is DNS policy --
templates, dnssec policy, remotes/ACLs, modules, the domain inventory and the
zone files -- is delivered by the dns repo.

knsctl replaces adddns.pl and adddnssec.pl, fixing four defects:
- the duplicate check searched for the domain in BIND named.conf double-quote
  syntax (/"$domain"/) against unquoted YAML, so it could never match; only
  the -f zone-file test ever caught anything
- neither script consulted the other class's manifest, so a domain already in
  public.conf could be appended to dnssec.conf and fail the reload AFTER both
  files had been written
- nothing validated before reloading
- the reload was non-blocking, so a rejected config reported success

Its manifest matching is anchored on the YAML key and escapes the dot, so
barsrvno.de and srvnoXde no longer false-positive against srvno.de.

Aliases preserve the existing muscle memory with three corrections: -b on
every triggering knotc command (without it knotc returns OK when the command
was SENT, not when it succeeded); knzr (zone-reload) added alongside knrl
(reload), since reloading one zone's data is the right verb for a record
change and a full reload is only needed when a zone is added or removed; and
serial/NSID helpers that query unicast addresses, because asking the anycast
service address reaches whichever node is nearest and says nothing about
which node is stale.

Break-glass writes (add/remove/edit) warn and audit-log: they are overwritten
by the next pipeline deploy unless the change also lands in git. Removal
refuses to purge DNSSEC keys -- zone-purge +keys is irreversible on Knot
3.5.x, the key trash bin having arrived in 3.6.0 -- and prints the ordering
requirement, since removing a signed zone before the parent DS is withdrawn
is an outage for validating resolvers rather than a graceful shutdown.

deploy.sh, build.sh and cloud-init.yml are deliberately not included yet;
they are blocked on the Knot version decision, which sets the apk pin and
feature availability. See the Status section in the README.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 00:36:38 -05:00

63 lines
3.1 KiB
Bash

# knotdns-aliases.sh -> /etc/profile.d/knotdns-aliases.sh
#
# The operator's existing muscle memory, preserved verbatim where it was
# already right and corrected only where it was silently wrong. Sourced by
# login shells on every Knot node.
# -----------------------------------------------------------------------------
# Reload / check
# -----------------------------------------------------------------------------
# -b is NOT cosmetic. Without it knotc returns OK as soon as the command has
# been *sent* to the server, not when it succeeded -- so a zone file the server
# rejected reports success. Every triggering command here blocks.
alias knrl='knotc -b reload' # config reload: picks up new/removed zones
alias knsc='knotc -b conf-check' # validate configuration
alias knst='knotc zone-status'
# Reload ONE zone's data. Prefer this over knrl for record changes: smaller
# blast radius, and a parse failure in one zone cannot disturb the others.
# knrl (full reload) is only needed when a zone was ADDED or REMOVED.
knzr() { knotc -b zone-reload "$1"; }
# Check a zone using the server's own load path with that zone's configured
# semantic-checks applied. knotc(8) marks zone-check "(*)" -- a LOCAL operation
# requiring only a configuration, so it works with knotd stopped, and CI can
# run it against a checked-out config without standing a server up.
# Stricter and more config-aware than standalone kzonecheck, which knows
# nothing about which template a zone uses.
knzc() { knotc -b zone-check "$1"; }
# -----------------------------------------------------------------------------
# Navigation
# -----------------------------------------------------------------------------
alias knpbz='cd /var/lib/knot/zones/public'
alias knsec='cd /var/lib/knot/zones/dnssec'
alias knarpa='cd /var/lib/knot/zones/arpa'
# Open a zone file in the editor, relative to the current directory -- composes
# with the cd aliases above (knsec; ozf srvno.de).
ozf() { "${EDITOR:-vi}" "$1".zone; }
# Same, but finds the file wherever it lives, and warns that a hand edit is a
# break-glass action that the next deploy will overwrite.
alias ozfa='knsctl edit'
# -----------------------------------------------------------------------------
# Inspection
# -----------------------------------------------------------------------------
# Serial for one zone from this node specifically. Always query the UNICAST
# address: asking the anycast service address reaches whichever node is
# nearest, which tells you nothing about which node is stale.
knser() { kdig +short @127.0.0.1 SOA "$1" | awk '{print $3}'; }
# Which node actually answered? NSID is set per node in knot.conf.
knsid() { kdig +nsid "@${2:-127.0.0.1}" SOA "$1" | grep -i nsid; }
# Serial comparison across the estate. Set PEERS in /etc/profile.d or the env.
alias knsers='knsctl serials'
# Catch a silently-ignored zone file: on a cold start Knot can log this and
# serve the journal copy instead, leaving git and the served zone diverged with
# a clean exit code everywhere.
alias knstale='logread 2>/dev/null | grep -i "ignoring zone file" || dmesg | grep -i "ignoring zone file"'