diff options
Diffstat (limited to 'src/pipeline')
| -rw-r--r-- | src/pipeline/publish.rs | 16 | ||||
| -rw-r--r-- | src/pipeline/steps.rs | 29 |
2 files changed, 29 insertions, 16 deletions
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 @@ -308,10 +308,22 @@ 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<StepResult> { Ok(StepResult::Done(Some(text))) } -/// Step 5 — `makechrootpkg -c -r <chroot> -- -si<key> -f`, with the log going to -/// the file the SSE tail reads. +/// Step 5 — `makechrootpkg -c -r <chroot> -- -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<StepResult> { 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<StepResult> { 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<StepResult> { 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<StepResult> { 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()); } |
