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/INVARIANTS.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docs/INVARIANTS.md (limited to 'docs/INVARIANTS.md') 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