summaryrefslogtreecommitdiffstats
path: root/tests/invariants.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 10:16:12 +0000
committeraur-build <aur-build@localhost>2026-11-18 10:16:12 +0000
commit12fb09b0ad11c0d9305d606b3b4fced8ba04d385 (patch)
treee33d6c974a4c31c01262ebec902c6c853152188b /tests/invariants.rs
parentbc63622a1a91f6e1036eb8e6824c04f922e2654e (diff)
downloadaur-build-12fb09b0ad11c0d9305d606b3b4fced8ba04d385.tar.gz
aur-build-12fb09b0ad11c0d9305d606b3b4fced8ba04d385.zip
I9: the pipeline stops trusting paths the build could have placed, plus README and the invariant index
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.
Diffstat (limited to 'tests/invariants.rs')
-rw-r--r--tests/invariants.rs65
1 files changed, 64 insertions, 1 deletions
diff --git a/tests/invariants.rs b/tests/invariants.rs
index c1a70ad..2bdbc8b 100644
--- a/tests/invariants.rs
+++ b/tests/invariants.rs
@@ -10,7 +10,7 @@
mod common;
-use aur_build::db::{self, model::*};
+use aur_build::db::{self, builds, model::*};
use aur_build::pipeline::{self, publish};
use aur_build::review::approve::approve as do_approve;
use aur_build::review::{candidates, diff};
@@ -394,3 +394,66 @@ fn index_db_names(path: &std::path::Path) -> Vec<String> {
names.dedup();
names
}
+
+/// I9: build hosts are treated as untrusted — a malicious PKGBUILD must not
+/// reach the control plane's data or smuggle foreign bytes into what we publish.
+///
+/// The real enforcement is the chroot, and that tier is gated. What is *not*
+/// gated, and what this pins, is the pipeline's own hygiene: `collect` scans the
+/// srcdir for `*.pkg.tar.zst` and `ingest` copies whatever those paths point at
+/// into the content-addressed store, from where the bytes are served from our
+/// repo and signed with our key. If a build could make one of those paths be a
+/// symlink to the signing keyring or the database, isolation would be the only
+/// thing standing between a hostile AUR recipe and a signed artifact of our own
+/// secret files. It must not be. So the pipeline refuses symlinks and refuses
+/// anything that resolves outside the build's own staging directory, and this
+/// test acts the attack out rather than arguing it away.
+#[test]
+fn i9_a_build_cannot_smuggle_bytes_in_from_outside_its_own_staging_dir() {
+ let (mut env, _fx) = env_with_fixture("plain-make");
+ aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, "plain-make").unwrap();
+ let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
+ let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
+ let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
+ do_approve(&env.db, "t", c.id, &c.identity_hash, &dd, None).unwrap();
+ let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
+ let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
+
+ // Something a build must never get to publish: our own database file.
+ let secret = env.cfg.db_path();
+ let store_before = dir_listing(&env.cfg.store_dir());
+ env.cfg.shim_plant_link = Some(secret.display().to_string());
+
+ let out = pipeline::run(&env.cfg, &env.db, &id);
+ env.cfg.shim_plant_link = None;
+ let err = match out {
+ Err(e) => e.to_string(),
+ other => panic!("a build that smuggled in a symlink must fail closed, got {other:?}"),
+ };
+ assert!(
+ err.contains("staging") || err.contains("symlink"),
+ "the failure should say why it refused: {err}"
+ );
+
+ // The refused bytes never reached the store, and nothing was published.
+ assert_eq!(
+ dir_listing(&env.cfg.store_dir()),
+ store_before,
+ "the store must be untouched by a refused build"
+ );
+ assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, build_state::FAILED);
+ assert!(db::index_version(&env.db, "plain-make").unwrap().is_none(), "nothing publishes from a failed build");
+ // And the database itself is intact — the build read it, it did not become it.
+ assert!(secret.exists());
+}
+
+fn dir_listing(dir: &std::path::Path) -> Vec<String> {
+ let mut out = Vec::new();
+ if let Ok(entries) = std::fs::read_dir(dir) {
+ for e in entries.flatten() {
+ out.push(e.path().display().to_string());
+ }
+ }
+ out.sort();
+ out
+}