#!/usr/bin/bash # # drift-check.sh — compare live netinfra DNS/DHCP config against git [#420][#469] # # Verifies that the running configuration on netinfra-01/02 matches the # files tracked in this repo. Founded after the 2026-09-01 DNS incident: # the live systems are production; git is the source of truth; drift is # a defect. # # Checks per node: # - /etc/dhcp/dhcpd.conf vs netinfra/dhcp/dhcpd-{primary,secondary}.conf # - /etc/pihole/pihole.toml vs netinfra/dns/pihole/netinfra-0{1,2}.pihole.toml # (secrets redacted on both sides before compare; "Last updated" line ignored) # # Usage: # drift-check.sh [--node 01|02|all] (default: all) # Exit: 0 = in sync, 1 = drift detected, 2 = fetch failure # set -uo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" DNS_SETUP="$HERE/dns-cluster-setup" DHCP_DIR="$HERE/dhcp" PIHOLE_DIR="$HERE/dns/pihole" REDACT='s/^( *pwhash *=).*/\1 "REDACTED"/; s/^( *totp_secret *=).*/\1 "REDACTED"/; s/^( *password *=).*/\1 "REDACTED"/' # redact_config — strip secrets from pihole.toml content redact_config() { sed -E "$REDACT"; } # normalize_toml — redact + drop churn lines (timestamps) normalize_toml() { redact_config | grep -v "Last updated on"; } # fetch — run via the remote-dns.sh chokepoint (env IPs honored) fetch() { local node="$1" cmd="$2" bash "$DNS_SETUP/remote-dns.sh" "netinfra${node}-root" "$cmd" 2>/dev/null } # check_file