diff --git a/crates/control/src/api/handlers.rs b/crates/control/src/api/handlers.rs index 88c690b..30ab398 100644 --- a/crates/control/src/api/handlers.rs +++ b/crates/control/src/api/handlers.rs @@ -124,6 +124,41 @@ fn replay(st: &AppState, s: Stored) -> Response { // ---------------------------------------------------------------- overview and hosts +/// What is known to differ on Caddy for these routes (decision Q3: switch allowed, the +/// differences listed). Control cannot run the differential suite at runtime; these are the +/// suite's known differences (tests/diff, KD-*) applied to the hosts that use the feature. +/// Returns (hosts compared, hosts that behave the same, sentences). +pub fn fallback_differences(m: &ianitor_core::Model) -> (u32, u32, Vec) { + let mut out = Vec::new(); + let mut matched = 0u32; + for h in m.hosts() { + let before = out.len(); + if h.share_links { + out.push(format!( + "{}: share links do not work; visitors with a link get the normal sign-in.", + h.hostname + )); + } + if h.auth == ianitor_core::AuthMode::ForwardAuth { + out.push(format!( + "{}: if Authelia's answer is broken or cut off, Pingora refuses the visit; Caddy goes by its status alone.", + h.hostname + )); + } + if out.len() == before { + matched += 1; + } + } + if !m.hosts().is_empty() { + out.push( + "Every host: Caddy adds its own Server and Via headers to answers, and a Content-Type when your service sends none." + .into(), + ); + } + let n = u32::try_from(m.hosts().len()).unwrap_or(u32::MAX); + (n, matched, out) +} + /// Everything the main screen shows, in one call. Answers 304 to a matching If-None-Match. #[utoipa::path(get, path = "/api/v1/overview", tag = "overview", responses((status = 200, body = Overview), (status = 304, description = "Unchanged since the ETag"), (status = 401, body = ErrorEnvelope)), @@ -173,6 +208,9 @@ pub async fn overview( state: r.state.clone(), summary: r.summary.clone(), seconds_left: r.watch.as_ref().map(|w| w.ends.saturating_sub(now())), + kind: r.kind.clone(), + hosts: r.hosts.clone(), + watch_ends_at: r.watch.as_ref().map(|w| rfc3339(w.ends)), queued: c.queued_count(), }); let site = tree @@ -219,9 +257,19 @@ pub async fn overview( running: es.running, target: es.target, switchable: es.switchable, - fallback_ready: Some(FallbackReady { - built_at: caddy_built, - current: caddy_current, + fallback_ready: Some({ + let (compared, matched, differences) = tree + .as_ref() + .and_then(|t| t.model().ok()) + .map(|m| fallback_differences(&m)) + .unwrap_or_default(); + FallbackReady { + built_at: caddy_built, + current: caddy_current, + compared, + matched, + differences, + } }), last_error: es.last_error, notes: es.notes, diff --git a/crates/control/src/api/pki.rs b/crates/control/src/api/pki.rs index 0dfb1d9..d3b57c7 100644 --- a/crates/control/src/api/pki.rs +++ b/crates/control/src/api/pki.rs @@ -79,6 +79,9 @@ pub struct PkiRequestView { pub name: Option, /// Renewals: the request to sign offline (also `GET /pki-requests/{id}/csr`). pub csr_pem: Option, + /// Renewals: SHA-256 of the request (DER, lowercase hex), what + /// `openssl req -in X.csr -outform DER | openssl dgst -sha256` prints on the offline computer. + pub csr_sha256: Option, /// Renewals, once installed: the new intermediate's expiry. pub not_after: Option, /// What to tell the user now (`pki.waiting.manual`, `pki.renew.manual`, `pki.denied`, …). @@ -138,6 +141,11 @@ pub fn request_view(c: &Control, r: &Request) -> PkiRequestView { device_id: r.device_id.clone(), name: r.name.clone(), csr_pem: r.csr_pem.clone(), + csr_sha256: r + .csr_pem + .as_deref() + .and_then(|c| ianitor_core::pki::csr_der(c).ok()) + .map(|d| ianitor_core::pki::sha256_hex(&d)), not_after: r.not_after.map(|t| rfc3339(t.max(0) as u64)), message_code, message: message_text, @@ -247,6 +255,9 @@ pub struct CertsView { pub root: RootView, pub devices: Vec, pub device_lifetime_days: u32, + /// When a device certificate issued now would end: a year, but never past the + /// intermediate's end (decision Q7). None without an intermediate. + pub device_valid_until: Option, pub server_lifetime_days: u32, /// `manual` (on the server, until Custos can) or `custos`. pub approval: String, @@ -283,6 +294,11 @@ pub async fn get_certs(State(st): Shared) -> Result { .map(|d| device_view(d, t)) .collect(), device_lifetime_days: ianitor_core::pki::DEVICE_DAYS, + device_valid_until: p.intermediate_info().map(|i| { + let end = (t as i64 + i64::from(ianitor_core::pki::DEVICE_DAYS) * 86_400) + .min(i.not_after); + rfc3339(end.max(0) as u64) + }), server_lifetime_days: ianitor_core::pki::SERVER_DAYS, approval: c .cfg diff --git a/crates/control/src/api/views.rs b/crates/control/src/api/views.rs index 68f385f..c7e7996 100644 --- a/crates/control/src/api/views.rs +++ b/crates/control/src/api/views.rs @@ -463,6 +463,12 @@ pub struct FallbackReady { pub built_at: Option, /// caddy.json is the compiled current tree. pub current: bool, + /// Hosts in the current routes, and how many of them behave the same on Caddy as far as + /// Ianitor knows (the differential tests' known differences, applied to these hosts). + pub compared: u32, + pub matched: u32, + /// What is different on Caddy, in plain English (per host first, then for every host). + pub differences: Vec, } #[derive(Debug, Clone, Serialize, ToSchema)] @@ -494,6 +500,11 @@ pub struct ActiveApply { pub state: String, pub summary: String, pub seconds_left: Option, + /// `add`, `edit`, `remove`, `undo`, `restore`, `share_links`: the UI writes the heading. + pub kind: String, + pub hosts: Vec, + /// When the health watch ends (only while watching), for a local countdown. + pub watch_ends_at: Option, pub queued: usize, } diff --git a/crates/control/src/crash.rs b/crates/control/src/crash.rs index 34354da..22870d7 100644 --- a/crates/control/src/crash.rs +++ b/crates/control/src/crash.rs @@ -3,7 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. //! Crash points for the crash-safety tests: with `IANITOR_TEST_CRASH_AT=` in its -//! environment, control aborts (no cleanup, like a kill -9) when an apply reaches that stage. +//! environment, control exits at once with status 134 (no cleanup in Ianitor's code, like a +//! kill -9) when an apply reaches that stage. It does not raise SIGABRT: a signal would make +//! the kernel log a register dump per crash test and could hand the process to the host's +//! core-dump handler, and the tests must not reach into the host's systemd. //! //! `IANITOR_TEST_FAIL_WRITE=` makes every write of a state file with that name //! fail, as on a full disk (fault injection for the same tests). @@ -31,8 +34,8 @@ pub const ENABLED: bool = cfg!(feature = "test-hooks"); #[cfg(feature = "test-hooks")] pub fn point(stage: &str) { if std::env::var("IANITOR_TEST_CRASH_AT").as_deref() == Ok(stage) { - log::error!(target: "ianitor::crash", "IANITOR_TEST_CRASH_AT={stage}: aborting on purpose"); - std::process::abort(); + log::error!(target: "ianitor::crash", "IANITOR_TEST_CRASH_AT={stage}: exiting on purpose"); + std::process::exit(134); } } diff --git a/crates/control/src/messages.rs b/crates/control/src/messages.rs index 93c08d6..fe01126 100644 --- a/crates/control/src/messages.rs +++ b/crates/control/src/messages.rs @@ -236,7 +236,7 @@ fn template(code: &str) -> &'static str { "Approve it on the server: run ianitor-control pki approve {code}. Approve only if the code matches." } "pki.renew.manual" => { - "Sign this request on the offline machine (ianitor-control ca sign), check that it shows the code {code}, then install the certificate." + "Sign this request on the offline computer and check that its fingerprint matches (Sign by hand shows both), then install the certificate." } "pki.denied" => "The request was turned down. Nothing was issued.", "pki.expired" => "Nobody approved it in time, so the request closed. Nothing was issued.", diff --git a/crates/control/src/pki.rs b/crates/control/src/pki.rs index 0db9178..a20227a 100644 --- a/crates/control/src/pki.rs +++ b/crates/control/src/pki.rs @@ -410,7 +410,7 @@ impl Pki { } /// The intermediate's public certificate, readable without the password. - fn intermediate_info(&self) -> Option { + pub fn intermediate_info(&self) -> Option { let pem = std::fs::read_to_string(self.dir.join("intermediate.crt")).ok()?; pki::inspect(&pem).ok() } diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index b858ded..ff20460 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -136,7 +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 ` (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). + **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 ` (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, sops-nix secrets, the two trial hosts): [deploy/beside-caddy.md](deploy/beside-caddy.md). **Mark, 2026-11-08:** production runs Authelia, configured outside Configuration_Server, so forward-auth stays (the admin UI host must be behind it; control refuses the ui-proof header on any other host); the trial hosts flowers.stage and esp32.stage on the hyperv-infra mirror are confirmed; and changes keep working while Caddy serves (applies, Undo and Restore are loaded into Caddy through its admin socket, watched through Caddy and reverted by reloading the previous caddy.json; only share links are off). 7. Red Panda Network donation route for a non-US individual and the receipt they issue. (phase 4, Mark) ## 9. Status diff --git a/docs/pki.md b/docs/pki.md index 2e855c2..65d1287 100644 --- a/docs/pki.md +++ b/docs/pki.md @@ -70,11 +70,12 @@ 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-.csr` and + shows the request's SHA-256 fingerprint. **Sign it by hand** downloads `domi-intermediate-.csr` and `domi-intermediate-.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: +2. On the offline machine, check the request (the fingerprint must be the one the UI shows), then sign: ```sh + openssl req -in domi-intermediate-.csr -outform DER | openssl dgst -sha256 openssl req -in domi-intermediate-.csr -noout -subject # CN=Ianitor Domi Intermediate openssl x509 -req -in domi-intermediate-.csr -CA domi-root.crt -CAkey domi-root.key \ -days 365 -sha256 -extfile domi-intermediate-.ext -out domi-intermediate-.crt @@ -84,9 +85,13 @@ offline (and go into Custos once it can hold them). 3. Back on the server: upload the `.crt` in the UI (step 3), or `sudo -u ianitor-control ianitor-control pki install domi-intermediate-.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 +Control checks that the certificate is signed by the configured root, is a CA with path length 0 +and keyUsage keyCertSign + cRLSign, has no extended key usage that would stop it issuing (none, +any, or both server and client auth), is valid now and ends no later than the root, and carries +the pending key; otherwise it refuses (`pki.manual.not_ca`, `pki.manual.eku`, `pki.manual.dates`, +`pki.wrong_key`, `pki.not_our_root`), says why on the request and in `pki install`, and keeps the +request open. Once it passes, control 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 diff --git a/docs/ui-api.md b/docs/ui-api.md index bb920c9..b629129 100644 --- a/docs/ui-api.md +++ b/docs/ui-api.md @@ -526,9 +526,15 @@ Recorded by the Phase 3 implementation (branch `phase-3`); docs/api.md has the c page, its button POSTs the download, so link previews cannot use it up; 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 (never listed in `GET /share-links`). -- **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}`). Changes keep working while Caddy serves (Mark 2026-11-08): they are +- **G18**: `GET/POST /engine` (shape in docs/api.md). Difference from §1.9: control cannot run the + differential suite at runtime, so `fallback_ready {built_at, current, compared, matched, + differences[]}` counts *hosts*, not requests: `compared` hosts in the routes, `matched` those + with none of the suite's known differences (share links, forward-auth edge cases), and + `differences` says what differs in plain English (decision Q3: listed under "Show details"). + `overview.active_apply` also carries `kind`, `hosts` and `watch_ends_at`, so the bar writes the + heading and counts down every second. `GET /certs` has `device_valid_until` (a year, capped at + the intermediate's end, Q7) and renewal requests carry `csr_sha256` (what + `openssl req -in X.csr -outform DER | openssl dgst -sha256` prints). Changes keep working while Caddy serves (Mark 2026-11-08): they are loaded into Caddy and watched through it; only share links are off. - **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