From 12fb09b0ad11c0d9305d606b3b4fced8ba04d385 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 10:16:12 +0000 Subject: I9: the pipeline stops trusting paths the build could have placed, plus README and the invariant index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three things. **A real hole, closed.** `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 generated by our own scan, but their *targets* are not: a PKGBUILD that drops a symlink called `evil.pkg.tar.zst` pointing at the signing keyring, the database, or anyone's home directory would have its target copied in, published and signed by us. The chroot is supposed to be the layer that prevents that, and the chroot tier is gated — but two protection layers must not be load-bearing on each other, and the control plane should not depend on isolation for the safety of its own secrets. `collect` now rejects symlinks and rejects anything whose canonicalized target escapes the build's own staging directory, failing the build closed with the path in the message. `i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir` acts the attack out — the shim plants a symlink to the database file — and asserts the build fails, the store is byte-for-byte untouched, and nothing publishes. This is the last §2 invariant that had no named test; docs/INVARIANTS.md says plainly which part of I9 this covers and which part belongs to the gated chroot tier. **README.md**, written for the person who has to operate this at 3am: the rule everything else follows, the quick start, the layout, how the shim harness makes the whole pipeline testable without root or network, the ops commands, the route table, and the §14 constraints stated as the hard edges they are. **docs/INVARIANTS.md**, mapping I1-I12 to the named tests that hold them, with corroborating tests listed, and an explicit note on the two invariants enforced by the schema (the partial unique index for I7, the append-only triggers for I10/I7) so a future code path cannot forget them. Also recorded in DECISIONS.md: metrics served without a session and why, retention recording a purge instead of deleting the row, and the real-chroot tier being explicitly skipped with what stands in for it and how to actually run it. .gitignore already covered .pi/ but the goal-tracker files were tracked from before the rule existed; untracked now so they stop appearing in every diff. --- README.md | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 README.md (limited to 'README.md') diff --git a/README.md b/README.md new file mode 100644 index 0000000..41ea57e --- /dev/null +++ b/README.md @@ -0,0 +1,156 @@ +# aur-build + +A build server for AUR packages: it watches recipes, shows a human what changed, +and publishes a signed pacman repository containing **only what a human +approved**. One process, no async runtime, no external services. + +The design is in [`DESIGN.md`](DESIGN.md). The invariants it must never violate +are in [`docs/INVARIANTS.md`](docs/INVARIANTS.md), each mapped to a named test. +Judgement calls where the design left an opening are in +[`docs/DECISIONS.md`](docs/DECISIONS.md). + +## The rule everything else follows + +Nothing reaches a consumer without an `approval` row behind it (I1). Every other +behaviour is downstream of that: the review page freezes the exact bytes a human +looked at and hashes them, the approve request must echo both hashes, the build +re-checks the recipe pin and the resolved version before it runs, and publish +refuses if the accepted pointer moved underneath it. + +## Quick start + +```sh +cargo build --release +target/release/aur-build --root /var/lib/aur-build init --repo aur +sudo -u aurbuild target/release/aur-build --root /var/lib/aur-build serve +``` + +Then subscribe and drive a package through once by hand: + +```sh +aur-build subscribe some-pkg +aur-build detect some-pkg # or wait for the watcher +aur-build reviews # candidate ids +aur-build show 12 # the diff panels + the two hashes +aur-build approve 12 --yes # approves exactly what was just rendered +aur-build build 12 # enqueue; the dispatcher picks it up on serve +aur-build packages # what the index is serving +``` + +`serve` runs the watcher, the HTTP UI, the dispatcher and the reaper in one +process. The CLI and the UI drive the same code paths, so anything the web +interface can do, an operator can do from a shell at 3am. + +## Layout + +``` +src/ + main.rs CLI: init, subscribe, detect, reviews, show, approve, reject, + build, rebuild, run, builds, status, packages, serve, audit, + metrics, gc, backup + config.rs one config file at /config.json + db/ SQLite: migrations, model rows, queries, build state machine + mod.rs single writer actor + thread-local read-only readers + watch/ detection: scheduler, cheap/expensive polls, upstream probes, + source digests, staleness derivation + review/ candidates, diff panels, risk scoring, approval + pipeline/ the step machine, the dispatcher + worker pool, publishing + pkgver/ vercmp and the dependency-string grammar + pkginfo.rs .PKGINFO / .BUILDINFO parsing (no libalpm) + http/ tiny_http server: routes, render, auth, SSE log tail + ops.rs retention, metrics, VACUUM INTO backups + shims/ the fake toolchain that makes the pipeline testable +testcorpus/ the fixture packages the tests build for real +templates/ askama templates, server-rendered +static/ app.css and one vendored htmx +docs/ DECISIONS.md, INVARIANTS.md +``` + +## Testing without root, network, or a real chroot + +`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. +* **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` + checksum, a VCS package with a local upstream repo, a downgrade, an epoch bump, + a package with an unsatisfiable dependency. Tests drive the real code against + these rather than against mocks of the code. + +Crash tests are real: `shim_kill_parent` makes a shim `SIGKILL` the pipeline +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. + +Some tests are gated on the host and skip themselves with a printed note rather +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. + +## Operations + +```sh +aur-build metrics # Prometheus text, same as GET /metrics +aur-build gc --keep 3 # evict files beyond the retention window +aur-build gc --keep 3 --dry-run # show what would go +aur-build backup /backups/aur.db # VACUUM INTO; refuses to overwrite +``` + +Retention never deletes a row. An evicted artifact keeps its digest, size and +provenance and gains a `purged_at`, so the database says "these bytes existed and +were dropped at T" instead of continuing to claim a file that is gone. The +currently accepted release and anything still backing an index entry are never +evicted, however old they are. + +Metrics are computed from live state on every scrape — there are no counters +incremented at event sites, because a counter maintained by every code path is a +counter that quietly drifts the first time a code path is added. + +## Web UI + +Server-rendered HTML with at most one vendored JavaScript file (htmx, ~15.6 KB +gzipped on the wire) and no build step. The review surface ships no JavaScript +at all; a test greps the rendered page for `