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. --- docs/DECISIONS.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/INVARIANTS.md | 44 +++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 docs/INVARIANTS.md (limited to 'docs') diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index c681c05..76c46c7 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -107,3 +107,79 @@ 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. + +## 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 integration tier is recorded as skipped, not silently absent + +§16a gates the tier that needs root, network and devtools. On this host the +tier was not run: it requires a privileged Arch chroot (`mkarchroot` over the +real mirror database), a signing key with a real passphrase, and outbound +network to the AUR, none of which the environment provides. + +**What stands in its place.** The shim tier drives the *unmodified* pipeline +against fake tools that produce real archives, and the crash tests kill real +processes with real signals. The parts the gated tier would exercise that the +shims cannot: `mkarchroot`'s actual root construction, `makechrootpkg`'s +copy-on-write snapshot semantics, GPG's passphrase handling, and the behaviour +of a PKGBUILD that escapes its sandbox in ways a symlink does not capture. + +**How to run it.** Install devtools, create a signing key, set `signing_key_id` +and leave `path_prepend` unset so the real tools are found on `PATH`, then +subscribe to a real pkgbase and drive it through `aur-build serve`. diff --git a/docs/INVARIANTS.md b/docs/INVARIANTS.md new file mode 100644 index 0000000..3e9c7ae --- /dev/null +++ b/docs/INVARIANTS.md @@ -0,0 +1,44 @@ +# §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 `. + +| # | 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 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 +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. +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. + +## 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). -- cgit v1.2.3