diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/DECISIONS.md | 511 | ||||
| -rw-r--r-- | docs/INVARIANTS.md | 73 |
2 files changed, 0 insertions, 584 deletions
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md deleted file mode 100644 index 32daa8c..0000000 --- a/docs/DECISIONS.md +++ /dev/null @@ -1,511 +0,0 @@ -# Decisions - -Choices made where DESIGN.md left an opening (§19), or where following the letter -of the design would have been worse than following its intent. Each entry states -the pressure, the choice, and what it costs. - ---- - -## Vendored JavaScript: htmx 1.9.12, served precompressed - -The design budgets "vendored htmx (~14 KB)". Real htmx is not that size: 1.9.12 -is 48 KB minified, and no released build of htmx is under 20 KB. The budget was -an estimate, not a constraint with a reason attached to it, and the reason it -was written — do not let a build step and a JavaScript dependency creep in — is -fully satisfied by vendoring one unmodified upstream file. - -**Choice.** Vendor `htmx.min.js` unmodified, plus a precompressed `.gz` beside -it, and serve the gzip to clients that accept it. The budget is enforced on -**served bytes**, which is what a browser actually downloads: 15.6 KB, asserted -by a test that reads the wire with a bare socket rather than an HTTP client that -would transparently decompress and hide the number. - -**Cost.** Two copies of one file in the repo, and a budget that has to be stated -as "on the wire" rather than "on disk". A reviewer who wants to audit the JS can -read the upstream file; the test asserts the served copy decompresses to it. - -## No JavaScript on the review surface, and no SSE extension - -htmx ships an SSE extension, and the obvious move was to wire the build log -stream into the page with it. Not done, for two reasons: - -- It swaps with `innerHTML`, and a build log is untrusted text produced by a - PKGBUILD someone else wrote. Wiring it up would be an XSS hole opened - specifically to make a log scroll by itself. -- It would add 3 KB gzipped to a budget the base library already nearly spends. - -**Choice.** The review flow ships no JavaScript at all — asserted by a test that -greps the rendered review page for `<script`. The log tail is a real endpoint -(`/builds/:id/log.stream`, server-sent events, tested end to end) and the page -links to it; the builds table refreshes by htmx polling, which degrades to "press -reload". - -## `identity_hash` is a digest, not the canonical JSON - -`Identity::hash()` originally returned the canonical JSON of the identity tuple. -That is an identity token, but it is not a hash, it is large, and it contains -quotes — so it could not survive an HTML attribute round-trip, which is exactly -what the approve form needs (§7.1a requires the form to carry it back). - -**Choice.** `hash()` returns `sha256:<hex of the canonical JSON>`. The JSON stays -internal; the token is what a form can carry and what a comparison can be made -on. - -## The reaper reaps `running`, not only `leased` - -§8.2 writes the reaper as -`UPDATE build SET state='queued' WHERE state='leased' AND lease_expires_at < now()`. -A worker sets `state='running'` the moment it starts a step, so a process that -dies mid-step leaves a `running` row — and following the design literally would -strand every real crash forever. Found by the SIGKILL test in `tests/crash.rs`. - -**Choice.** The reaper matches `state IN ('leased','running')`. - -## Paused subscriptions are not observed at all - -The design has `paused` as a subscription state but does not say what the watcher -does with it. Polling a package nobody will act on wastes requests and keeps -opening reviews nobody will read. - -**Choice.** `check_pkgbase` returns `Outcome::Paused` before it touches the -network. Pausing is a statement that we are not looking. - -## Staleness is computed on read, never stored - -§10.2 asks for this and the code follows it exactly: there is no `stale` column. -A stored flag goes wrong the moment anything else is published, and something else -is always being published. Deriving it from the recorded world snapshots against -the live index means it cannot lie, at the cost of a query per page view. - -## Downgrades are an announcement, not a build request - -When AUR offers a lower version than we serve, nothing should be rebuilt and -nothing should be withdrawn automatically — a human has to decide whether the -mirror or the upstream is wrong. The row appears on Attention with both versions -and no action button. - -## The test hooks are a gated submodule, not fields on `Config` - -`publish_fault`, `shim_fail`, `shim_kill_parent` and their siblings exist only so -the harness can reproduce failures it cannot otherwise cause: a crash between the -rename and the signature, a tool that exits non-zero, and a process killed -mid-step with a signal it cannot catch. The alternative — an in-process -simulation of a crash — can be caught and cleaned up by accident, which is -precisely what I5 must not allow. - -They are no longer seven `Option` fields on the production `Config`, and the -branches that consult them are no longer compiled into the binary at all. Under -the default features there is a `TestHooks` type with no fields, the shims and -their binaries do not exist, and `Config::child_env` exports nothing; the fault -branches in `publish` are `#[cfg]`-ed away rather than guarded by a runtime -`if`. A production binary that carries its own fault injection is a binary in -which someone will eventually ask whether a fault can be triggered from the -network, and the honest answer will be "not today". - -**Cost.** The test harness depends on the crate with `features = ["test-support"]`, -so `cargo test` and `cargo build` compile slightly different libraries — which is -the point, and is why `production_surface.rs` asserts the default build is clean. - -## CAS baseline comes from the candidate, not from the live pointer - -At publish time the compare-and-swap compares against the `base_release_id` -recorded on the candidate, not against `pkgbase.current_accepted_release_id` as -it reads it then. If they differ, someone accepted a newer version while this -build was running, and publishing over it would silently drop a human decision. - -## One publisher lock per process, not a queue - -§8.2 says the publish step goes through the publisher's single-thread channel. -With `max_concurrent_builds > 1` two workers could otherwise interleave the index -rewrite. A `static Mutex` around `publish()` gives the same guarantee with less -machinery; the critical section is the db file rewrite, never a build. The lock -poison is cleared deliberately: atomic publish means a panic cannot have left a -half-written db, so wedging the queue would be worse than continuing. - -There is now exactly one such lock, `REPO_LOCK`, taken at the top of `publish()` -for the whole sequence — file rewrite, signature, index update — and by -`withdraw_package`, which rewrites the same files. There used to be a second one -(`PUBLISH_LOCK`) covering a shorter span inside the first, which gave the -appearance of a second serialization point and would have been the natural place -for the next writer to acquire the wrong one. A test fails if a second lock -guarding the served index appears. - -## The session id is the credential, not a cookie the client controls - -Login used to set `auth=1`, so the secret was the *name* of a cookie and anyone -who could type `Cookie: auth=1` was the reviewer. Sessions are now a map the -server owns — a random sid minted at login, marked authenticated only in the -server's table — and the cookie carries the sid and nothing else. Logging in -rotates the sid, so a session id that a previous identity might have leaked is -useless after a re-login; logging out deletes the entry, so the id stops working -rather than being re-interpreted. - -**Cost.** Sessions are per-process and lost on restart, so a server restart signs -everyone out. For a single-operator tool that is a feature: the same restart that -reloads the binary also revokes every session it was running under. - -## `db/` is a boundary, and the writer does not hand out connections - -Every SQL statement in the crate lives in `db/`. `Writer::call`, `tx` and `send` -are `pub(crate)`, and the raw door the test harness needs exists only under -`test-support`. A module that needs the database asks `db/` for a typed query; -if the query does not exist, writing it is the change to make. - -**Cost.** `db/` is large, and a one-off ad-hoc query now costs a function instead -of a line. That is the trade: the schema's shape is knowable from one directory, -and a grep for a table name finds every reader of it. - -## A stale review and a broken database are different answers - -`approve()` used to return an `Approval` with `id: 0` when the transaction -failed, which the UI then rendered as "someone else got there first" — telling a -reviewer their click lost a race it did not lose, and hiding an I/O error behind -a message that invites them to retry. It returns `Result<Approval, ApproveError>` -now, with `Stale` (the review moved: 409, re-render the current diff) kept apart -from `System` (the database failed: 500, name the cause). `bulk()` answers the -same way, per row. - -## The shims are test-only, and the real `.PKGINFO` parser is the only one - -The publish path used to read a package's name out of the archive with a -simplified parser that the shim harness also had a copy of, which meant -production was tested against a model of the format rather than the format. There -is one parser (`pkginfo::parse_pkginfo`), the shims are behind `test-support`, -and the shim binaries are not built by default. - -## States are enums, and writing one is a compare-and-swap - -`build.state`, `candidate.state`, `step.state`, `release.state` and -`subscription.state` were free text, and `current_state` returned `""` for a -build that did not exist. They are five enums now, parsed at the row boundary — a -state the code does not define is an error, not a default — and every transition -is a conditional update (`WHERE state IN (…)`), so a worker whose lease expired -finds its write refused instead of quietly overwriting the state of the build -somebody else now owns. A zombie finishing a live build is the failure mode this -prevents, and it is silent in the old shape. - -**Cost.** The transition table is real code that has to be kept honest with the -schema, and `failed → running` is legal (I5 says a failed build resumes on its -own row), which is not obvious and is commented where it is defined. - -## A row that cannot be read fails the query - -`filter_map(|r| r.ok())` was used in some queries and not others, so a row that -failed to deserialize was sometimes skipped and sometimes an error — and the -skips were invisible. The policy is now uniform: if a row cannot be read, the -query fails. A silently missing package is worse than a failed page, because the -missing package looks like an absent one. `setting_i64` is the one documented -exception, because a *setting* falling back to its default is the designed -behaviour, not a lost row. - -## Only momentary I/O is transient - -`is_transient` classified every `Io` error as retryable, so ENOSPC and EACCES -were retried with the same backoff as a connection reset — a full disk produced a -build that retried until it gave up, blaming a network that was fine. Retryable -now means the kinds that can genuinely pass on the next attempt: would-block, -timed out, interrupted, broken pipe, connection reset/refused/aborted. - -## The pipeline refuses symlinks in the srcdir, even though a chroot should make that moot - -`collect` scans the build's srcdir for `*.pkg.tar.zst`, and `ingest` copies -whatever those paths resolve to into the content-addressed store — from where -the bytes are served from our repo and signed with our key. The paths are ours -(the scan generates them) but their *targets* are not: a PKGBUILD that drops a -symlink named `evil.pkg.tar.zst` pointing at the signing keyring, the database, -or anyone's home directory would have its target copied in and published. - -**Choice.** `collect` rejects any entry that is a symlink, and any entry whose -canonicalized target escapes the build's own staging directory. The build fails -closed with the path in the message. `tests/invariants.rs::i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir` -acts the attack out through a shim hook rather than arguing it is unlikely. - -**Cost.** A legitimate build that stages a package outside its srcdir and -symlinks it in now fails. That is a build we want to fail: it is telling us the -recipe does something we cannot see the whole of. - -**Why this is not a substitute for the chroot.** I9's real enforcement is -isolation, and that tier is gated. This is the narrower claim that the control -plane does not *depend* on isolation for its own secrets — the layers should not -be load-bearing on each other. - -## Metrics are served without a session - -Everything else in the UI is behind a password. `/metrics` is not, because a -Prometheus scraper has no session to present, and the alternative — teaching the -scraper to log in and hold a cookie — puts a credential in a monitoring config -to protect numbers. - -**Choice.** `/metrics` returns counts only: queue depth, review debt and its age -histogram, build success rate, WAL size, index size, stale counts by reason, -staging usage. No package names, no versions, no audit detail, no paths. The -bind address is loopback by default, which is where that is safe; anyone exposing -it further is exposing their own choice of numbers, not their recipe history. - -**Cost.** A visitor on the host can see how busy the server is. If that ever -matters, the fix is a scrape token, not a session. - -## Retention records a purge instead of deleting the row - -The schema exists so that "which bytes produced this installed package" stays -answerable years later (§11a). Disk cannot be kept forever, so something has to -give, and the honest option is to let the *bytes* go while the *record* stays. - -**Choice.** Eviction deletes the package, signature, build log and cached -sources of releases beyond the keep window — as a unit, because a package whose -log is gone but whose bytes remain is full price for no explanation — and sets -`purged_at` on the release and its artifact rows. The digest and size survive, so -the database says "these bytes existed, hashed to this, and were dropped at T" -rather than continuing to claim a file that is no longer there. Shared -content-addressed files are reference-checked against every *retained* release -first: two releases built from the same source share one cached archive, and -aging one out must not corrupt the other. - -**Cost.** A `purged_at` column on two tables, and a UI that has to say "bytes no -longer held" rather than offering a download that 404s. - -## The real-chroot tier: what was actually run, and where it stopped - -§16a gates the tier that needs root, network and devtools. It was not skipped -for lack of trying; it was run on a host with all three, and here is how far it -got. - -**What passed with the real tools.** Real `gpg` (a generated 2048-bit RSA key) -detached-signed the artifact the pipeline produced, and `gpg --verify` reported a -good signature. Real `repo-add -s -k` built a pacman database over that artifact -and signed it, and that signature verified too. So the claim "both the packages -and the `.db` are signed" is checked against real crypto, not the shim's fake -key. - -**What the attempt caught.** `mkarchroot` has no `-N` flag. The pipeline was -calling `mkarchroot -N <seed>`, which the shim accepted (it ignores unknown -flags) and the real tool rejected with a usage error — so the first real chroot -build would have died on its very first step, in a code path no shim test could -ever have caught. The seed's package list is now configuration -(`mkarchroot_args`, default `base`) and the call follows the real usage, -`mkarchroot <working-dir> <packages...>`. - -**Where it still stops.** `mkarchroot <dir> base` against a live mirror -downloaded and installed the base set into the chroot (437 MB, 14 packages, -install scripts ran), then failed in devtools' init stage with -`Failed to parse --bind(-ro)= argument : Invalid argument` from -`systemd-nspawn` 262, and with `etc/pacman.conf` unreadable inside the root. -That is a devtools/nspawn interaction inside an unprivileged container, not -something this codebase controls. - -**What therefore remains unverified by execution:** `makechrootpkg`'s -copy-on-write snapshot semantics, `systemd-nspawn` isolation behaviour, and GPG -passphrase handling through a real agent. The shim tier drives the *unmodified* -pipeline against fake tools that produce real archives, and the crash tests kill -real processes with real signals, so the step machine, the checkpoints and the -publish path are all exercised for real — it is the chroot boundary itself that -is modelled rather than crossed. - -**How to run it properly.** A privileged Arch host (or a container with the -nspawn capabilities devtools expects), devtools installed, a real signing key, -`signing_key_id` set, `path_prepend` left unset so the real tools are found, then -subscribe to a real pkgbase and drive it through `aur-build serve`. - -## Signing moved from the build step to hub-side ingest - -The build step used to pass `-si<key>` through to `makepkg`, which meant -whatever machine ran the build had to hold the signing key. That was survivable -when the build was a chroot on the hub; it disqualifies every form of remote or -disposable build sandbox, because a machine executing untrusted PKGBUILD code -must never be a machine that can mint our signatures. - -**Choice.** The build produces unsigned bytes. `ingest` signs the exact bytes -that entered the store, with the same key and the same code path that signs the -database (`publish::sign_to`), and a gpg failure fails the build closed. -`verify` no longer checks for a build-made signature — the meaningful guarantee -moved to "ingest produced one or the build failed." The shim `makechrootpkg` -now emits `.sig` only when `-si` is passed, like the real tool, so the suite -cannot accidentally test a signing path the pipeline no longer has. A test -asserts both halves: zero `-si` on any build invocation, and the signature -ingest recorded was made over the stored artifact's bytes. - -**Cost.** The artifact is unsigned between build and ingest — a window that -matters not at all here (staging is hub-local and ingest re-hashes) but must -never be widened by moving ingest off-hub. And a rebuild of a stored artifact -re-signs it with the *current* key, which is correct but worth knowing. - -## The devtools chroot is gone: the sandbox is the isolation boundary - -§8.3 bought isolation with `mkarchroot` + `makechrootpkg`, which costs a sudo -requirement on the build host — and DECISIONS' own real-chroot entry records -that stack failing inside containers anyway (`systemd-nspawn` bind-arg errors). -Once the build runs in a disposable sandbox — a Kata VM, a throwaway container, -the loopback harness — the chroot is scaffolding inside a boundary that already -does the job, and I9 gets *stronger*: the untrusted build never touches the -kernel that runs the hub. - -**Choice.** No `mkarchroot`, no `makechrootpkg`, no nspawn, anywhere in the -pipeline. The build step is plain `makepkg -c -f`: no `-s` (dependencies -arrive installed; resolving them at build time is what the pinning model -forbids) and no `-si` (see the signing entry). The step id stays `chroot` in -the checkpoint table — the DB does not care what the string means, and -renaming would strand every existing checkpoint row. The devtools shims stay -in the test tier as stand-ins for the real tools so the shim protocol itself -remains exercised, but nothing in `src/pipeline` names them. - -**Cost.** The "must build in a clean chroot" folklore has a real tail: some -PKGBUILDs assume `makechrootpkg` conventions (`$PKGDEST`, non-root builder). -A per-build disposable VM bootstrapped from a pinned base is at least as clean -— this is how OBS builds distro packages — but expect the tail to show up in -the gated real-build tier, and budget for `-e` shims there. - -## Dependencies arrive pinned by digest via `pacman -U`, not resolved - -A sandbox that runs `pacman -Sy` at build time re-resolves against live mirrors -*after* `plan()` approved a world — a path from "mirror moved since review" to -"we built it anyway," which is exactly what the fail-closed posture forbids. - -**Choice.** The provisioning step (step id `chroot`) builds a **lease -manifest**: every dependency this build needs that we publish, pinned to the -exact version and digest of the artifact the index serves -(`db::index_artifact`). The hub re-hashes every blob before staging it into -the sandbox, installs with `pacman -U` — no repo DBs, no `Server=`, no mirror -at build time — and the sandbox's own `pacman -Q` must confirm the pinned -world landed, or the build fails closed with a dedicated `WorldMismatch` -error class. Official packages are the base image's business: they arrive -with the sandbox, and hub-side caching of official artifacts (which also -solves mirror-rot and mirror etiquette) is recorded as future work, not -pretended to. - -**Cost.** The lease covers only what we publish; pinning the official set -end-to-end needs the hub's official-repo cache, which is not built. And -`pacman -U` does no dependency resolution — an incomplete closure fails with a -world mismatch rather than being helpfully fetched, which is correct here but -depends on `plan()` computing the closure honestly. The shim `pacman` models -all of this for real: `-U` refuses bytes that do not hash to the digest their -name claims, and `-Q` reports exactly what landed. - -## repo-add names the database; the render happens in scratch space - -Publishing needs the index rendered *before* the DB transaction commits and -renamed into place *after* it, so a crash between the two leaves the old index -serving (I4). The obvious way to get that was to render to `<db>.tar.gz.tmp` -beside the live file and rename over it. That is also a filename real `repo-add` -refuses: its database argument has to be a name pacman would itself accept, and -a trailing `.tmp` is a usage error to it. Every publish test passed and the first -real package anyone tried to publish died at the last step, with the database -already committed and the served index untouched. - -**Choice.** `render_db` renders into a scratch directory *under* the served -directory — `.render-<pid>-<n>-<tag>/` — under the exact name a consumer will -download. Same filesystem, so the caller's `rename` is still the atomic swap I4 -requires, and the live database is never the file repo-add is writing into. The -scratch directory is removed on every path this code controls, and -`reconcile` sweeps leftovers at startup for the paths it does not. `run_repo_add` -also dropped `-s`: repo-add would sign the database into scratch space that is -about to be deleted, and `publish::sign` signs the renamed file — one key, one -code path, signature always over the bytes that shipped. - -**Cost.** Three call sites (`publish`, `reconcile`, `withdraw_package`) now share -the render helper instead of each doing its own tmp-and-rename, and a publish that -dies between render and rename leaves a directory for the next startup to sweep -rather than a single stray `.tmp` for a human to notice. - -## A shim is as strict as the tool it replaces, or it is not a test of it - -The `repo-add` shim wrote the database wherever it was told to. The real tool -validates the filename first. That asymmetry is the whole reason the previous -entry was possible: 200+ tests drove a real subprocess through a real publish and -reported success, because the fake accepted what the real thing rejects. - -**Choice.** The shim enforces the accepted set — `.db.tar` with or without a -compression suffix, nothing else, `.files.*` included in the refusals because -those belong to `repo-files` — with the real tool's wording and exit status. The -set was measured against `repo-add (pacman) 7.1.0`, not read out of its docs, and -`shims::repo_add_db_names_match_the_real_repo_add` re-derives it against the -installed tool whenever there is one, in the shape of the `vercmp` oracle test. -The same rule already holds elsewhere — the `pacman` shim refuses bytes that do -not hash to the digest their name claims — this is that rule, applied where it was -missing. - -**Cost.** The shim now rejects things the pipeline might one day want to do, and -the rejection has to be updated if pacman's rule changes. That is the correct -failure: a shim drifting from its tool should break a test loudly, not let a -production path go untested. -## The root is the directory `config.json` lives in - -`--root` selects a directory and `init` writes `config.json` inside it, so the -root is already named by the location of the config. The `root` field in the file -was treated as a second source of truth: a relative one was re-joined onto the -config's own directory, and `init` saved whatever it had been handed. So -`--root runtime` wrote `"root": "runtime"`, and every command after `init` -resolved that to `runtime/runtime/` — a second tree, with its own empty database, -while `init` had created and migrated the first one. Compounding it, the CLI fell -back to a default config whenever loading failed, so a typo'd `--root` produced a -fresh empty server that answered every command as if it were the real one. - -**Choice.** `Config::load` sets the root to the directory it found the config in, -absolutized; the field in the file is a record for whoever is reading the tree, -and `save` writes it absolute so it stays readable. A missing config is an error -for every command except `init`, which is the only one that runs before one -exists. - -**Cost.** A hand-edited absolute `root` in a config file no longer relocates a -tree — you move the directory and point `--root` at it, which is how the CLI -already worked. And an existing tree that was already split by the doubling keeps -its two databases until someone notices and moves the rows; the fix stops the -bleeding rather than reconstructing what went into the wrong tree. - -## The sandbox backend is a tagged enum, and an unwired kind is an error - -`sandbox_backend` was a string, and `backend_for` matched it with `_ => loopback`. -The design documents a Kata backend, so `sandbox_backend = "kata"` was a -configuration an operator could write in good faith — and it meant "run the -untrusted PKGBUILD as the hub's own user", silently. There was no validation of -any kind in the crate: an empty `agent_token`, a missing listen address, a -half-filled cluster coordinate set, all parsed and failed later as something -else. - -**Choice.** One `sandbox` object, three kinds — `loopback`, `remote`, -`agent-sandbox` — internally tagged, `deny_unknown_fields`, required fields -required by the type rather than by a validation pass someone must remember. -An unknown kind is a parse error naming the value and the valid set; a misspelled -field is named rather than read as absent. `Config::validate` catches what a type -cannot see (a field present but empty) and runs both at startup and wherever a -backend is constructed, so nothing that builds one can skip it. Retired flat keys -are refused when they carry intent — a config saying `"remote"` errors and names -the replacement — while the `"loopback"` plus empty strings that `init` used to -write is noise, not intent, and keeps loading. `agent-sandbox` parses, validates, -and builds a real `KataBackend` over `K8sSandboxProvisioner`; the -containerd/`nerdctl` payload builder is deleted rather than left as a route the -configuration refuses. - -Two consequences of "actually reachable from config" needed fixing on the way. -The agent listener was bound per build, because `Ctx::new` constructed a backend -per build, so a second concurrent build on a fixed `listen` died of `EADDRINUSE` -— the listener is now shared per `(address, token)` for the life of the process, -with the token in the key so two tokens cannot quietly share one. And a Kata -backend cannot share only a listener: it routes dial-ins by nonce into a map of -its own, so two on one address would each see half of them; the whole backend is -shared per configuration instead, keyed by a digest so the token and bearer are -not copied into a second place. - -**Cost.** Existing configs that named a non-loopback backend must be rewritten — -deliberately, because silently reinterpreting them is the bug. And a kind that is -valid but not yet implemented is now a hard error at the first build instead of a -silent downgrade, which is correct but will bite someone mid-rollout. - -## A remote sandbox must be told the workspace is shared - -The workspace is not shipped to a remote sandbox: `Run` frames carry a hub-side -cwd and `build` runs `makepkg` in `ctx.srcdir`. On a hub that shares that path -with the sandbox — the test tier, and any same-host deployment — this works. On -one that does not, it fails obscurely inside `makepkg`. Worse, a misconfiguration -could make a "remote" build succeed on the hub, which is the exact substitution -the whole enum exists to prevent, one layer down. - -**Choice.** Both remote kinds require `"shared_workspace": true`, and the refusal -explains the gap rather than just naming the field. The field defaults to false -rather than being required by the type precisely so the error can say why. -`loopback` needs no assertion because it shares the filesystem by construction. - -**Cost.** This is a guard, not a fix. The real fix is the workspace manifest and -tar sync the design sketches, which touches the wire protocol, `collect`, and the -I9 containment checks; until then a genuinely networked remote deployment is not -possible, and the config now says so at startup instead of letting `makepkg` -discover it. diff --git a/docs/INVARIANTS.md b/docs/INVARIANTS.md deleted file mode 100644 index 80a98aa..0000000 --- a/docs/INVARIANTS.md +++ /dev/null @@ -1,73 +0,0 @@ -# §2 invariants, and the test that holds each one - -Every invariant in DESIGN.md §2 maps to at least one named test. The primary -name is listed first; corroborating tests are listed after it. Run any of them -with `cargo test --test <file> <name>`. - -| # | Invariant | Test | -|---|---|---| -| **I1** | Every artifact in a served index traces to an `approval` row. | `invariants::i1_every_index_entry_traces_back_to_an_approval` · `pipeline::i1_no_index_entry_without_an_approval` · `pipeline::publish_refuses_without_an_approval_behind_it` · `db::i1_query_flags_index_entries_without_approval` | -| **I2** | A review's base is the pkgbase's `current_accepted_release`, not the last detected candidate. | `invariants::i2_base_is_the_last_accepted_version_after_many_detections` · `detect::i2_diff_base_is_the_last_accepted_version_however_many_detections_arrive` | -| **I3** | Candidate identity is content-addressed over everything that becomes a byte. | `invariants::i3_materialization_fails_closed_on_the_recipe_pin` · `detect::epoch_and_pkgrel_are_part_of_the_identity` · `detect::recipe_hash_covers_shipped_patches` · `detect::detection_is_idempotent_and_records_no_duplicate_candidate` · `db::candidate_identity_is_unique_per_pkgbase` | -| **I4** | Publishing is the only externally visible step, and it is atomic and serialized. | `invariants::i4_kill_mid_publish_leaves_the_old_index_byte_identical` · `pipeline::i4_kill_mid_publish_leaves_the_old_index_intact` · `pipeline::a_stale_accepted_pointer_refuses_to_publish` | -| **I5** | Every step is idempotent and checkpointed; a worker can die at any instant. | `invariants::i5_resume_after_a_crash_repeats_no_completed_step` · `pipeline::i5_a_restarted_build_resumes_at_the_next_incomplete_step` · `crash::a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work` · `dispatch::a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work` | -| **I6** | A manual rebuild reuses the approved source identity, with no new approval. | `invariants::i6_manual_rebuild_publishes_the_same_version_without_a_new_approval` · `pipeline::i6_manual_rebuild_reuses_the_approved_identity` · `surfaces::a_manual_rebuild_reuses_the_approved_identity_without_a_new_approval` | -| **I7** | At most one open review per pkgbase; a newer detection collapses into it. | `invariants::i7_the_schema_refuses_a_second_open_review` · `db::i7_second_open_review_is_rejected_by_the_database` · `approve::collapse_in_place_bumps_revision_without_a_new_row` | -| **I8** | The index is exactly the set of `current_accepted_release` pointers. | `invariants::i8_index_equals_the_accepted_pointers` · `pipeline::i8_served_index_holds_exactly_the_accepted_pointers` | -| **I9** | Build hosts are untrusted: a malicious PKGBUILD must not reach the DB, the signing key, or another build. | `invariants::i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir` | -| **I10** | Every state transition is recorded, append-only, with actor and timestamp. | `invariants::i10_audit_is_append_only_and_records_the_decisions` · `db::audit_log_is_append_only` · `surfaces::the_builds_page_names_the_version_and_the_audit_page_records_the_decision` | -| **I11** | A non-publishable change never silently disappears; it becomes a `notice`. | `notices::i11_nothing_publishable_is_ever_silently_dropped` · `detect::recipe_drift_under_a_static_version_is_a_notice_not_a_candidate` · `vcs::a_moved_tip_with_an_unchanged_pkgver_is_a_notice_not_a_candidate` · `notices::digest_drift_is_a_high_severity_integrity_alert_and_no_candidate` | -| **I12** | Every release records the set of our own packages it was built against. | `invariants::i12_every_build_records_a_world_snapshot` · `pipeline::i12_world_snapshot_is_recorded_at_ingest` · `world::the_world_snapshot_is_intersected_with_our_index_at_ingest_time` · `db::world_snapshot_dedupes_by_hash` | - -## What I9 does and does not cover - -The full statement of I9 is enforced by the sandbox: with a remote or kata -backend the build code runs on a machine that holds no database, no mirrors, -and — since signing moved to hub-side ingest — not even the signing key. The -boundary is now a VM, which is stronger than the chroot it replaced. What is -*not* gated, and what -`i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir` pins, -is the pipeline's own hygiene: `collect` scans the srcdir for `*.pkg.tar.zst` -and `ingest` copies whatever those paths resolve to into the content-addressed -store, from where the bytes are served from our repo and signed with our key. A -build that could make one of those paths be a symlink to the keyring or the -database would turn a missing sandbox into a signed artifact of our own secrets. -The test acts that attack out — the shim plants a symlink to the database file — -and asserts the build fails closed, the store is untouched, and nothing -publishes. The provisioning layer adds its own I9-adjacent assertions: staged -blobs are re-hashed by the hub before a sandbox sees them, and a sandbox whose -`pacman -Q` misreports its world fails the build closed -(`failure_modes::an_incomplete_closure_fails_closed_as_a_world_mismatch`). - -## Invariants that are properties of the schema, not of a code path - -Two of these are enforced by SQLite itself so that no future code path can forget -them, and each has a test that tries to violate it through the database rather -than through the application: - -* I7 — a partial unique index on `candidate (pkgbase_id) WHERE state='pending_review'`. -* I10 — `UPDATE`/`DELETE` triggers on `audit`, and on `approval` (§7.2, the - approval record is immutable because it is the only proof of what a human saw). - -## Structural invariants, and the test that holds each one - -The rest of this file is about the twelve numbered invariants, which are claims -about what the system does. The ones below are claims about how the code is -allowed to be shaped — the kind that a review finds once and that a test then -holds forever, because a convention nobody checks erodes back into inconsistency -within a few commits. Each is enforced by a test that reads the source tree and -fails on the shape, not on behaviour. - -| Invariant | Test | -|---|---| -| SQL has one owner: `db/`. No other module holds a statement or touches a rusqlite connection. | `schema_ownership::no_sql_statements_outside_the_db_module` | -| A version string is formatted in exactly one place, `pkgver::full_version` — never again as a `CASE` in SQL. | `schema_ownership::only_rust_formats_a_version` | -| Dependency direction: `db` does not know about `review`/`watch`/`pipeline`; `review` does not call back into the watcher; `watch` does not reach into the pipeline or the UI; `recipe` is a leaf. | `layers::persistence_names_nothing_above_itself` · `layers::review_does_not_call_back_into_the_watcher` · `layers::the_watcher_does_not_reach_into_the_pipeline_or_the_ui` · `layers::the_recipe_leaf_depends_on_nothing_above_it` | -| The five state machines are enums. A row whose state text the code does not define is an error, not an empty string, and a transition the table does not define is refused rather than applied. | `state_machine::the_machine_refuses_a_transition_it_does_not_define` · `state_machine::a_state_the_code_does_not_know_is_an_error_not_an_empty_string` · `state_machine::every_state_round_trips_through_its_column_text` · `state_machine::an_unnamed_state_in_any_row_is_an_error` | -| A worker that lost its lease cannot write over the worker that owns the build. | `state_machine::a_zombie_worker_cannot_finish_a_build_it_no_longer_owns` | -| The production binary contains no test scaffolding: no shim harness, no shim binaries, no ungated fault-injection branch, and a default config with no hooks attached. | `production_surface::no_production_module_references_the_shim_harness` · `production_surface::the_shim_binaries_are_test_only` · `production_surface::the_publish_hot_path_has_no_ungated_test_branch` · `production_surface::a_default_config_has_no_hooks_attached` | -| The served index has exactly one serialization lock, so no second lock can be added that does not know about the first. | `production_surface::the_served_index_has_exactly_one_serialization_lock` | -| The rules a reviewer reads are the same rules the machine scored: no private copies of the host rule, the body-changed rule, or a hand-built audit row. | `production_surface::the_review_modules_do_not_keep_private_copies_of_the_rules` · `production_surface::audit_rows_are_built_by_the_constructors_not_by_hand` | -| `canonical_json` is canonical in fact — key order is a property of the bytes, not of the struct declaration — and a value that cannot be serialized is an error, never an empty object that hashes like a real identity. | `hash::the_rendering_is_canonical_in_fact_not_in_name` · `hash::a_value_that_cannot_be_serialized_is_an_error_not_an_empty_object` | -| The session id is the credential: a cookie a client typed by hand proves nothing, and logging out invalidates the id rather than flipping a bit inside a cookie the client controls. | `http::a_forged_auth_cookie_is_not_a_session` · `http::login_rotates_the_session_and_logout_ends_it` | -| A pinned clock pins everything derived from it, including lease expiry — a test that freezes time must not compute a real-clock deadline. | `time::a_pinned_clock_moves_relative_arithmetic_with_it` · `time::a_lease_taken_under_a_pinned_clock_expires_against_that_clock` | |
