diff options
Diffstat (limited to 'src/pipeline/steps.rs')
| -rw-r--r-- | src/pipeline/steps.rs | 24 |
1 files changed, 24 insertions, 0 deletions
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 |
