summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs9
-rw-r--r--src/pipeline/steps.rs24
-rw-r--r--src/shims/mod.rs19
3 files changed, 52 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 127c5a3..7effa53 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -59,6 +59,11 @@ pub struct Config {
/// the pipeline, mid-step. This is how a real crash is reproduced for I5 —
/// not a caught error, an uncatchable death. Never set in production.
pub shim_kill_parent: Option<String>,
+ /// Make the build shim plant a symlink to this path in its srcdir, so a test
+ /// can act out the I9 attack: an untrusted PKGBUILD smuggling bytes in from
+ /// outside its own staging dir.
+ #[serde(default)]
+ pub shim_plant_link: Option<String>,
/// How many builds may run at once (§8.2 backpressure). Default 1, which
/// also means the chroot pool only needs one warm root.
pub max_concurrent_builds: usize,
@@ -98,6 +103,7 @@ impl Default for Config {
publish_fault: None,
shim_fail: None,
shim_kill_parent: None,
+ shim_plant_link: None,
max_concurrent_builds: 1,
lease_secs: 90,
min_free_disk_mb: 1024,
@@ -151,6 +157,9 @@ impl Config {
if let Some(k) = &self.shim_kill_parent {
cmd.env("AUR_SHIM_KILL_PARENT", k);
}
+ if let Some(l) = &self.shim_plant_link {
+ cmd.env("AUR_SHIM_PLANT_LINK", l);
+ }
}
/// Create the directory tree the server needs. Idempotent.
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<StepResult> {
.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
diff --git a/src/shims/mod.rs b/src/shims/mod.rs
index 754bbb4..46dd98f 100644
--- a/src/shims/mod.rs
+++ b/src/shims/mod.rs
@@ -291,9 +291,28 @@ pub fn makechrootpkg(args: &[String], m: &Manifest) -> Result<i32, String> {
}
}
}
+ plant_link_if_asked(&startdir);
Ok(0)
}
+/// I9 test hook: drop a symlink into the srcdir pointing wherever the test names,
+/// standing in for a PKGBUILD that tries to smuggle outside bytes into the
+/// artifact store. The pipeline must refuse it; see `collect` in steps.rs.
+fn plant_link_if_asked(startdir: &Path) {
+ let target = match std::env::var("AUR_SHIM_PLANT_LINK") {
+ Ok(t) if !t.is_empty() => t,
+ _ => return,
+ };
+ let link = startdir.join("planted.pkg.tar.zst");
+ #[cfg(unix)]
+ {
+ let _ = std::fs::remove_file(&link);
+ if let Err(e) = std::fs::symlink(&target, &link) {
+ eprintln!("shim: could not plant {link:?} -> {target}: {e}");
+ }
+ }
+}
+
fn packages_to_emit(m: &Manifest, startdir: &Path) -> Vec<FakePackage> {
if !m.packages.is_empty() {
return m.packages.clone();