[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:
2026-11-08 00:04:13 +01:00
parent a61dfd854f
commit ca9bf3fdd4
13 changed files with 1375 additions and 4 deletions
+93 -3
View File
@@ -10,9 +10,12 @@ Everything below was run end to end on loopback against `--dev` with a real edge
## Ground rules
- **Token.** Every call needs `Authorization: Bearer <API token>`. Nothing else identifies a
caller (no `Remote-User`). Without a valid token: `401` with `token.missing`,
`token.unknown`, `token.expired` or `token.revoked`. 120 calls a minute per token.
- **Token or sign-in.** A script sends `Authorization: Bearer <API token>`. The web UI sends
no token: it comes through edge on the admin host, behind Authelia (see "Sign-in" below).
Without either: `401` with `token.missing`, `token.unknown`, `token.expired` or
`token.revoked`; a `Remote-*` header without edge's proof is `401 ui.no_proof`, whatever
else the request carries. 120 calls a minute per token or user. The one exception is the
one-time device download (`GET /device-bundles/{token}`), where the link is the secret.
- **Host header.** Only `127.0.0.1:<port>`, `localhost:<port>`, `[::1]:<port>` and the
configured `allowed_hosts` are answered (DNS rebinding). A browser write (`Origin` or
`Sec-Fetch-Site` present) also needs `X-Ianitor-UI: 1` (CSRF).
@@ -232,6 +235,89 @@ curl -s -H "$H" -X DELETE "$API/tokens/<id>" # 204; anything using it sto
curl -s "$API/overview" | jq .error.code # "token.missing"
```
## Sign-in (the web UI, G14)
The UI is served by control (`[ui] static_dir`) and reached through edge on the **admin host**,
a host in the routes repository with forward-auth to Authelia and one header rule:
```toml
# hosts/ianitor.example.toml
hostname = "ianitor.example"
upstreams = ["http://127.0.0.1:7878"]
tls = "domi"
auth = "forward-auth"
[[request_headers]]
action = "set"
name = "X-Ianitor-Proof"
secret = "ui-proof" # listed in ianitor.toml: secrets = ["ui-proof"]
```
- `ui-proof` is a **per-boot secret**: the `ianitor-ui-proof` unit writes 32 random bytes to
`/run/ianitor-proof/ui-proof` (root only), and edge, caddy-fallback and control load it with
`LoadCredential`. No other process can read it.
- Edge strips every client-sent `Remote-*` header on forward-auth hosts, asks Authelia, copies
Authelia's `Remote-User` (and `Remote-Name`, …) onto the request, and *sets* `X-Ianitor-Proof`
(replacing anything the client sent) only on requests Authelia allowed.
- Control (`[ui] proof_credential = "ui-proof"`, `hostname = "ianitor.example"`) trusts
`Remote-User` only on a request whose `X-Ianitor-Proof` matches (constant-time compare). Then
`Remote-User` is the actor (history, logs) and `Remote-Name` the name the UI shows. Every write
also needs `X-Ianitor-UI: 1` (CSRF; the session is a cookie).
- Any request with a `Remote-*` header but without the proof is `401 ui.no_proof`, so a local
process on loopback cannot claim a user; the proof without `Remote-User` is `401 ui.no_user`.
Tested in `crates/control/tests/ui_auth.rs`, including end to end through edge and a mock Authelia.
- `[ui] logout_url` (Authelia's logout address) becomes `overview.site.auth_logout_url`, the UI's
"Sign out". A Unix socket only edge can reach is Phase 4 hardening (decision Q2).
Why not the Unix socket now: edge's upstreams are `host:port` in the schema; a socket upstream is a
schema and compiler change in both engines, and the proof header needs neither.
## Certificates (the Domi CA)
Everything is in [pki.md](pki.md); the calls:
```sh
curl -s -H "$H" "$API/certs" | jq '{intermediate: .intermediate.state, root: .root.offline, devices: [.devices[].name]}'
curl -s -H "$H" -X POST "$API/certs/intermediate/renewal" | jq '{request_id, match_code, approve_command}'
curl -s -H "$H" "$API/pki-requests/$ID/csr" > req.csr; curl -s -H "$H" "$API/pki-requests/$ID/ext" > req.ext
curl -s -H "$H" -H 'Content-Type: application/json' -X PUT "$API/pki-requests/$ID/certificate" \
-d "$(jq -n --rawfile c int.crt '{certificate_pem: $c}')" | jq .state # "approved"
curl -s -H "$H" -H 'Content-Type: application/json' -X POST "$API/certs/devices" \
-d '{"name": "Mark'\''s phone", "kind": "phone"}' | jq '{request_id, match_code, approve_command}'
# on the server: sudo -u ianitor-control ianitor-control pki approve 47 19 83 --config /etc/ianitor/control.toml
curl -s -H "$H" -H 'Content-Type: application/json' -X POST "$API/certs/devices/$DEV/bundle" \
-d '{"format": "p12"}' | jq '{download_url, one_time_password}'
curl -s -o phone.p12 "$DOWNLOAD_URL" # once; a second try is 410 pki.bundle_used
curl -s -H "$H" -X DELETE "$API/certs/devices/$DEV" # 204, off the allow list at once
```
`overview.intermediate` is `{state ("ok"|"due"|"urgent"|"expired"|"missing"), subject, not_after,
days_left, renewal, banner}`, or `null` without `[pki]`. With `[pki]` configured, control issues
the server certificate of every `tls = "domi"` host before an apply is committed, renews it with 30
days left, and an apply with a Domi host and no intermediate fails with `pki.no_intermediate`.
## Engine switch (G18)
```sh
curl -s -H "$H" "$API/engine" | jq '{running, state, switchable}'
curl -s -H "$H" -H 'Content-Type: application/json' -X POST "$API/engine" -d '{"target": "caddy"}' # 202
# poll GET /engine until state = "running"; last_error says why if it went back
```
Control writes `/var/lib/ianitor/engine` first, stops the serving unit, starts the other one (polkit
allows exactly `ianitor-edge.service` and `caddy-fallback.service`, verbs start/stop/restart) and
waits until it serves; if it does not within 20 s, it starts the old one again and reports
`engine.switch_failed`. The switch waits for a running apply (same lock). Refusals:
`engine.unmanaged` (no `[engine]` in control.toml), `engine.same`, `engine.switching`,
`engine.not_ready` (Caddy's settings cannot be built from the current routes).
While Caddy serves (decisions Q3, Q4):
- changes are paused: `overview.paused_reason = "engine.caddy"`, writes get `409 control.paused`;
- **share links are off**: minting is `409 share.engine_caddy`, and a visitor with a link gets the
normal sign-in (fails closed). Caddy cannot check a share token and control never serves
visitors; a validator Caddy calls through `forward_auth` is planned before v1.1;
- device revocations restart caddy-fallback (Caddy reads the allow list when it starts).
## All calls
| Call | Does |
@@ -248,4 +334,8 @@ curl -s "$API/overview" | jq .error.code # "token.missing"
| `GET/POST /tokens`, `PATCH/DELETE /tokens/{id}` | API tokens |
| `POST /hosts/{h}/share-links`, `GET /share-links`, `DELETE /share-links/{id}`, `POST /share-links/stop-all` | share links |
| `GET /health` | edge reachability, config hash, trial, paused state, hosts |
| `GET /certs`, `POST /certs/devices`, `DELETE /certs/devices/{id}`, `POST /certs/devices/{id}/bundle` | the Domi CA screen, device requests, revocation, one-time install files |
| `POST /certs/intermediate/renewal`, `GET/DELETE /pki-requests/{id}`, `GET /pki-requests/{id}/csr`, `GET /pki-requests/{id}/ext`, `PUT /pki-requests/{id}/certificate` | renewals and approvals |
| `GET /device-bundles/{token}` | the one-time PKCS#12 download (no token; the link is the secret) |
| `GET /engine`, `POST /engine` | which engine serves; switch |
| `GET /openapi.json` | the OpenAPI document |