Runs and levels (core): deploy approvals with domi-approve, the security member, display offers; v0.12.0 #14

Manually merged
mnovak merged 5 commits from feature/runs-core into main 2026-11-04 21:09:34 +01:00
Owner

Core part of "Runs and levels" (Custos docs/11_runs_and_levels.md, sections 3, 4, 5 and the Core row of the test matrix). Release v0.12.0 after review; not tagged.

What

custos-sign: deploy approvals

  • approval_check(text, now_secs) -> Result<Approval, Error>: parses the canonical JSON (v,run,repo,commit,pipeline,version,targets,expires), checks every member, writes it again in canonical form and compares bytes; then the expiry (> now, <= now + 3600). approval_parse(text) is the same without the clock (for filling the audit of a refused or expired request; never used to sign).
  • approval(secret, key_id, text, timestamp, run) -> Result<String, Error>: checks again, requires the JSON's run = run, then the existing prehashed minisign() with file name approval-<run>.json. No new crypto.
  • run_id_ok, Approval::canonical, MAX_APPROVAL (8 KiB), APPROVAL_MAX_AHEAD (3600), Error::Approval(&'static str).

custos-vault: signing

  • SignKind::Approval ("approval"), Request.approval, Request.run, Context.version (skipped when empty), AuditEntry.run (skipped when none).
  • domi-approve (Ed25519, role release, "Domi deploy approval", the release keys' scope) is made by signing_create(Role::Release, …); signing_add_approve(now) adds it to release keys made by an older core.
  • signing_check_at(req, now); signing_check(req) keeps its signature and uses now_ms().
  • Rules: approval only by domi-approve (Ed25519, release), domi-approve signs nothing else; run required and equal to the JSON's; a malformed run on any request is invalid; approval text on another kind is invalid; a non-empty context repo/pipeline/commit/version that differs from the JSON is invalid; scope is checked against the JSON's repo and pipeline.

custos-vault: provision — store display, outcome confirmed. A display is an offer, never accepted/approved/generated/replaced; confirmed only with display. No confirmed-wrong: Custos only sends a code its own check accepted, and does not see the server's exit 10.

custos-vault: security — new body member security (docs/FORMAT.md): Setup window, finished, ticked items, kept scope, append-only audit (newest 5 000). Level computed: Setup for started <= now < until of an unfinished window; else Hardened with any tick; else Standard. Expiry written lazily (setup-expired, finished = until) by the first change after it. Pure rules: accept_all_allowed, replacing_line_preticked, ssh_needs_auth, totp_offer_allowed, hello_for_approvals.

Docs: SIGNING.md (approval kind, domi-approve, canonical form, compatibility), FORMAT.md (security member, display/confirmed, the values older cores refuse).

Deviations from the design, to decide

  1. Rollback claim does not hold for approvals and display offers. Design, Rollback: "A vault saved by 0.7.0 still opens in 0.6.0". True for security, run, version and the domi-approve key (an older core ignores them; tested against a mirror of the 0.11.0 parser). But a signing audit entry of kind approval, or a provision entry with store display / outcome confirmed, is an enum value core 0.11.0 does not know, and it refuses the whole vault (Corrupted), as docs/FORMAT.md already documents for unknown values. So after the first approval request or display offer, a desktop rollback to a 0.11 core cannot open the vault. Tests pin this (an_older_reader_..._but_not_approval_entries, an_older_reader_refuses_display_and_confirmed). Options if that is not acceptable: keep these entries in a member old readers ignore (e.g. signing.audit2), or record them in the security audit instead. Not done here without a decision.
  2. Trusted comment has \thashed. The design writes timestamp:<now>\tfile:approval-<run>.json; reusing the existing minisign path gives …\tfile:approval-<run>.json\thashed, which is what minisign itself writes for a prehashed signature and what our other .minisig files carry. minisign -V and minisign-verify accept it (tested). The hub must not compare the comment literally without \thashed.
  3. "Printable" targets are interpreted as: no control characters and none of U+00AD, U+061C, U+180E, U+200B–U+200F, U+2028–U+202E, U+2060–U+2069, U+FEFF (bidi overrides and zero-width characters could make a target look like another on the card). Length counts Unicode scalar values.
  4. approval(...) returns Result<String, Error> (not String): it re-checks the text and the run.

Adversarial self-review

  • Canonical-form bypasses. serde_json accepts things the canonical form does not (escapes like \u0041, \/, spaces, 1.0, duplicate or unknown keys, leading/trailing whitespace, a trailing newline): each is refused because the text is rewritten and compared byte for byte, and each has a test. deny_unknown_fields and serde's duplicate-field error are a second layer. A quote/backslash in a target round-trips (\", \\). Raw non-ASCII is canonical; the same character via \u is not, so there is exactly one spelling. Size is capped before parsing (8 KiB). Numbers: expires is u64, so negative, float and string forms fail to parse; u64::MAX fails the hour check with saturating_add. Possible gap: a target that is all spaces, or leading/trailing spaces, is allowed (printable); the card shows it literally.
  • Approval scope confusion. A requester could put repo: Arca in the context and repo: Fabrica in the JSON to pass scope: refused, scope uses the JSON, and a differing non-empty context member is invalid. run in the request must equal the JSON's run; the signature names approval-<run>.json. Replay across runs is the hub's check (run, expiry); expiry is at most an hour.
  • Key/kind confusion. domi-approve cannot sign minisign/manifest digests (so it cannot be tricked into signing an installer), and no other key (release, test, code-signing, root) signs approval. A crafted vault with a test-role domi-approve cannot sign approvals (role must be release), so no auto-approval path exists. Approval::Auto on it is refused like any release key.
  • An older reader dropping security. Older cores ignore and, when they save, drop the member: level back to Standard, checklist unticked, audit lost (same model as signing/provision, documented). Dropping makes things less permissive in one way (Setup gone) but unticks hardening, e.g. no-ssh; that is the documented "every Custos that saves must be 0.12.0+".
  • Level at the window boundary. until itself is Standard, until - 1 is Setup, started is Setup, started - 1 is Standard (a clock set back does not give Setup before its start); tested. Restarting while in Setup returns the same window and writes nothing. If the clock goes back below started while a window is open, security_start_setup starts a new window at the earlier time (not an extension in wall time, but worth knowing). security_level/security_view never mutate; expiry is written by the next change only, so a vault that is only read keeps finished empty (level is still right).
  • Unknown values. Unknown item, action, auth, a window with until <= started, finished without setup, a kept-scope prefix that is empty, too long or has control characters: the vault refuses to open (Corrupted); tested by editing the decrypted body and sealing it again. Same strictness as signing/provision, so a future core adding an item makes this core refuse such a vault: the next item needs the same compatibility decision as point 1.
  • Audit. Append-only by API (no edit/remove), trimmed to the newest 5 000 on write and on read. setup-expired is written once because finished is set when it is.
  • Secrets. Nothing in the approval, security or display entries is secret. domi-approve's seed is covered by the existing "no API path returns a private key" test (now 7 keys, with an approval signed). Errors carry static reasons or names (repo/pipeline in out-of-scope messages, as before).
  • Not built here: the wasm32 target (no local wasm toolchain; custos-sign now depends on serde/serde_json, which custos-vault already links in the browser build).

Tests

cargo test --workspace --release: all green.

Crate Before After New
custos-sign 9 21 12 (tests/approval.rs)
custos-vault 51 78 27: signing 7 + 1 unit, provision 2, security 13 + 4 unit

(doc-tests unchanged.) Each new test was first seen failing to compile, then failing an assertion against a stub, except: a_display_offer_is_recorded_as_confirmed_and_survives_a_reopen (the two enum variants are the whole change, so it passed once they compiled), a_vault_that_never_had_setup_is_standard and values_are_spelled_as_docs_format_says (the stub's default and the real types), and the two older-reader tests (the approval key and approval entries; display/confirmed), written after those features as characterization tests of the compatibility in point 1.

Core part of "Runs and levels" (Custos docs/11_runs_and_levels.md, sections 3, 4, 5 and the Core row of the test matrix). Release v0.12.0 after review; not tagged. ## What **custos-sign: deploy approvals** - `approval_check(text, now_secs) -> Result<Approval, Error>`: parses the canonical JSON (`v,run,repo,commit,pipeline,version,targets,expires`), checks every member, writes it again in canonical form and compares bytes; then the expiry (`> now`, `<= now + 3600`). `approval_parse(text)` is the same without the clock (for filling the audit of a refused or expired request; never used to sign). - `approval(secret, key_id, text, timestamp, run) -> Result<String, Error>`: checks again, requires the JSON's run = `run`, then the existing prehashed `minisign()` with file name `approval-<run>.json`. No new crypto. - `run_id_ok`, `Approval::canonical`, `MAX_APPROVAL` (8 KiB), `APPROVAL_MAX_AHEAD` (3600), `Error::Approval(&'static str)`. **custos-vault: signing** - `SignKind::Approval` (`"approval"`), `Request.approval`, `Request.run`, `Context.version` (skipped when empty), `AuditEntry.run` (skipped when none). - `domi-approve` (Ed25519, role release, "Domi deploy approval", the release keys' scope) is made by `signing_create(Role::Release, …)`; `signing_add_approve(now)` adds it to release keys made by an older core. - `signing_check_at(req, now)`; `signing_check(req)` keeps its signature and uses `now_ms()`. - Rules: `approval` only by `domi-approve` (Ed25519, release), `domi-approve` signs nothing else; `run` required and equal to the JSON's; a malformed `run` on any request is `invalid`; `approval` text on another kind is `invalid`; a non-empty context `repo`/`pipeline`/`commit`/`version` that differs from the JSON is `invalid`; scope is checked against the JSON's repo and pipeline. **custos-vault: provision** — store `display`, outcome `confirmed`. A display is an offer, never `accepted`/`approved`/`generated`/`replaced`; `confirmed` only with `display`. No `confirmed-wrong`: Custos only sends a code its own check accepted, and does not see the server's exit 10. **custos-vault: security** — new body member `security` (docs/FORMAT.md): Setup window, `finished`, ticked items, kept scope, append-only audit (newest 5 000). Level computed: Setup for `started <= now < until` of an unfinished window; else Hardened with any tick; else Standard. Expiry written lazily (`setup-expired`, `finished = until`) by the first change after it. Pure rules: `accept_all_allowed`, `replacing_line_preticked`, `ssh_needs_auth`, `totp_offer_allowed`, `hello_for_approvals`. Docs: SIGNING.md (approval kind, domi-approve, canonical form, compatibility), FORMAT.md (security member, display/confirmed, the values older cores refuse). ## Deviations from the design, to decide 1. **Rollback claim does not hold for approvals and display offers.** Design, Rollback: "A vault saved by 0.7.0 still opens in 0.6.0". True for `security`, `run`, `version` and the `domi-approve` key (an older core ignores them; tested against a mirror of the 0.11.0 parser). But a `signing` audit entry of kind `approval`, or a `provision` entry with store `display` / outcome `confirmed`, is an enum value core 0.11.0 does not know, and it refuses the whole vault (`Corrupted`), as docs/FORMAT.md already documents for unknown values. So after the first approval request or display offer, a desktop rollback to a 0.11 core cannot open the vault. Tests pin this (`an_older_reader_..._but_not_approval_entries`, `an_older_reader_refuses_display_and_confirmed`). Options if that is not acceptable: keep these entries in a member old readers ignore (e.g. `signing.audit2`), or record them in the `security` audit instead. Not done here without a decision. 2. **Trusted comment has `\thashed`.** The design writes `timestamp:<now>\tfile:approval-<run>.json`; reusing the existing minisign path gives `…\tfile:approval-<run>.json\thashed`, which is what minisign itself writes for a prehashed signature and what our other `.minisig` files carry. `minisign -V` and minisign-verify accept it (tested). The hub must not compare the comment literally without `\thashed`. 3. **"Printable" targets** are interpreted as: no control characters and none of U+00AD, U+061C, U+180E, U+200B–U+200F, U+2028–U+202E, U+2060–U+2069, U+FEFF (bidi overrides and zero-width characters could make a target look like another on the card). Length counts Unicode scalar values. 4. `approval(...)` returns `Result<String, Error>` (not `String`): it re-checks the text and the run. ## Adversarial self-review - **Canonical-form bypasses.** serde_json accepts things the canonical form does not (escapes like `\u0041`, `\/`, spaces, `1.0`, duplicate or unknown keys, leading/trailing whitespace, a trailing newline): each is refused because the text is rewritten and compared byte for byte, and each has a test. `deny_unknown_fields` and serde's duplicate-field error are a second layer. A quote/backslash in a target round-trips (`\"`, `\\`). Raw non-ASCII is canonical; the same character via `\u` is not, so there is exactly one spelling. Size is capped before parsing (8 KiB). Numbers: `expires` is u64, so negative, float and string forms fail to parse; `u64::MAX` fails the hour check with `saturating_add`. Possible gap: a target that is all spaces, or leading/trailing spaces, is allowed (printable); the card shows it literally. - **Approval scope confusion.** A requester could put `repo: Arca` in the context and `repo: Fabrica` in the JSON to pass scope: refused, scope uses the JSON, and a differing non-empty context member is `invalid`. `run` in the request must equal the JSON's run; the signature names `approval-<run>.json`. Replay across runs is the hub's check (run, expiry); expiry is at most an hour. - **Key/kind confusion.** `domi-approve` cannot sign minisign/manifest digests (so it cannot be tricked into signing an installer), and no other key (release, test, code-signing, root) signs `approval`. A crafted vault with a test-role `domi-approve` cannot sign approvals (role must be release), so no auto-approval path exists. `Approval::Auto` on it is refused like any release key. - **An older reader dropping `security`.** Older cores ignore and, when they save, drop the member: level back to Standard, checklist unticked, audit lost (same model as `signing`/`provision`, documented). Dropping makes things *less* permissive in one way (Setup gone) but unticks hardening, e.g. `no-ssh`; that is the documented "every Custos that saves must be 0.12.0+". - **Level at the window boundary.** `until` itself is Standard, `until - 1` is Setup, `started` is Setup, `started - 1` is Standard (a clock set back does not give Setup before its start); tested. Restarting while in Setup returns the same window and writes nothing. If the clock goes back below `started` while a window is open, `security_start_setup` starts a new window at the earlier time (not an extension in wall time, but worth knowing). `security_level`/`security_view` never mutate; expiry is written by the next change only, so a vault that is only read keeps `finished` empty (level is still right). - **Unknown values.** Unknown item, action, auth, a window with `until <= started`, `finished` without `setup`, a kept-scope prefix that is empty, too long or has control characters: the vault refuses to open (`Corrupted`); tested by editing the decrypted body and sealing it again. Same strictness as `signing`/`provision`, so a future core adding an item makes this core refuse such a vault: the next item needs the same compatibility decision as point 1. - **Audit.** Append-only by API (no edit/remove), trimmed to the newest 5 000 on write and on read. `setup-expired` is written once because `finished` is set when it is. - **Secrets.** Nothing in the approval, security or display entries is secret. `domi-approve`'s seed is covered by the existing "no API path returns a private key" test (now 7 keys, with an approval signed). Errors carry static reasons or names (repo/pipeline in out-of-scope messages, as before). - **Not built here:** the wasm32 target (no local wasm toolchain; custos-sign now depends on serde/serde_json, which custos-vault already links in the browser build). ## Tests `cargo test --workspace --release`: all green. | Crate | Before | After | New | | :-- | --: | --: | --: | | custos-sign | 9 | 21 | 12 (tests/approval.rs) | | custos-vault | 51 | 78 | 27: signing 7 + 1 unit, provision 2, security 13 + 4 unit | (doc-tests unchanged.) Each new test was first seen failing to compile, then failing an assertion against a stub, except: `a_display_offer_is_recorded_as_confirmed_and_survives_a_reopen` (the two enum variants are the whole change, so it passed once they compiled), `a_vault_that_never_had_setup_is_standard` and `values_are_spelled_as_docs_format_says` (the stub's default and the real types), and the two older-reader tests (the approval key and approval entries; display/confirmed), written after those features as characterization tests of the compatibility in point 1.
mnovak added 5 commits 2026-11-04 20:58:03 +01:00
mnovak manually merged commit ac69cf4638 into main 2026-11-04 21:09:34 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/CustosPublic#14