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. --- src/pipeline/steps.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/pipeline') diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index 3f575bd..db7032c 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -261,7 +261,31 @@ fn collect(ctx: &Ctx) -> Result { .filter(|p| p.to_string_lossy().ends_with(".pkg.tar.zst")) .collect(); entries.sort(); + // I9: the build is untrusted. In production it runs in a chroot, but the + // control plane must not *depend* on that for its own safety. Everything + // below takes a path that a PKGBUILD could have arranged to exist in the + // srcdir, and the next step copies whatever that path points at into the + // content-addressed store — from where it is served from our repo and signed + // with our key. A symlink to the signing keyring, the database, or anyone's + // home directory would otherwise become a signed artifact we publish. So: + // no symlinks, and the resolved target must live inside this build's own + // staging directory. Anything else fails the build closed. + let staging_root = ctx.staging.canonicalize()?; for path in entries { + if std::fs::symlink_metadata(&path).map(|m| m.file_type().is_symlink()).unwrap_or(true) { + return Err(Error::fail_closed(format!( + "{} is a symlink; a build may not smuggle bytes in from outside its own staging dir (I9)", + path.display() + ))); + } + let resolved = path.canonicalize()?; + if !resolved.starts_with(&staging_root) { + return Err(Error::fail_closed(format!( + "{} resolves outside this build's staging dir ({staging_root:?}); refusing to ingest it (I9)", + path.display() + ))); + } + let path = resolved; let bytes = std::fs::read(&path)?; let (digest, size) = crate::hash::digest_file(&path)?; // Read what the package says about itself out of the archive, rather -- cgit v1.2.3