single file for dns
This commit is contained in:
1 parent
309b61b985
commit
09e2e03423
33 files changed
+319
-574
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# modules/openwrt/
|
||||
|
||||
Config generator + deploy tooling for the homelab's **OpenWrt** router. This is *not* a NixOS
|
||||
Config generator + deploy tooling for the homelab's **OpenWrt** router. This is _not_ a NixOS
|
||||
module — it's a Nix function that builds a Rust generator and wraps it in an
|
||||
`openwrt-deploy` shell script. OpenWrt is managed out-of-band (the router isn't a NixOS host),
|
||||
so this provides a declarative, reviewable way to push `dnsmasq.conf` and `/etc/ethers`.
|
||||
@@ -24,12 +24,12 @@ exported env vars before inlining each file's content via `builtins.readFile`.
|
||||
## How it works
|
||||
|
||||
1. The router config lives as an **agenix secret** (e.g. `secrets/glmain.json.age`).
|
||||
1b. Before generating, the decrypted JSON's `generalMappings` are **merged** (via `jq`) with
|
||||
`$NIX_DNS_RECORDS` — the DNS records declared across all hosts through `skyg.dns`
|
||||
(see `modules/nixos/common/dns-records/`) and aggregated by `modules/dns-aggregate.nix`
|
||||
1b. Before generating, the decrypted JSON's `generalMappings` are **merged** (via `jq`) with
|
||||
`$NIX_DNS_RECORDS` — the router DNS records rendered from the global
|
||||
`skyg.internalNetworkingMap` (see `modules/main.nix`) by `modules/internal-networking.nix`
|
||||
into `packages.<sys>.skyg-dns-records`. The secret stays the source of truth for
|
||||
devices/MACs; **Nix owns service names**, so a container's DNS name lives next to the
|
||||
host config that owns its IP. Inspect the aggregate with `nix eval .#dnsRecords --json`.
|
||||
devices/MACs; **Nix owns service names**. Inspect the records with
|
||||
`nix eval .#dnsRecords --json`.
|
||||
2. `openwrt-deploy` reads the decrypted JSON from stdin, runs `openwrt-gen dnsmasq`,
|
||||
`openwrt-gen ethers`, and `openwrt-gen firewall` to render the three target files.
|
||||
3. It SSHes to the router, shows a **colorized unified diff** against the current files
|
||||
@@ -61,12 +61,12 @@ is passed as a command-line argument (default `glmain`).
|
||||
```bash
|
||||
skyg openwrt --dry-run
|
||||
# → .tmp/openwrt-glmain/dnsmasq.conf
|
||||
# → .tmp/openwrt-glmain/dns-records.json # the Nix-declared skyg.dns fragment merged in
|
||||
# → .tmp/openwrt-glmain/dns-records.json # the Nix-rendered internalNetworkingMap fragment merged in
|
||||
# → .tmp/openwrt-glmain/ethers
|
||||
# → .tmp/openwrt-glmain/firewall.batch # the exact `uci -m import firewall` input
|
||||
```
|
||||
|
||||
Use this to inspect what a deploy *would* do (especially the firewall rules) before running
|
||||
Use this to inspect what a deploy _would_ do (especially the firewall rules) before running
|
||||
the real `skyg openwrt`.
|
||||
|
||||
`router.ip` / `router.user` are taken from the `config` passed into `default.nix`.
|
||||
|
||||
@@ -17,9 +17,8 @@ in
|
||||
config:
|
||||
|
||||
let
|
||||
# Nix-generated DNS records (skyg.dns, aggregated across all hosts). Merged
|
||||
# into the decrypted secret's generalMappings by the scripts below, so
|
||||
# service names stay declarative next to the host config that owns the IP.
|
||||
# Nix-rendered DNS records from the global skyg.internalNetworkingMap. Merged
|
||||
# into the decrypted secret's generalMappings by the scripts below.
|
||||
# Empty fragment when the caller doesn't supply one.
|
||||
dnsRecords =
|
||||
if config ? dnsRecords && config.dnsRecords != null
|
||||
|
||||
@@ -36,10 +36,10 @@ openwrt-gen firewall < config.json # prints UCI firewall rules (uci batch form
|
||||
`wildcard` defaults to `true` (omitted in existing secrets) and renders
|
||||
`address=/domain/ip` + `address=/.domain/ip`, matching every subdomain too.
|
||||
Set `false` for a plain `host-record=domain,ip` (A record + reverse PTR) —
|
||||
this is what Nix-declared `skyg.dns` records use by default.
|
||||
this is what the Nix-rendered `skyg.internalNetworkingMap` records use.
|
||||
At deploy time this list is the **union** of the secret's entries and the
|
||||
records aggregated from every host's `skyg.dns` (see
|
||||
`modules/nixos/common/dns-records/`), merged by `jq` in `openwrt-deploy.sh`.
|
||||
records rendered from `skyg.internalNetworkingMap` (see
|
||||
`modules/internal-networking.nix`), merged by `jq` in `openwrt-deploy.sh`.
|
||||
- `networks`: `{ <network>: [ { mac, name, id?, domains?, justMac?, internetOnly? } ] }` —
|
||||
per-network hosts. A device with `internetOnly: true` is restricted to internet-only
|
||||
access (matched by MAC), on any network.
|
||||
@@ -56,7 +56,7 @@ LAN (`10.0.0.0/16` IPv4, `fd59:de0a:bff5::/48` IPv6). Two sources of restriction
|
||||
- **IPv4** — one rule per network matching the whole subnet (catches every device on it).
|
||||
- **IPv6** — one rule per known device MAC. All subnets share a single ULA /64
|
||||
(`fd59:de0a:bff5::/48`, see `network::ULA_PREFIX`), so subnets are not distinguishable
|
||||
in IPv6 and blocking is done per known device. An *unknown* IPv6-only device on those
|
||||
in IPv6 and blocking is done per known device. An _unknown_ IPv6-only device on those
|
||||
subnets is **not** blocked (inherent to the flat-L2 topology).
|
||||
|
||||
**Device-level** — for any device with `internetOnly: true` (on any network):
|
||||
|
||||
@@ -12,14 +12,14 @@ set -euo pipefail
|
||||
|
||||
SERVER="$ROUTER_USER@$ROUTER"
|
||||
|
||||
# Merge the Nix-declared DNS records (skyg.dns, aggregated across all hosts)
|
||||
# into the secret's generalMappings. The secret stays the source of truth for
|
||||
# Merge the Nix-rendered DNS records (skyg.internalNetworkingMap) into the
|
||||
# secret's generalMappings. The secret stays the source of truth for
|
||||
# devices/MACs; Nix owns service names.
|
||||
CONFIG=$(cat | jq --slurpfile nix "$NIX_DNS_RECORDS" \
|
||||
'.generalMappings = ((.generalMappings // []) + $nix[0].generalMappings)')
|
||||
|
||||
NIX_COUNT=$(jq '.generalMappings | length' "$NIX_DNS_RECORDS")
|
||||
echo "Merged $NIX_COUNT Nix-declared DNS mapping(s) from skyg.dns."
|
||||
echo "Merged $NIX_COUNT Nix-declared DNS mapping(s) from skyg.internalNetworkingMap."
|
||||
|
||||
DNSMASQ=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen dnsmasq)
|
||||
ETHERS=$(echo "$CONFIG" | "$GENERATOR"/bin/openwrt-gen ethers)
|
||||
|
||||
@@ -11,7 +11,7 @@ if [ $# -ge 1 ]; then ROUTER="$1"; else ROUTER=glmain; fi
|
||||
OUTDIR=".tmp/openwrt-$ROUTER"
|
||||
mkdir -p "$OUTDIR"
|
||||
|
||||
# Same merge as the real deploy: secret config + Nix-declared skyg.dns records.
|
||||
# Same merge as the real deploy: secret config + Nix-rendered skyg.internalNetworkingMap records.
|
||||
CONFIG=$(cat | jq --slurpfile nix "$NIX_DNS_RECORDS" \
|
||||
'.generalMappings = ((.generalMappings // []) + $nix[0].generalMappings)')
|
||||
|
||||
@@ -25,4 +25,4 @@ echo "Dry-run configs written to $OUTDIR (no router changes made):"
|
||||
echo " $OUTDIR/dnsmasq.conf"
|
||||
echo " $OUTDIR/ethers"
|
||||
echo " $OUTDIR/firewall.batch"
|
||||
echo " $OUTDIR/dns-records.json # Nix-declared skyg.dns records merged in"
|
||||
echo " $OUTDIR/dns-records.json # Nix-rendered skyg.internalNetworkingMap records merged in"
|
||||
Reference in new issue
Block a user