From 99ad2034be8fc5b107205199e19da831596a6791 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 22:45:28 +0000 Subject: pipeline: signing moves from the build step to hub-side ingest The build step used to pass -si through makechrootpkg, which meant whatever machine ran the build had to hold the signing key - fine for a chroot on the hub, disqualifying for a remote sandbox. The build now produces unsigned bytes; ingest signs the exact bytes that entered the store, with the same key and code path that signs the database, and a gpg failure fails the build closed. verify() no longer checks for a build-made signature: the meaningful guarantee moved to 'ingest produced one or the build failed'. The shim makechrootpkg now only emits .sig when -si is passed, like the real tool, so the suite cannot accidentally test a signing path that no longer exists. --- src/pipeline/publish.rs | 16 ++++++++++++++-- src/pipeline/steps.rs | 29 +++++++++++++++-------------- src/shims/mod.rs | 9 +++++++-- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs index 94fc46f..fd2fdd1 100644 --- a/src/pipeline/publish.rs +++ b/src/pipeline/publish.rs @@ -305,13 +305,25 @@ fn run_repo_add(cfg: &Config, db_path: &Path, pkgs: &[PathBuf]) -> Result<()> { } fn sign(cfg: &Config, path: &Path) -> Result<()> { + if cfg.signing_key_id.is_empty() { + return Ok(()); + } + let sig = format!("{}.sig", path.display()); + sign_to(cfg, path, Path::new(&sig)) +} + +/// `gpg --detach-sign` over `path`, written to `sig_out` atomically. Shared by +/// publish (the database) and ingest (the packages): one key, one code path, +/// and the key never leaves the hub — a build sandbox signs nothing (§8, +/// remote-builder design). +pub(crate) fn sign_to(cfg: &Config, path: &Path, sig_out: &Path) -> Result<()> { if cfg.signing_key_id.is_empty() { return Ok(()); } let mut cmd = Command::new(&cfg.gpg_bin); cmd.args(["--batch", "--yes", "--detach-sign", "--local-user", &cfg.signing_key_id]); cmd.arg("-o"); - let tmp = format!("{}.tmp", path.display()); + let tmp = format!("{}.tmp", sig_out.display()); cmd.arg(&tmp); cmd.arg(path); cfg.child_env(&mut cmd); @@ -322,7 +334,7 @@ fn sign(cfg: &Config, path: &Path) -> Result<()> { detail: String::from_utf8_lossy(&out.stderr).into_owned(), }); } - std::fs::rename(&tmp, format!("{}.sig", path.display()))?; + std::fs::rename(&tmp, sig_out)?; Ok(()) } diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index 98089ca..89c01f2 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -211,21 +211,19 @@ fn pkgver(ctx: &Ctx) -> Result { Ok(StepResult::Done(Some(text))) } -/// Step 5 — `makechrootpkg -c -r -- -si -f`, with the log going to -/// the file the SSE tail reads. +/// Step 5 — `makechrootpkg -c -r -- -f`, with the log going to the +/// file the SSE tail reads. No `-si`: the build environment never holds the +/// signing key — packages are signed hub-side at ingest. fn build(ctx: &Ctx) -> Result { let seed = ctx.cfg.chroot_seed(&ctx.profile); - let mut argv = vec![ + let argv = vec![ ctx.cfg.makechrootpkg_bin.clone(), "-c".into(), "-r".into(), seed.display().to_string(), "--".into(), + "-f".into(), ]; - if !ctx.cfg.signing_key_id.is_empty() { - argv.push(format!("-si{}", ctx.cfg.signing_key_id)); - } - argv.push("-f".into()); // Capture the child's output into the build log regardless of outcome — // the sandbox streams it here as it arrives, and the SSE tail reads the // same file. @@ -335,14 +333,13 @@ fn collect(ctx: &Ctx) -> Result { Ok(StepResult::Done(Some(crate::hash::hex_str(&serde_json::to_string(&pkgs)?)))) } -/// Step 7 — signature present, dependencies satisfiable, no downgrade. +/// Step 7 — dependencies satisfiable, no downgrade. Signature checking is not +/// here: the build no longer signs (the sandbox never sees the key), so the +/// signature is made at ingest, after these checks pass. fn verify(ctx: &Ctx) -> Result { let collect = Collect::load(&ctx.collect_path)?; let ours = db::our_package_names(&ctx.db)?; for p in &collect.packages { - if p.signature_path.is_none() && !ctx.cfg.signing_key_id.is_empty() { - return Err(Error::fail_closed(format!("{} has no signature", p.name))); - } if crate::pkgver::is_downgrade( &db::index_version(&ctx.db, &p.name)?.unwrap_or_else(|| "0".into()), &p.version, @@ -381,10 +378,14 @@ fn ingest(ctx: &Ctx) -> Result { std::fs::copy(from, &dest)?; } p.path = dest.display().to_string(); - if let Some(sig) = p.signature_path.clone() { + // Hub-side signing: the build environment never holds the key, so the + // signature is made here, over the exact bytes that just entered the + // store, by the same key that signs the database. A gpg failure fails + // the build closed — an unsigned artifact never reaches the repo. + if !ctx.cfg.signing_key_id.is_empty() { let sigdest = ctx.cfg.store_path(&format!("{}-sig", p.digest)); - if !sigdest.exists() && Path::new(&sig).exists() { - std::fs::copy(&sig, &sigdest)?; + if !sigdest.exists() { + crate::pipeline::publish::sign_to(&ctx.cfg, Path::new(&p.path), &sigdest)?; } p.signature_path = Some(sigdest.display().to_string()); } diff --git a/src/shims/mod.rs b/src/shims/mod.rs index a34cf7d..c1b169c 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -247,7 +247,7 @@ pub fn mkarchroot(args: &[String]) -> Result { Ok(0) } -/// `makechrootpkg -c -r -- -si -f`, run with cwd = the build dir. +/// `makechrootpkg -c -r -- -f`, run with cwd = the build dir. /// /// Emits one `.pkg.tar.zst` per package in the manifest into the current /// directory, exactly where the real tool leaves them. @@ -281,10 +281,15 @@ pub fn makechrootpkg(args: &[String], m: &Manifest) -> Result { )); } let pkgs = packages_to_emit(m, &startdir); + // Sign only when the caller asked for it, like the real tool: signing is + // `-si`/`-i`, and the pipeline stopped passing it when signing moved + // hub-side to ingest. A shim that signed anyway would hide that move from + // every test in the suite. + let wants_sig = args.iter().any(|a| a.starts_with("-si") || a == "-i" || a == "--sign"); for p in &pkgs { let path = write_package(&startdir, p, m)?; println!("==> Creating package '{}'", path.file_name().unwrap().to_string_lossy()); - if m.sig { + if m.sig && wants_sig { if let Ok(bytes) = std::fs::read(&path) { let sig = path.with_extension("pkg.tar.zst.sig"); let _ = std::fs::write(&sig, fake_sig(&bytes)); -- cgit v1.2.3