[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:
+5
-1
@@ -64,7 +64,10 @@ Main screen: host list with health dots, engine chip, intermediate-expiry banner
|
||||
| API token: ⚙ → API → New token | 3 |
|
||||
|
||||
Accepted exceptions [M 2026-11-07]: copying a new API token and installing a device certificate may take a 4th click
|
||||
(deliberate secret-handling steps).
|
||||
(deliberate secret-handling steps). A share link on a host with links off takes 4 clicks (⋯ → Share link → Turn on
|
||||
share links → Copy, after the apply is kept; no `turn_on` API change). Signing the intermediate by hand on the offline
|
||||
machine (openssl) is outside the 1-click Renew budget while Custos lacks the operation (§8.6). Share links are off
|
||||
while Caddy serves (v1); a validator Caddy calls through forward_auth comes before v1.1's monthly switch rehearsal.
|
||||
|
||||
## 5. Test layers (all run in an Artifex pipeline by phase 4)
|
||||
1. Differential: the same request corpus against Ianitor and Caddy; status, selected headers and body compared.
|
||||
@@ -133,6 +136,7 @@ Identity gate, tunnel, Domi templates, ACME server, HTTP/3, migrating public sit
|
||||
5. Authelia forward-auth endpoint and headers to mirror exactly. (phase 1)
|
||||
**Answer: `GET /api/authz/forward-auth` (ForwardAuth implementation; legacy `/api/verify` not used).** Edge sends X-Forwarded-Method, -Proto, -Host, -URI (required) and X-Forwarded-For, and always sets them itself. It also forwards the client's headers (Cookie, Authorization) without hop-by-hop headers or body. A 2xx answer copies Remote-User, Remote-Groups, Remote-Email and Remote-Name onto the request (client copies removed). Any other answer (302 portal, 401 + WWW-Authenticate, 403) goes back to the client verbatim. An unreachable, silent (10 s deadline), oversized (>1 MiB), broken or `101` auth answer fails closed with 502; 1xx heads are skipped. Client-sent Remote-* headers are always stripped on forward-auth hosts, whatever copy_headers says. This mirrors `caddy adapt` output for Authelia's documented `forward_auth` snippet; tested against a mock, not a real Authelia. [S authelia.com/reference/guides/proxy-authorization, authelia.com/integration/proxies/caddy]
|
||||
6. Custos CSR-signing operation with match-code approval. (phase 3)
|
||||
**Answer: Custos has none (desktop 0.8.0, CustosPublic v0.13.0).** Its `sign` op signs only minisign, SHA256SUMS manifests, Authenticode digests and deploy approvals, refuses any request against `domi-root` (the RSA-3072 Authenticode root), and no path takes a CSR. Its server reach is the factor-service sign mailbox (`POST /api/sign/requests`, Bearer sign token, answers sealed to a one-time X25519 key, 5-minute match-code card on the PC with a push to the phone). So, per §6: the operation is written as a ticket, [custos-ticket.md](custos-ticket.md) (a new key `domi-pki-root`, ECDSA P-256; a sign kind `x509_csr` through the same mailbox that builds the intermediate from a fixed profile and takes only the CSR's key and CN; the match code computed from the CSR on both screens), not filed. Until then the intermediate is signed **by hand on the offline machine with openssl** ([pki.md](pki.md); Mark accepted it as a §4 exception, 2026-11-07) and device certificates are approved on the server with `sudo -u ianitor-control ianitor-control pki approve <code>` (Q5). API tokens: Custos stores them as "Local app credential" items with a `domi-ref`; the intended import is Provisio's `offer` (the server seals the value to the PC's key and Mark accepts a match-code card), or copy and paste in the item editor. [S Custos docs/09_signing.md, 07_domi_identity.md, 10_provisio.md, apps/desktop/src-tauri/src/signing.rs] Configuration_Server findings (domains, Caddy, no Authelia in the repository, sops-nix secrets, the two trial hosts): [deploy/beside-caddy.md](deploy/beside-caddy.md).
|
||||
7. Red Panda Network donation route for a non-US individual and the receipt they issue. (phase 4, Mark)
|
||||
|
||||
## 9. Status
|
||||
|
||||
+93
-3
@@ -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 |
|
||||
|
||||
@@ -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; }; }
|
||||
+ ];
|
||||
+}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
# The Domi CA
|
||||
|
||||
ROADMAP §1.1, §1.2, §1.8, §3. Code: `crates/core/src/pki.rs` (the CA, pure),
|
||||
`crates/control/src/pki.rs` (state, requests, devices), `crates/edge/src/tls.rs` (device
|
||||
certificates in the handshake).
|
||||
|
||||
```text
|
||||
Domi PKI Root ~10 years, pathLen 1 offline; never on the server
|
||||
└ Ianitor Domi Intermediate 1 year, pathLen 0 on the server, key encrypted at rest
|
||||
├ <hostname> 90 days, serverAuth tls = "domi" hosts, renewed by control
|
||||
└ <device name> 1 year, clientAuth mTLS for hosts with device_certs = true
|
||||
```
|
||||
|
||||
All keys are ECDSA P-256.
|
||||
|
||||
## Lifetimes, and why
|
||||
|
||||
| Certificate | Lifetime | Why |
|
||||
|:--|:--|:--|
|
||||
| Root | 3653 days | ROADMAP §3 ("~10 years"). It signs once a year, offline. |
|
||||
| Intermediate | 365 days | ROADMAP §3 ("~1 year"); renewed through the banner, signed by the root. |
|
||||
| Server | 90 days, renewed at 30 days left | Control renews them by itself (hourly check), so a short life costs nothing and bounds a key read from the certificate directory; 30 days of slack survive a long control outage. |
|
||||
| Device | 365 days, "renew soon" at 30 days | Installing is a deliberate manual step (§4 accepts its 4th click), so not more than once a year; a lost device is revoked (allow list) rather than waited out. Mark, 2026-11-07 (Q7). |
|
||||
|
||||
No certificate is ever issued past its issuer's `notAfter`.
|
||||
|
||||
## What is where on the server
|
||||
|
||||
`/var/lib/ianitor/control/pki/` (mode 0700, owner ianitor-control):
|
||||
|
||||
| File | What |
|
||||
|:--|:--|
|
||||
| `intermediate.crt`, `previous.crt` | the intermediate, and the one before while it is valid |
|
||||
| `intermediate.key` | its key, `IANITOR ENCRYPTED PRIVATE KEY` (PBKDF2-HMAC-SHA256 600,000 rounds + AES-256-GCM), password from the `pki-password` credential |
|
||||
| `pending-<id>.key` | the new key of an open renewal, encrypted the same way |
|
||||
| `devices.json`, `devices/<id>.key` | issued device certificates; their keys, encrypted, kept to make an install file again until revoked |
|
||||
| `requests.json`, `approvals/` | approval requests, and the manual approvals the CLI writes |
|
||||
|
||||
`/var/lib/ianitor/certs/`: `<host>.crt` (leaf + intermediate) and `<host>.key` (0640, group
|
||||
ianitor), `domi-devices-ca.pem` (the intermediates that issue device certificates) and
|
||||
`domi-devices.pem` (the allow list: every issued, unrevoked, unexpired device certificate). Edge
|
||||
and Caddy read these files; a presented device certificate must chain to the bundle **and** be
|
||||
on the list, or the handshake fails.
|
||||
|
||||
The root key is never here. Control refuses to start when a file named like a root key is in
|
||||
its state directory (tested: `control_refuses_to_start_with_a_root_key_in_its_state_dir`).
|
||||
|
||||
## Until Custos can sign: the manual offline step
|
||||
|
||||
Custos has no CSR-signing operation yet (ROADMAP §8.6, [custos-ticket.md](custos-ticket.md)).
|
||||
Mark accepted this as a §4 exception (2026-11-07, Q6): **the offline machine runs openssl.**
|
||||
|
||||
### Once: the root, on the offline machine
|
||||
|
||||
```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"
|
||||
# asks for a passphrase: domi-root.key is stored encrypted
|
||||
openssl x509 -in domi-root.crt -noout -fingerprint -sha256
|
||||
```
|
||||
|
||||
(`ianitor-control ca init --out <dir>` makes the same root with Ianitor's own encrypted key
|
||||
format, on a machine that has Ianitor.) Copy **only `domi-root.crt`** to the server's
|
||||
configuration (`services.ianitor.pki.rootCertificate`). `domi-root.key` and its passphrase stay
|
||||
offline (and go into Custos once it can hold them).
|
||||
|
||||
### Each year (and the first time): the intermediate
|
||||
|
||||
1. In the UI: the banner's **Renew** (or **Set up**) makes a new key on the server and a CSR, and
|
||||
shows a match code. **Sign it by hand** downloads `domi-intermediate-<date>.csr` and
|
||||
`domi-intermediate-<date>.ext` (the signing profile: CA, pathLen 0, keyCertSign + cRLSign). By
|
||||
API: `POST /certs/intermediate/renewal`, `GET /pki-requests/{id}/csr`, `GET /pki-requests/{id}/ext`.
|
||||
2. On the offline machine, check the request, then sign:
|
||||
```sh
|
||||
openssl req -in domi-intermediate-<date>.csr -noout -subject # CN=Ianitor Domi Intermediate <yyyy-mm>
|
||||
openssl x509 -req -in domi-intermediate-<date>.csr -CA domi-root.crt -CAkey domi-root.key \
|
||||
-days 365 -sha256 -extfile domi-intermediate-<date>.ext -out domi-intermediate-<date>.crt
|
||||
```
|
||||
(`ianitor-control ca sign --root <dir> --csr … --out …` does the same and asks for the match
|
||||
code before it signs.)
|
||||
3. Back on the server: upload the `.crt` in the UI (step 3), or
|
||||
`sudo -u ianitor-control ianitor-control pki install domi-intermediate-<date>.crt --config /etc/ianitor/control.toml`.
|
||||
|
||||
Control checks that the certificate is signed by the configured root, is a CA with path length 0,
|
||||
is valid now, and carries the pending key; then it swaps the intermediate, reissues every
|
||||
`tls = "domi"` certificate and reloads the engine that serves. Tested with real openssl
|
||||
(`an_intermediate_signed_with_openssl_is_installed`).
|
||||
|
||||
## Device certificates
|
||||
|
||||
ROADMAP §4: Certificates → + Device → Issue (3 clicks), then install (the accepted 4th).
|
||||
|
||||
1. `POST /certs/devices {name, kind}` opens a request with a six-digit match code, for 10 minutes.
|
||||
2. Until Custos can approve (Mark, Q5): approve it on the server, comparing the code with the UI:
|
||||
`sudo -u ianitor-control ianitor-control pki approve 47 19 83 --config /etc/ianitor/control.toml`
|
||||
(`pki deny <code>` turns it down; `pki status` lists open requests). Control issues the
|
||||
certificate within two seconds and puts it on the allow list; edge re-reads the list at once.
|
||||
3. Install: `POST /certs/devices/{id}/bundle {format: "qr"|"p12"}` gives a one-time link (10
|
||||
minutes, one download) to a PKCS#12 file (AES-256, SHA-256 MAC) and a one-time password. When
|
||||
`[ui] hostname` is set the link goes through edge on the admin host, as a share link when that
|
||||
host has share links on, so a device without a sign-in can fetch it; the token is the secret.
|
||||
4. Revoke: `DELETE /certs/devices/{id}`. It is off the allow list at once (edge:
|
||||
`/v1/device-certs/reload`; Caddy: control restarts caddy-fallback, which reads the list at start).
|
||||
|
||||
A host asks for device certificates with `device_certs = true` in its file. Only such hosts send a
|
||||
certificate request in the TLS handshake (other hosts never prompt a browser). Without a
|
||||
certificate, or with one not on the list, the handshake fails on both engines; a request whose
|
||||
`Host` is another name than the connection's SNI is answered 421 once any host needs device
|
||||
certificates (as Caddy does).
|
||||
@@ -508,3 +508,34 @@ written above.
|
||||
`share.not_found`, `share.replaces`, `share.password_long`, `share.too_many`,
|
||||
`request.in_progress`, `control.files_unwritten`, `token.not_found`, `token.name`,
|
||||
`token.expiry`, `file.*`, `site.*` (problems in `ianitor.toml`).
|
||||
|
||||
## 7. Phase 3: the deferred items as built
|
||||
|
||||
Recorded by the Phase 3 implementation (branch `phase-3`); docs/api.md has the calls.
|
||||
|
||||
- **G7** (share links under Caddy): off for v1 (Mark, Q4). Minting is refused with
|
||||
`409 share.engine_caddy` while Caddy serves, `overview.site.share_links_available` is false and
|
||||
the engine popover, share dialog and Settings say so. Visitors fail closed (normal sign-in).
|
||||
- **G12**: the token dialog keeps "Copy token" as the accepted 4th click (Mark); the POST answers
|
||||
well under a second. Tokens never reach storage, URLs or logs (tested in the smoke test).
|
||||
- **G13**: device install is the accepted 4th click.
|
||||
- **G14**: edge's per-boot proof header on the admin host; control trusts `Remote-User` (actor)
|
||||
and `Remote-Name` (shown) only with it; a forged `Remote-User` is `401 ui.no_proof`.
|
||||
`overview.viewer {name, via}` and `overview.site.auth_logout_url` are new.
|
||||
- **G15**: `POST /certs/devices/{id}/bundle` → one-time `GET /device-bundles/{token}` (10 min,
|
||||
one use, PKCS#12 with a one-time password, `qr_svg` for `format = "qr"`); through edge on the
|
||||
admin host, as a share link when that host has share links on.
|
||||
- **G18**: `GET/POST /engine` (shape in docs/api.md). Differences from §1.9: no `fallback_ready
|
||||
{compared, matched}` (control cannot run the differential suite at runtime; it reports
|
||||
`{built_at, current}`), and **changes are paused while Caddy serves** (`paused_reason =
|
||||
"engine.caddy"`).
|
||||
- **G19**: the UI shows "No websockets" only when off, and "Open to anyone" for `auth = none` (Q11).
|
||||
- **PKI** (§1.7, §1.8, §3.6): built as drawn, with two differences while Custos lacks the
|
||||
operations: device requests are approved on the server (`pki approve <code>`, the UI shows the
|
||||
command and the code; `message_code = "pki.waiting.manual"`), and renewals are signed by hand
|
||||
with openssl (`approve_command`, `file_base`, `GET /pki-requests/{id}/ext`). Requests carry
|
||||
`problem` (not `error`) for why they failed. Renewal requests stay open 7 days, device requests
|
||||
10 minutes.
|
||||
- New host field `device_certs` (bool): only Domi device certificates on the allow list get in.
|
||||
- `overview.paused_reason` gives the underlying code (`apply.needs_attention`,
|
||||
`control.files_unwritten`, `repo.*`, `engine.caddy`) next to `paused {code: "control.paused"}`.
|
||||
|
||||
Reference in New Issue
Block a user