diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/invariants.rs | 65 |
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 +} |
