# Ianitor beside Caddy on two low-risk hosts ROADMAP §1.12 and §6 Phase 3: Ianitor runs beside Caddy on two low-risk hosts before any cut-over. This is **prepared, not applied**: Mark runs every command below himself. ## What was found in Configuration_Server (read-only, 2026-11-07) - `hyperv-infra/` is the active flake (`nixosConfigurations.hyperv-vm`, the staging mirror on 192.168.100.166), pinned to production's nixpkgs (24.11, rev 50ab793). Production (.217) is a classic-channels install whose real config is not in the repository; `nixos-live/` is a snapshot. - Caddy is the only listener on 80/443 and the only service beyond loopback (decision D-21a); every backend binds 127.0.0.1. Secrets come from sops-nix (`/run/secrets/...`). - Authelia is not in the repository: production runs it, configured outside Configuration_Server (Mark, 2026-11-08). Ianitor keeps forward-auth; the admin UI's host must sit behind it, and control refuses a ui-proof header rule on any other host. The two trial hosts use no sign-in (their applications have none today). - The module turns on `security.polkit` (control may start and stop exactly `ianitor-edge` and `caddy-fallback`). The server had no other use for polkit, so that service is new there. - Lowest-risk hosts: `flowers.stage.marek-novak.cz` (a static presentation app, nginx on 127.0.0.1:8091) and `esp32.stage.marek-novak.cz` (a static web IDE, 127.0.0.1:8093, used only by Mark). Both are on the staging mirror, "the one machine safe to break". ## The shape ```text visitor ── Caddy :443 (as today) ── unix:/run/ianitor-proxy/edge.sock ── Ianitor edge ── the app ``` - Caddy reaches edge on edge's **proxy socket** (`services.ianitor.edge.proxySocket`, phase 4): `/run/ianitor-proxy/edge.sock`, mode 0660, in a setgid directory of the group `ianitor-proxy`, whose only members are edge, the Caddy fallback and Caddy (`proxySocket.users = [ "caddy" ]`). Edge serves the HTTPS hosts there in plain HTTP (Caddy terminated TLS) and **believes the X-Forwarded-For Caddy sends**, so the visit log and the share-link throttle see the visitor. No other local user can connect, so none can claim an address; no loopback TCP port is involved, and `trustedProxies` stays off. The Caddy fallback listens on the same socket (compile option `proxy_socket`, a third Caddy server with `trusted_proxies_unix`), so an engine switch keeps the two hosts reachable through Caddy. - Edge's TCP listeners stay on **loopback only** (127.0.0.1:18080 and :18443), so D-21a holds: nothing new is reachable from the LAN. Control is on 127.0.0.1:7878 (API tokens) and on its UI socket `/run/ianitor-control/ui.sock` (the admin host, [../api.md](../api.md), "Sign-in"). - Every other host is untouched. Rollback: revert the patch and switch (below). - Until phase 4 this hop was TLS to 127.0.0.1:18443 with Domi certificates, and edge saw every visitor as 127.0.0.1. The socket replaces it; the Domi root is no longer needed by Caddy. ## The patch [configuration-server.patch](configuration-server.patch), against Configuration_Server `main` (5124e9d): adds the `ianitor` flake input, `hyperv-infra/modules/ianitor.nix`, and routes the two vhosts in `hyperv-infra/modules/caddy.nix` through Ianitor. No secret is in it. ## Commands (Mark) On the offline machine (once; see [../pki.md](../pki.md)): ```sh openssl req -x509 -new -newkey ec -pkeyopt ec_paramgen_curve:P-256 \ -keyout domi-root.key -out domi-root.crt -days 3653 \ -subj "/CN=Domi PKI Root/O=Fabrica Domi" \ -addext "basicConstraints=critical,CA:TRUE,pathlen:1" -addext "keyUsage=critical,keyCertSign,cRLSign" ``` In Configuration_Server, on a branch, per the repository's workflow: ```sh git switch -c feature/ianitor-beside-caddy git apply /path/to/Ianitor/docs/deploy/configuration-server.patch mkdir -p hyperv-infra/ianitor && cp /path/to/domi-root.crt hyperv-infra/ianitor/domi-root.crt # Two new secrets, generated and piped (never in a command line, a file in the repository or # the shell history). Needs `sops set --value-stdin`; with an older sops, use `sops edit`: cd hyperv-infra for k in share-link-key pki-password; do { printf '"'; head -c 32 /dev/urandom | base64 -w0; printf '"'; } | sops set --value-stdin secrets/secrets.yaml "[\"ianitor\"][\"$k\"]" done # Pin Ianitor to the reviewed commit (the patch carries MERGED_COMMIT as a placeholder): sed -i "s/MERGED_COMMIT//" flake.nix nix flake lock --update-input ianitor nix flake check --no-build git add -A && git commit ``` Deploy to the staging mirror (build first, as the repository's rules say): ```powershell scripts/staging/Deploy-Staging.ps1 -Mode Build scripts/staging/Deploy-Staging.ps1 -Mode Test scripts/staging/Deploy-Staging.ps1 -Mode Switch ``` On the mirror, the first intermediate and the two hosts: ```sh sudo -u ianitor-control ianitor-control token create --name mark-laptop --config /etc/ianitor/control.toml # -> save the token in Custos; then, from the laptop. The token goes into a header file that only # you can read, so it is never in a command line (ps) or the shell history: ssh -fN -L 7878:127.0.0.1:7878 mirror H=@$HOME/.ianitor-header; API=http://127.0.0.1:7878/api/v1 ( umask 077; IFS= read -rs t; printf 'Authorization: Bearer %s\n' "$t" > ~/.ianitor-header ) # paste the token curl -s -H "$H" -X POST "$API/certs/intermediate/renewal" | jq -r .csr_pem > req.csr curl -s -H "$H" "$API/pki-requests/$(curl -s -H "$H" $API/overview | jq -r .intermediate.renewal.request_id)/ext" > req.ext # offline: openssl x509 -req -in req.csr -CA domi-root.crt -CAkey domi-root.key -days 365 -sha256 -extfile req.ext -out int.crt scp int.crt mirror:/tmp/ && ssh mirror sudo -u ianitor-control ianitor-control pki install /tmp/int.crt --config /etc/ianitor/control.toml for h in flowers esp32; do curl -s -H "$H" -H 'Content-Type: application/json' -X POST "$API/hosts" \ -d "$(jq -c --arg h "$h.stage.marek-novak.cz" '.[] | select(.hostname == $h) | {host: .}' /etc/ianitor/trial-hosts.json)" done # each is kept or reverted within 60 s; GET $API/applies/ ``` (The web UI needs the admin host behind Authelia; for the trial, run it locally against the tunnel. The token goes in through the environment, never the command line, and the dev proxy adds it, so the browser never holds it: IANITOR_CONTROL=http://127.0.0.1:7878 \ IANITOR_DEV_TOKEN="$(sed 's/^Authorization: Bearer //' ~/.ianitor-header)" pnpm --filter web dev ) Then, from the desktop (192.168.100.140): ```sh deploy/test-access.sh --server 192.168.100.166 --insecure \ --public git.stage.marek-novak.cz --public ha.stage.marek-novak.cz \ --via-ianitor flowers.stage.marek-novak.cz --via-ianitor esp32.stage.marek-novak.cz ``` `--insecure` because the stage names use Caddy's `tls internal` (or the stage wildcard). Each `--via-ianitor` host must answer with `X-Served-By: ianitor` (set by its route in the patch), so an answer from Caddy alone fails. It must print `all checks passed`; the two-week run (§1.12) starts then. Rollback at any time: `git revert` the commit, `Deploy-Staging.ps1 -Mode Switch`. Ianitor's state stays in /var/lib/ianitor and is ignored. ## The Let's Encrypt staging check (moved to phase 3, Mark 2026-11-07) ACME HTTP-01 needs a name that resolves publicly to the machine that receives port 80, which is production (.217; the mirror has no port forward). It is one documented check, not part of the trial: 1. At Forpsi, add `ianitor-le.marek-novak.cz` (A record, the public IP). 2. On production's Caddy, hand that name's challenge path to Ianitor (the rest of the name can 404): ```caddy http://ianitor-le.marek-novak.cz { reverse_proxy /.well-known/acme-challenge/* 127.0.0.1:18080 } ``` 3. In Ianitor's routes, `ianitor.toml` gets `[acme] directory = "https://acme-staging-v02.api.letsencrypt.org/directory"` and a host `ianitor-le.marek-novak.cz` with `tls = "letsencrypt"` and any upstream. 4. Check: `openssl s_client -connect 127.0.0.1:18443 -servername ianitor-le.marek-novak.cz