Files
ianitor/docs/ROADMAP.md
T

210 lines
22 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Ianitor Domi — roadmap
*Ianitor* = the doorkeeper: it decides who comes through the door (routing, TLS) and checks credentials (certificates).
Legend: [S] sourced · [J] judgment · [M] decided by Mark.
## 1. Decisions (do not reopen without Mark)
1. Scope: internal Domi CA for home-server services and mTLS between Domi apps/devices. Public sites stay on Let's Encrypt. [M]
2. Root key offline in Custos; intermediate on the server, renewed yearly through a Custos match-code approval. [M]
3. Own proxy on Pingora (Rust, Apache 2.0; HTTP/1, HTTP/2, gRPC, websockets; a library, not a binary). [M] [S blog.cloudflare.com/pingora-open-source]
4. Caddy is the fallback: one config model compiled to the Pingora runtime and to Caddy JSON, kept honest by differential tests on every build. [M]
5. Web UI only, on the server behind Authelia. API tokens are saved by Mark in Custos; control stores only hashes. [M]
6. Routes live in a git repo (private: ianitor-routes), one TOML file per host, schema-validated. Every change is a commit, applied live without nixos-rebuild. Rebuild only for service-level changes (ports, version). The engine is switched at runtime by control (§3, §4); decided 2026-11-07, replacing "engine" in the rebuild list. [M]
7. Two processes: ianitor-edge (data plane) and ianitor-control (API + UI). Traffic keeps flowing if control crashes. [M]
8. Own small CA in crates/core using rcgen. No internal ACME server in v1. [M]
9. One public MPL-2.0 monorepo on Gitea; read-only GitHub mirror for discovery. Mark's server deployment stays in his NixOS flake. [M]
10. Branding: "Ianitor Domi", with "Built, tested and signed by Fabrica Domi" on the repo and release page. [M]
11. Support: free source; "Adopt a red panda" — 80% developer, 20% Red Panda Network, remitted yearly with a published receipt. [M]
12. Cut-over: only after all five test layers are green and two weeks beside Caddy on low-risk hosts. [M]
13. Competitor to watch: Pangolin (tunnelled identity-aware reverse proxy). Our edge: Nix-native history, Domi PKI, friend nodes. [S github.com/fosrl/pangolin] [J]
## 2. Versions and gates
| Version | Contents | Gate question |
|:--|:--|:--|
| v1 (phases 1–4) | engine, both compilers, control plane, web UI, PKI, NixOS module, five test layers, signed release | Does Ianitor serve two low-risk hosts beside Caddy for two weeks with zero incidents and the differential tests green? |
| v1.1 | all hosts on Ianitor; monthly rehearsed switch to Caddy and back | Are all hosts on Ianitor, with the Caddy switch rehearsed monthly? |
| v2 | identity gate (passkey/TOTP) replacing Authelia, tunnel via friend node/VPS, one-click Domi templates | Can a family member reach a home service from outside with no open port and no Authelia? |
## 3. Architecture
- Host file fields (v1): hostname, upstreams[], tls = letsencrypt | domi, auth = none | forward-auth,
request/response header rules (set/remove; values may reference a named secret), websockets,
health check path + interval, share links enabled, access log = off | truncated.
- Edge: TLS termination with SNI per host, Let's Encrypt via an ACME crate, upstream health checks, websockets,
header rules, forward-auth compatible with Authelia (existing protected services must keep working),
graceful reload without dropping connections.
- Secrets referenced by header rules load from $CREDENTIALS_DIRECTORY and never appear in logs or responses.
- Logging: error log always; access log only per host when enabled, IPv4 truncated to /24, IPv6 to /48, local file only.
- Apply: validate → compile → write edge config + Caddy JSON → reload edge → watch health checks 60 s →
on failure git-revert, reload, report "reverted" with the reason; otherwise "kept". Concurrent applies are serialised.
Undo = revert the last kept commit through the same path. Restore = apply an older tree as a new commit. Push to Gitea after a kept apply.
- Share links: HMAC token bound to host + path prefix + expiry (+ optional password, mixed into the MAC; no hash in the token,
so it cannot be guessed offline; edge rate-limits tries), validated statelessly by edge; key from systemd credentials;
revocation by key rotation, an epoch ("stop all") or a small deny list kept in a file outside git that control writes and edge
re-reads at once, so a Stop never waits for an apply; neither the epoch nor the list ever goes backwards. [M 2026-11-07]
- API: REST + JSON on loopback, OpenAPI generated from code.
- CA: root created offline, ~10 years, pathLenConstraint ≥ 1, never on the server. Intermediate ~1 year, key encrypted on the server,
password via systemd credentials. Leaf and device mTLS certs issued by control (lifetimes decided and justified in phase 3).
Intermediate renewal: control makes a CSR; Custos signs with the root after a match-code approval.
- Engine switch: the NixOS module defines ianitor-edge and caddy-fallback (reads the generated Caddy JSON); only one runs;
an engine-select unit starts the chosen one at boot from /var/lib/ianitor/engine; control may start/stop only these two
units through a polkit rule scoped to exactly them.
- NixOS module: services.ianitor.*; everything on loopback except edge; LoadCredential for secrets, asserted not to be store paths.
## 4. UI (count clicks in every smoke test)
Main screen: host list with health dots, engine chip, intermediate-expiry banner, last-apply bar with Undo.
| Flow | Clicks |
|:--|:--|
| Add host: + Host → fill → Apply (auto-kept or auto-reverted) | 2 |
| Undo last change | 1 |
| Restore: History → pick → Restore | 3 |
| Share link: ⋯ → Share → Copy (default expiry 7 d) | 3 |
| Switch engine: engine chip → Switch to Caddy | 2 |
| Device cert: Certs → + Device → Issue (approve in Custos) | 3 |
| Renew intermediate: banner Renew (approve in Custos) | 1 |
| 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).
## 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.
2. Protocol conformance: h2spec, testssl.sh.
3. Fuzzing: cargo-fuzz on config parsing, header rules, share tokens; any crash fails the pipeline.
4. NixOS VM tests: failed apply auto-reverts; switch to Caddy and back keeps a host reachable; intermediate renewal with a test root; control unreachable from outside loopback.
5. Load and soak against Caddy, reproducible from a script; results committed as data, published honestly including where Caddy wins.
## 6. Phases
### Phase 1 — Core and engine
Goal: Pingora proxy serving hosts from the validated model; same model compiled to Caddy JSON; differential harness proving parity.
First: .gitignore and a pre-commit hook (rejects binaries, private keys, files > 5 MB). Placeholders only for control/web.
Tests first: schema rejects unknown fields, missing/duplicate hostnames, bad upstream URLs, undefined secret references;
both compilers deterministic (byte-identical output); an injected secret never appears in a response or log;
a forward-auth denial never reaches the upstream; the diff harness (≥ 20 seed requests: plain, headers, websocket upgrade,
upstream down, auth denied) catches a deliberately broken compiler once.
Done: proxies two local test upstreams with Let's Encrypt staging and with a self-signed test cert; diff suite green.
### Phase 2 — Control plane
Goal: ianitor-control edits route files in the git repo, applies with automatic rollback, manages share links and API tokens.
Tests first: failed health check reverts the commit and restores the previous edge config; a control crash mid-apply leaves edge
on the last good config; share token rejected when expired, wrong path, wrong host, tampered or missing password;
requests without a valid token rejected and tokens never logged; concurrent applies serialised.
Done: add host, undo, restore and share link work end to end via the API on loopback; curl examples in docs/api.md;
diff suite green after every apply.
Also includes the UI API contract (docs/ui-api.md: overview, error codes, idempotency, health classes, watch probes,
history grouping, restore previews), accepted by Mark 2026-11-07.
### Phase 3 — Web UI, PKI, NixOS
Goal: the UI from section 4, the CA flows, the NixOS module with VM tests; Ianitor runs beside Caddy on two low-risk hosts.
Tests first: issued chains validate to the root; a leaf cannot sign; expired and wrong-name certs rejected; no root key file
in the state dir; a Domi device cert is accepted for mTLS while a self-signed cert with the same subject is rejected;
VM tests from section 5 layer 4.
If Custos has no CSR-signing operation with match-code approval: stop that part, write the needed operation as a Custos ticket,
and document a temporary manual offline signing step.
Done: smoke test of every UI flow with clicks counted; VM tests green; Mark has run nixos-rebuild; deploy/test-access.sh passes.
### Phase 4 — Hardening and release
Goal: all five test layers in an Artifex pipeline (strict Fabrica YAML); verifiable Nix build; artefacts signed via Custos,
published as Gitea release assets, sha256-pinned; GitHub push mirror.
Deliverables: README (what, why Pingora, honest benchmarks, the Caddy fallback, the Fabrica badge, support section);
docs/support.md (the red panda model); launch post drafts in docs/launch/ only. Release notes live on the Gitea release.
Done: pipeline green; signed v1.0.0 on Gitea; mirror visible on GitHub; the two-week run beside Caddy starts.
## 7. Out of scope for v1
Identity gate, tunnel, Domi templates, ACME server, HTTP/3, migrating public sites away from Caddy before the cut-over gate.
## 8. Open points (resolve at the start of the phase that needs them; record the answer here)
1. Pingora TLS backend: rustls vs BoringSSL/OpenSSL — maturity and NixOS packaging. (phase 1)
**Answer: rustls (ring), pingora 0.9.1 feature `rustls`.** Pure Rust, so no system TLS library, Perl, Go or clang in the Nix build. `TlsSettings::set_cert_resolver` gives SNI selection and lets ACME renewals swap certificates live; tested in crates/edge. Risk: the Pingora README labels it "rustls(experimental)", and the cert callback API is not available on rustls. Mitigation: the diff suite now, then testssl.sh/h2spec in phase 4. Fallback: the `openssl` feature, a change local to crates/edge/src/lib.rs and tls.rs. [S github.com/cloudflare/pingora README; pingora-core 0.9.1 src/listeners/tls/rustls] [J]
2. Rust ACME crate for Let's Encrypt — maintenance status; pick and justify. (phase 1)
**Answer: instant-acme 0.8.5** (djc/instant-acme; release 2026-02-24, ~1.5 M recent downloads). It is a plain RFC 8555 client with rustls/ring and rcgen, and edge keeps control of HTTP-01, storage and renewal. rustls-acme and tokio-rustls-acme (also maintained) own the TLS acceptor, which conflicts with Pingora's listener. acme2 (last release 2022) and acme-lib (2024) are stale. Verified end to end against Pebble 2.6 only, not against LE staging. [S crates.io API 2026-11-07] [J]
3. Does Pingora build on Windows? If not, develop in WSL2 and note it in CLAUDE.md. (phase 1)
**Answer: it compiles and the unit tests run on Windows (MSVC, Rust 1.99), but the README calls Windows support "preliminary by community's best effort only".** Unix-only parts include graceful upgrade, the in-process runner and the integration tests. Caddy and Pebble are not on this Windows box. So the edge integration tests, the diff suite and the ACME test run in WSL2 Debian, as noted in CLAUDE.md. One gotcha: libz-ng-sys's CMake build fails under a very deep CARGO_TARGET_DIR (MSBuild path length). [S github.com/cloudflare/pingora README; local builds 2026-11-07]
4. Pingora graceful reload behaviour under load. (phase 2)
**Answer: no Pingora graceful upgrade for config changes; edge swaps its config in process.** A reload builds a complete new runtime from the config file (secrets, certificates, share-link key) and installs it with one atomic pointer swap (`arc-swap`); listeners, TLS sessions and keep-alive connections are untouched, each request keeps the runtime it started with, and the next request on the same connection uses the new one. A config that fails to build is refused and the old one keeps serving; listen addresses change only with a restart. Control triggers it through edge's admin Unix socket (mode 0660, never a TCP port) as a *trial* that edge reverts by itself unless control confirms it in time, so a control crash mid-apply cannot strand edge on an unverified config. Pingora's graceful upgrade (new process takes the listening sockets, old one drains for the grace period) stays for binary upgrades only: it needs a second process and fd passing, and idle keep-alive connections on the old process are closed after the drain, which clients see as a reset on their next request; it was not measured. [J]
Measured (`crates/edge/tests/reload.rs`, debug build, WSL2 Debian, 16 cores, one local upstream; alternating two configs that differ in a response header, `POST /v1/reload` every 100 ms, each client one TLS keep-alive connection sending requests back to back):
| Clients | Duration | Reloads | Requests | Errors | Connection resets | Connections that saw both configs | p50 / p99 / max latency |
|--:|--:|--:|--:|--:|--:|--:|:--|
| 32 | 10 s | 98 | 30,198 | 0 | 0 | 32/32 | 10.5 / 17.2 / 132 ms |
| 64 | 30 s | 294 | 95,229 | 0 | 0 | 64/64 | 20.0 / 31.9 / 190 ms |
| 128 | 30 s | 292 | 87,796 | 0 | 0 | 128/128 | 43.1 / 69.1 / 215 ms |
Reproduce: `IANITOR_RELOAD_CLIENTS=64 IANITOR_RELOAD_SECS=30 cargo test -p ianitor-edge --test reload -- --exact unix::reload_under_load_drops_nothing --nocapture`. Not measured: a release build, HTTP/2 clients, long-lived websockets across reloads (they keep the runtime they started with until they close), and Pingora graceful upgrade for comparison. [S local runs 2026-11-07]
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)
7. Red Panda Network donation route for a non-US individual and the receipt they issue. (phase 4, Mark)
## 9. Status
| Phase | State | Notes |
|:--|:--|:--|
| 1 Core and engine | Done | Merged to main 2026-11-07. Tests run in WSL2; ACME checked only against Pebble. The Let's Encrypt staging check moved to phase 3 (Mark, 2026-11-07). |
| 2 Control plane | Done | Merged to main 2026-11-07 (PR 3): routes repo, journaled apply with trial/watch/revert, undo, restore, share links, API tokens, REST API + OpenAPI, `--dev`. Four QC rounds; every finding fixed or listed in Handover. Real Gitea, systemd credentials and Authelia not exercised. |
| 3 Web UI, PKI, NixOS | Not started | UI design drafted: claude.ai/artifact/GEiCCPcGC1hiCkA2NrrH9u ("murex" palette on the Domi system, approved). Carries the Let's Encrypt staging check, on the first low-risk host beside Caddy. |
| 4 Hardening and release | Not started | Known gaps carried here: see Handover. |
## 10. Handover
(Rewritten at the end of every session: what changed, what was not verified, which build is deployed, the next step.)
**2026-11-07: Phase 2, control plane.**
- **Changed:**
- Phase 2 on branch control/phase-2: crates/control (routes repo through the `git` binary, journaled apply with edge trial reloads, 60 s watch and revert, undo/redo, restore, push with retry, share links, API tokens, REST API with OpenAPI, `--dev`), edge in-process reload over an admin Unix socket, share-link checks and visitor pages in edge, share tokens and the exact `hosts/<hostname>.toml` loader in core.
- docs/api.md (curl examples, run end to end against `--dev`) and docs/ui-api.md (the designer's contract for phase 3, with the deviations listed at its end).
- §8.4 answered with load numbers. Tests: core 86, edge 43, control 42, diff 3 (diff after each of six applies: 0 new differences), testkit 1; hook self-test 55.
- Four QC rounds. Fixed along the way: password-throttle flush, CLI revoke lost to a server write, a pause lost on a full disk (three variants), revocation epoch rollback, Unicode and encoded `..` escapes in share paths, credentials echoed in errors, a port race in the test harness.
- **Deployed:** nothing. The server is unchanged and no nixos-rebuild is needed.
- **Not verified:**
- Push to the real Gitea over HTTPS (askpass) — a local bare repo stood in.
- systemd LoadCredential (a credentials-dir override stood in); a real Authelia (mock only).
- A release build, HTTP/2 clients and websockets across reloads; Pingora graceful upgrade (kept for binary upgrades only, not measured).
- A lost confirm answer from edge is tested only indirectly (edge stopped during the watch, not a late answer).
- Everything from the phase 1 list below that is still open.
- **Known gaps for later phases:**
- Share links work only on Pingora; under the Caddy fallback a visitor gets the normal sign-in (G7, phase 3).
- The "site not reachable" visitor page is not built: it needs a matching Caddy `handle_errors` to keep the diff suite equal.
- The crash and write-failure test hooks (`IANITOR_TEST_CRASH_AT`, `IANITOR_TEST_FAIL_WRITE`) are in the release binary, gated only by environment; move them behind a default feature that the Nix release build turns off. (phase 3)
- Control trusts only API tokens; forwarded `Remote-User` headers get 401 until the UI sign-in is designed (G14, phase 3).
- Edge config is version 2; a phase-1 edge refuses it.
- Workspace `rust-version` is now 1.89 (`File::lock`).
- One open flake: in one full run `apply_sequence` timed out waiting for Caddy on the chunked-body case (Ianitor answered 200). The diff suite alone passed 5/5 afterwards; cause not found.
- **Decided by Mark (2026-11-07):**
- (a) Let's Encrypt staging moves to phase 3, run on the first low-risk host beside Caddy.
- (b) The engine is switched at runtime by control (§3, §4); §1.6 corrected.
- (c) The 4th click for copying an API token and for installing a device certificate is accepted (§4).
- (d) The murex palette is approved; CLAUDE.md now says "dark Domi theme, murex palette".
- (f) The share-link deny list stays a separate file outside git (§3 updated).
- (g) §3 now describes the password as mixed into the MAC, with no hash in the token.
- (h) Phase 2's growth to the UI API contract is accepted (§6 Phase 2 note).
- **Still open:**
- The phase 1 click note also listed "share link on a host with links off" as needing a 4th click; not yet decided.
- (e) Delete the stray build folder F:\pwt, and the merged remote branches docs/bootstrap, core/phase-1 and control/phase-2.
- **Next step:** Phase 3, starting with §8.6 (Custos CSR signing) and the Let's Encrypt staging check.
**2026-11-07: Phase 1, design draft** (kept for its open items).
- **Changed:**
- Phase 1 on branch core/phase-1: workspace, `.githooks/pre-commit`, crates/core (schema and both compilers), crates/edge (Pingora with rustls), tests/diff (60 cases against Caddy 2.11.7), tests/support.
- Reviewed by a separate QC pass, two rounds; every finding fixed or listed below.
- §8 answers 1, 2, 3 and 5 recorded.
- **Deployed:** nothing. The server is unchanged and no nixos-rebuild is needed.
- **Not verified:**
- Let's Encrypt staging; ACME renewal; Caddy's ACME config.
- A real Authelia (mock only).
- HTTPS upstreams against the system roots.
- HTTP/2 client paths; a DNS change while edge runs.
- The hook on bash 3.2 (it refuses to run there).
- **Known gaps for later phases:**
- Slowloris: the header read has no overall deadline; Caddy closes the connection at 60 s, edge keeps it past 90 s. (phase 4)
- Timed-out DNS lookups keep a blocking-pool thread busy until glibc gives up. (phase 4)
- Divergences KD-4 to KD-10 compare status only.
- The plain-HTTP listener answers only the first of pipelined requests.
- The `<hostname>.toml` check looks at the base name only. (phase 2 loader)
- On Windows the Linux-only test targets show "1 passed" (a skip test).
- CLAUDE.md lists packages/ui, tests/fuzz, deploy/nixos, the flake and deploy/test-access.sh, which do not exist yet. (phase 3/4)
- **Needs Mark:**
- (a) Let's Encrypt staging: defer or give a domain.
- (b) §1.6 says an engine change needs a rebuild, but §3 and §4 let control switch engines at runtime. Which one holds?
- (c) §4 click counts: share link with links off, device-cert install and saving an API token each need a 4th click.
- (d) Approve the "murex" palette, and whether CLAUDE.md's "dark Domi theme" wording should change.
- (e) Delete the stray build folder F:\pwt.
- **Next step:** Phase 2, control plane. Resolve §8.4 (graceful reload under load) first.