diff options
| -rw-r--r-- | DESIGN.md | 66 | ||||
| -rw-r--r-- | README.md | 35 | ||||
| -rw-r--r-- | docs/DECISIONS.md | 74 | ||||
| -rw-r--r-- | docs/INVARIANTS.md | 20 |
4 files changed, 168 insertions, 27 deletions
@@ -521,14 +521,17 @@ individually confirmed. Bulk approve is per-candidate, never "approve everything 0 materialize git worktree add --detach <builddir> <aur_commit> (local mirror only, no net) recompute recipe_hash; assert == candidate.recipe_hash → fail closed 1 plan resolve deps against current accepted index; compute WorldSnapshot -2 chroot acquire/refresh chroot overlay; install makedepends + depends from our repo +2 provision lease the sandbox; install the pinned lease set (our deps by exact + version+digest) with pacman -U; assert the sandbox's pacman -Q + confirms the approved world landed → fail closed on mismatch 3 sources seed from source_cache, fetch what is missing, then verify against candidate.source_digests (not only the PKGBUILD's declared sums) + PGP 4 pkgver (VCS only) resolve pkgver(); assert == approved pkgver/pkgrel -5 build makechrootpkg -c -r <chroot> -- -si <key> -f +5 build makepkg -c -f in the provisioned sandbox (no -s: deps are installed; + no -si: the sandbox never holds the signing key) 6 collect parse .PKGINFO/.BUILDINFO, extract artifacts + build log -7 verify signature valid, deps satisfiable in target repo, no downgrade -8 ingest move artifacts to content-addressed store, record rows +7 verify deps satisfiable in target repo, no downgrade +8 ingest move artifacts to content-addressed store, sign hub-side, record rows 9 publish repo-add + repo-remove, sign, atomic swap 8 ingest move artifacts to content-addressed store, record rows 9 publish repo-add + repo-remove, sign, atomic swap @@ -596,13 +599,20 @@ reaper (in the dispatcher loop): `UPDATE … WHERE state='queued'` in a `BEGIN IMMEDIATE` transaction is still atomic across processes, so the design survives that split unchanged. -### 8.3 Clean chroot specifics - -* devtools: `mkarchroot` per profile (`extra-x86_64`), one warm root per profile, - per-build CoW snapshot (`makechrootpkg -c`), never mutate the seed. -* The chroot's pacman is configured to trust **only** our repo key + the arch keyring; - `SigLevel = Required DatabaseOptional` inside the chroot so a poisoned mirror can't inject - a build dep. +### 8.3 Clean build environment specifics + +* The sandbox boots from a **base image** we build per profile (`extra-x86_64`), + content-addressed by the world it contains, carrying `base` + `base-devel`, the + arch keyring and our signing key in pacman's keyring, and a pacman.conf with + `SigLevel = Required` and no `Server=` lines: dependencies enter only as + digest-pinned blobs through the lease (§8a), never from a live mirror. +* The provisioning step installs the **lease manifest** — every dependency we + publish, pinned to the exact version and digest the index serves — with + `pacman -U`, and the sandbox's own `pacman -Q` must confirm the pinned world + landed. A byte that hashes differently, or a world that drifted, fails the + build closed (`WorldMismatch`). The devtools chroot (`mkarchroot`, + `makechrootpkg`, nspawn) is gone: the sandbox *is* the isolation boundary, and + the machine boundary makes I9 stronger than a chroot did (DECISIONS.md). * Network: **available during `build()`**, no controls in v1 (decided). Many AUR packages fetch at build time (cargo, npm, go, `pip install` during `build()`), so blocking egress would break a large share of the set. Consequence stated plainly: a `PKGBUILD` can fetch @@ -629,6 +639,40 @@ reaper (in the dispatcher loop): * Flaky test suites: `checkdepends` failures produce a distinct "build ok, check() failed" state with a "retry with --nocheck" action that is itself an explicit, audited decision. +### 8a. Sandbox backends (remote builder) + +Where build code *runs* is a deployment fact, so it is an interface +(`crate::sandbox::SandboxBackend`), not a pipeline fact. The step machine leases +a sandbox (`acquire`), runs argv-shaped commands on it (`run`, streaming output +into the same build log the SSE tail reads), moves content-addressed blobs in +and out (`put`/`get` — there is no "path on the sandbox" concept in the +interface), and destroys it. Three bodies: + +* **loopback** — commands run as subprocesses of the hub, with the §16a shim + protocol applied. This is `cargo test` and the single-machine deployment; the + shim suite passing through it unchanged is what keeps the seam honest. +* **remote** — an ephemeral `sandbox-agent` dials the hub (outbound rendezvous: + the hub never needs a route into an untrusted box), serves `Run`/`Put`/`Get` + frames over length-prefixed JSON, and dies — taking its child with it — when + the connection drops or its TTL expires. A vanished sandbox fails the step, + which is already the shape of an expired lease (I5): the remote path adds no + new failure vocabulary. +* **kata** — ad-hoc, TTL-bounded sandboxes provisioned by an orchestrator + (agent-sandbox-style CR with `runtimeClass: kata` and `activeDeadlineSeconds`, + or `nerdctl` + containerd's kata runtime). `acquire` mints a rendezvous nonce, + provisions, and leases only the dial-in whose hello carries the nonce back; a + box that never dials in is a TTL expiry. A pool that cannot fit a lease is + `PoolExhausted`: the build blocks on `sandbox-pool` using the same blocked + machinery as missing deps (§10.4) — capacity is a fact to wait on, not a + failure to retry. + +The TTL is the guarantee under every leak: hub crash, partition, a forgotten +destroy. Every sandbox is garbage-collected by its deadline, and the hub itself +never needs root — the privileged surface shrank to "nothing on this machine +runs build code at all." Workspace sync over the wire is deliberately not +implemented: `Run` carries a hub-side cwd, honest for loopback-shaped +deployments and the test tier, and the code says so. + --- ## 9. Publishing & serving the index @@ -55,6 +55,8 @@ src/ source digests, staleness derivation review/ candidates, diff panels, risk scoring, approval pipeline/ the step machine, the dispatcher + worker pool, publishing + sandbox/ where build code runs: the backend seam, loopback, remote + agent protocol + agent binary, kata adapter, failure fakes pkgver/ vercmp and the dependency-string grammar pkginfo.rs .PKGINFO / .BUILDINFO parsing (no libalpm) http/ tiny_http server: routes, render, auth, SSE log tail @@ -71,13 +73,17 @@ docs/ DECISIONS.md, INVARIANTS.md `cargo test` runs the whole thing on an ordinary user account. Two mechanisms make that possible (§16a): -* **PATH shims.** `src/bin/` contains `makepkg`, `makechrootpkg`, `mkarchroot`, - `repo-add`, `gpg` and `pacman`. Pointing `path_prepend` at the directory cargo - built them into makes the *unmodified* pipeline drive a fake toolchain: it - still runs real subprocesses, still reads their stdout and exit codes, still - gets real `.pkg.tar.zst` files with real `.PKGINFO` and `.BUILDINFO` inside - them, and still signs them with a fake key. The step machine cannot tell it is - not in a chroot, which is the point. +* **PATH shims.** `src/bin/` contains `makepkg`, `pacman`, `repo-add` and + `gpg` — the tools the pipeline actually shells out to now that builds run + in provisioned sandboxes — plus `mkarchroot` and `makechrootpkg`, kept as + stand-ins for the real devtools so the shim protocol itself stays + exercised. Pointing `path_prepend` at the directory cargo built them into + makes the *unmodified* pipeline drive a fake toolchain: it still runs real + subprocesses, still reads their stdout and exit codes, still gets real + `.pkg.tar.zst` files with real `.PKGINFO` and `.BUILDINFO` inside them, + and the fake `pacman -U` refuses bytes that do not hash to the digest + their name claims. The step machine cannot tell it is not in a sandbox, + which is the point. * **The fixture corpus.** `testcorpus/` holds ~20 synthetic packages, each with a `PKGBUILD` and a manifest describing what the shims should emit: a split pkgbase, a build that fails, a recipe whose payload drifts under a `SKIP` @@ -90,6 +96,15 @@ process mid-step, and a separate test spawns the compiled binary and kills *it*, then asserts a fresh process resumes from the step checkpoints with no duplicate work and the old index still byte-identical. +The sandbox seam (§8a of the design) is tested the same way — the interface is +executed, not mocked: `tests/remote_agent.rs` drives a **full build over the +real agent protocol** (frames, rendezvous, log streaming, blob round-trip, +bad-token refusal) against the shims on a loopback socket, and +`tests/failure_modes.rs` runs a `FakeBackend` that breaks sandboxes on +purpose: dies mid-run (lease expiry → reaper → requeue), TTL bites mid-build, +pool at quota (the build blocks on `sandbox-pool`, it does not fail), and a +sandbox whose `pacman -Q` lies (fail-closed world mismatch). + All of it is behind a `test-support` feature, which `cargo test` turns on through its dev-dependency on this crate and `cargo build` does not turn on at all: the shim binaries are not built, the `TestHooks` type has no fields, and the @@ -101,8 +116,10 @@ than failing: * `versions::vercmp_matches_the_system_oracle` needs pacman's `vercmp` on `PATH` and compares the hand-written comparator against it over ~1100 pairs. -* The real-chroot tier needs root, network and devtools. It is recorded as - skipped in `docs/DECISIONS.md` rather than silently absent. +* The live kata tier needs `/dev/kvm` and a cluster (`AUR_KATA_API`); the kata + rendezvous and TTL logic itself runs everywhere via a real `sandbox-agent` + process with no VM. The old real-chroot tier retired with devtools; what it + caught is recorded in `docs/DECISIONS.md` rather than silently absent. ## Operations diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 68f1fee..2861fed 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -305,3 +305,77 @@ is modelled rather than crossed. 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. diff --git a/docs/INVARIANTS.md b/docs/INVARIANTS.md index c148961..80a98aa 100644 --- a/docs/INVARIANTS.md +++ b/docs/INVARIANTS.md @@ -21,17 +21,23 @@ with `cargo test --test <file> <name>`. ## What I9 does and does not cover -The full statement of I9 is enforced by the chroot, and the chroot tier is gated -behind root and network (§16a). 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 +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 chroot into a signed artifact of our own secrets. +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. +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 |
