[repo] NixOS: flake with the release build (test hooks off) and the web UI, services.ianitor module (edge, control, caddy-fallback, engine-select, per-boot UI proof, polkit for exactly two units), four VM tests, deploy/test-access.sh
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
# 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/...`).
|
||||
- There is **no Authelia** in the repository; hosts rely on their applications' own logins.
|
||||
- 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) ── https://127.0.0.1:18443 Ianitor edge ── the app
|
||||
```
|
||||
|
||||
- Ianitor edge listens 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.
|
||||
- Caddy keeps the public side for the two names and hands them to Ianitor over TLS; Ianitor
|
||||
serves them with Domi certificates, which Caddy checks against the Domi root (a public file).
|
||||
- Every other host is untouched. Rollback: revert the patch and switch (below).
|
||||
|
||||
## 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 (values generated, never typed into a file in the repository):
|
||||
cd hyperv-infra
|
||||
sops set secrets/secrets.yaml '["ianitor"]["share-link-key"]' "\"$(head -c 32 /dev/urandom | base64 -w0)\""
|
||||
sops set secrets/secrets.yaml '["ianitor"]["pki-password"]' "\"$(head -c 32 /dev/urandom | base64 -w0)\""
|
||||
# Pin Ianitor to the reviewed commit:
|
||||
nix flake lock --override-input ianitor "git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=<merged commit>"
|
||||
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:
|
||||
ssh -L 7878:127.0.0.1:7878 mirror
|
||||
TOKEN=ian_...; API=http://127.0.0.1:7878/api/v1; H="Authorization: Bearer $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/<id>
|
||||
```
|
||||
|
||||
(The web UI needs the admin host behind Authelia, which this repository does not have. For the
|
||||
trial, run it locally against the tunnel: `IANITOR_CONTROL=http://127.0.0.1:7878
|
||||
IANITOR_DEV_TOKEN=$TOKEN pnpm --filter web dev`; the dev proxy adds the token, the browser never
|
||||
holds it.)
|
||||
|
||||
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). 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 </dev/null | openssl x509 -noout -issuer`
|
||||
shows a `(STAGING)` issuer; `GET /api/v1/hosts/ianitor-le.marek-novak.cz` shows
|
||||
`certificate.state = "ok"`.
|
||||
5. Remove the name, the Caddy block and the `[acme]` line afterwards.
|
||||
@@ -0,0 +1,119 @@
|
||||
diff --git a/hyperv-infra/flake.nix b/hyperv-infra/flake.nix
|
||||
index 0d30b91..4302dc7 100644
|
||||
--- a/hyperv-infra/flake.nix
|
||||
+++ b/hyperv-infra/flake.nix
|
||||
@@ -60,6 +60,11 @@
|
||||
# full commit rather than by branch: `nixos-unstable` drifts, and drifting is precisely the
|
||||
# failure mode that produced G-27 on production in the first place.
|
||||
nixpkgs-gitea.url = "github:nixos/nixpkgs/6368eda62c9775c38ef7f714b2555a741c20c72d";
|
||||
+
|
||||
+ # Ianitor (the Pingora reverse proxy), beside Caddy on two low-risk hosts. Its packages are
|
||||
+ # built from its own pinned nixpkgs; only the module is evaluated against this one. Pin to a
|
||||
+ # reviewed commit (rev=...) before switching production.
|
||||
+ ianitor.url = "git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?ref=main";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, sops-nix, nixpkgs-gitea, ... }@inputs: {
|
||||
@@ -86,6 +91,8 @@
|
||||
|
||||
# Application modules
|
||||
./modules/caddy.nix
|
||||
+ # Ianitor beside Caddy: flowers and esp32 go through it (modules/ianitor.nix).
|
||||
+ ./modules/ianitor.nix
|
||||
./modules/home-assistant.nix
|
||||
|
||||
# ./modules/nextcloud.nix
|
||||
diff --git a/hyperv-infra/modules/caddy.nix b/hyperv-infra/modules/caddy.nix
|
||||
index e79f6b2..6fb5a49 100644
|
||||
--- a/hyperv-infra/modules/caddy.nix
|
||||
+++ b/hyperv-infra/modules/caddy.nix
|
||||
@@ -225,6 +225,21 @@ in
|
||||
Referrer-Policy "strict-origin-when-cross-origin"
|
||||
}
|
||||
'';
|
||||
+ # The Ianitor trial (modules/ianitor.nix): Caddy keeps the public side and hands the request
|
||||
+ # to Ianitor edge on loopback, over TLS with a Domi certificate it checks against the Domi
|
||||
+ # root. Host and SNI are the visitor's name.
|
||||
+ viaIanitor = host: {
|
||||
+ extraConfig = ''
|
||||
+ tls internal
|
||||
+ ${secureHeaders "SAMEORIGIN"}
|
||||
+ reverse_proxy https://127.0.0.1:18443 {
|
||||
+ transport http {
|
||||
+ tls_server_name ${host}
|
||||
+ tls_trusted_ca_certs ${../ianitor/domi-root.crt}
|
||||
+ }
|
||||
+ }
|
||||
+ '';
|
||||
+ };
|
||||
simple = { frame ? "SAMEORIGIN", upstream }: {
|
||||
extraConfig = ''
|
||||
tls internal
|
||||
@@ -252,7 +267,11 @@ in
|
||||
# flowers - was `localhost:8085`, which is PRODUCTION's port. On the mirror the app is
|
||||
# published on 127.0.0.1:8092 and fronted by nginx on 8091, matching production's topology
|
||||
# (nginx in front, not Caddy straight to the container). Proxying to 8085 reached nothing.
|
||||
- "flowers.stage.marek-novak.cz" = simple { upstream = "127.0.0.1:8091"; };
|
||||
+ # Through Ianitor (trial); before: simple { upstream = "127.0.0.1:8091"; }.
|
||||
+ "flowers.stage.marek-novak.cz" = viaIanitor "flowers.stage.marek-novak.cz";
|
||||
+
|
||||
+ # Through Ianitor (trial). Explicit, so it wins over the `projects` entry below.
|
||||
+ "esp32.stage.marek-novak.cz" = viaIanitor "esp32.stage.marek-novak.cz";
|
||||
|
||||
# supabase - the whole block previously proxied to 172.18.0.3 / .6 / .9.
|
||||
#
|
||||
diff --git a/hyperv-infra/modules/ianitor.nix b/hyperv-infra/modules/ianitor.nix
|
||||
new file mode 100644
|
||||
index 0000000..cd23016
|
||||
--- /dev/null
|
||||
+++ b/hyperv-infra/modules/ianitor.nix
|
||||
@@ -0,0 +1,49 @@
|
||||
+{ config, lib, inputs, ... }:
|
||||
+
|
||||
+# Ianitor beside Caddy (Ianitor ROADMAP §1.12, Phase 3): two low-risk hosts, flowers and esp32,
|
||||
+# go through Ianitor's edge; every other host stays on Caddy exactly as before.
|
||||
+#
|
||||
+# Shape, chosen to keep decision D-21a ("Caddy is the only thing on 80/443 and the only service
|
||||
+# exposed beyond loopback"):
|
||||
+#
|
||||
+# visitor -> Caddy :443 (tls as today) -> https://127.0.0.1:18443 Ianitor edge -> the app
|
||||
+#
|
||||
+# Ianitor edge listens on loopback only (18080/18443) and terminates TLS with a Domi certificate;
|
||||
+# Caddy trusts the Domi root (a public certificate, ianitor/domi-root.crt) for that hop. Control
|
||||
+# listens on 127.0.0.1:7878. Nothing new is reachable from the LAN.
|
||||
+#
|
||||
+# Secrets come from sops-nix (paths under /run/secrets, never the store); the module asserts it.
|
||||
+# Rollback: remove this import and the two `viaIanitor` lines in caddy.nix, nixos-rebuild switch.
|
||||
+
|
||||
+let
|
||||
+ stage = "stage.marek-novak.cz";
|
||||
+in
|
||||
+{
|
||||
+ imports = [ inputs.ianitor.nixosModules.ianitor ];
|
||||
+
|
||||
+ sops.secrets."ianitor/share-link-key" = { };
|
||||
+ sops.secrets."ianitor/pki-password" = { };
|
||||
+
|
||||
+ services.ianitor = {
|
||||
+ enable = true;
|
||||
+ edge = {
|
||||
+ httpListen = "127.0.0.1:18080";
|
||||
+ httpsListen = "127.0.0.1:18443";
|
||||
+ openFirewall = false;
|
||||
+ };
|
||||
+ control.listen = "127.0.0.1:7878";
|
||||
+ shareLinkKeyFile = config.sops.secrets."ianitor/share-link-key".path;
|
||||
+ pki = {
|
||||
+ enable = true;
|
||||
+ rootCertificate = ../ianitor/domi-root.crt;
|
||||
+ passwordFile = config.sops.secrets."ianitor/pki-password".path;
|
||||
+ };
|
||||
+ };
|
||||
+
|
||||
+ # The trial hosts, as Ianitor route files. They are applied through the API after the first
|
||||
+ # start (docs/deploy/beside-caddy.md in the Ianitor repo); listed here so the review sees them.
|
||||
+ environment.etc."ianitor/trial-hosts.json".text = builtins.toJSON [
|
||||
+ { hostname = "flowers.${stage}"; upstreams = [ "http://127.0.0.1:8091" ]; tls = "domi"; auth = "none"; health_check = { path = "/"; interval_secs = 30; }; }
|
||||
+ { hostname = "esp32.${stage}"; upstreams = [ "http://127.0.0.1:8093" ]; tls = "domi"; auth = "none"; health_check = { path = "/"; interval_secs = 30; }; }
|
||||
+ ];
|
||||
+}
|
||||
Reference in New Issue
Block a user