summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 22:45:28 +0000
committeraur-build <aur-build@localhost>2026-11-18 22:45:28 +0000
commit99ad2034be8fc5b107205199e19da831596a6791 (patch)
tree8b49bd4f72101a21fbf5924d0ad5bb8c4b07476c
parent632a08c8543f0db533efc7bfb6728b50a77ae3d8 (diff)
downloadaur-build-99ad2034be8fc5b107205199e19da831596a6791.tar.gz
aur-build-99ad2034be8fc5b107205199e19da831596a6791.zip
pipeline: signing moves from the build step to hub-side ingest
The build step used to pass -si<key> 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.
-rw-r--r--src/pipeline/publish.rs16
-rw-r--r--src/pipeline/steps.rs29
-rw-r--r--src/shims/mod.rs9
-rw-r--r--tests/pipeline.rs33
4 files changed, 69 insertions, 18 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());
}
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<i32, String> {
Ok(0)
}
-/// `makechrootpkg -c -r <chroot> -- -si<key> -f`, run with cwd = the build dir.
+/// `makechrootpkg -c -r <chroot> -- -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<i32, String> {
));
}
let pkgs = packages_to_emit(m, &startdir);
+ // Sign only when the caller asked for it, like the real tool: signing is
+ // `-si<key>`/`-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));
diff --git a/tests/pipeline.rs b/tests/pipeline.rs
index 59a1b35..878c193 100644
--- a/tests/pipeline.rs
+++ b/tests/pipeline.rs
@@ -85,6 +85,39 @@ fn end_to_end_publishes_a_signed_index() {
}
#[test]
+fn the_build_never_signs_ingest_does() {
+ // Signing moved hub-side: the build environment is a sandbox that must
+ // never hold the key, so the build command carries no `-si` and the
+ // signature over each artifact is made at ingest by the hub's own gpg.
+ // This is the property that makes a remote build sandbox safe to run at
+ // all — worst the sandbox ever returns is unsigned bytes.
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ assert!(matches!(run_for(&env, &c), pipeline::Outcome::Succeeded { .. }));
+
+ let shimlog = env.cfg.hooks.shim_dir.clone().unwrap();
+ assert_eq!(
+ aur_build::shims::called_with(&shimlog, "makechrootpkg", "-si"),
+ 0,
+ "the build step must not hand a signing key to the sandbox"
+ );
+
+ let (digest, sig_path): (String, Option<String>) = env
+ .db
+ .read(|c| {
+ Ok(c.prepare("SELECT digest, signature_path FROM artifact LIMIT 1")?
+ .query_row([], |r| Ok((r.get(0)?, r.get(1)?)))?)
+ })
+ .unwrap();
+ assert!(sig_path.is_some(), "ingest must record a signature for the artifact");
+ assert!(std::path::Path::new(sig_path.as_ref().unwrap()).exists());
+ assert!(
+ aur_build::shims::called_with(&shimlog, "gpg", &digest) > 0,
+ "the signature ingest recorded was made over the stored artifact's bytes"
+ );
+}
+
+#[test]
fn i1_no_index_entry_without_an_approval() {
let (env, _fx) = env_with_fixture("plain-make");
let c = approve_fixture(&env, "plain-make");