diff --git a/RELEASING.md b/RELEASING.md index d515bee..63ee9e5 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -126,7 +126,11 @@ smoke-tests them: `--version` for the macOS binaries, `file` must call the Linux ones static, and with Docker they run in containers (with no network). It then packages into `dist//`, writes `SHA256SUMS`, renders the Homebrew formula from it, and installs the Apple Silicon tarball with -`install.sh` from `dist/` to check that path too. A dry run stops there and +`install.sh` to check that path too. Nothing is signed yet at this point, so +the check signs a copy of `SHA256SUMS` with a throwaway minisign key and runs +a copy of `install.sh` that trusts only that key: the signature check still +runs, and neither the real key nor `install.sh` is involved (without +`minisign` installed, it checks `SHA256SUMS` only). A dry run stops there and prints the `gh` command it would run, without any call to GitHub (`--dry-run` is the default and also wins over `--draft-upload`); `--targets "aarch64-apple-darwin"` narrows a dry run to some targets. Without Rosetta diff --git a/crates/codesmith/tests/release_scripts.rs b/crates/codesmith/tests/release_scripts.rs index d660d6d..037f7ce 100644 --- a/crates/codesmith/tests/release_scripts.rs +++ b/crates/codesmith/tests/release_scripts.rs @@ -1097,6 +1097,87 @@ fn release_sh_writes_the_manifest_the_signing_scripts_check() { assert!(!dist.join("BUILT-SHA256SUMS.tmp").exists()); } +/// Fixed: release.sh's install check ran the real install.sh against the +/// unsigned build, which it refuses, so every release stopped there. It now +/// signs a copy with a throwaway key and runs install.sh trusting only that, +/// so the signature check still runs; a tarball that doesn't match the sums +/// still fails. Needs the real minisign, so it runs only where that is. +#[cfg(all(target_os = "macos", target_arch = "aarch64"))] +#[test] +fn release_sh_install_check_verifies_a_throwaway_signature() { + let minisign = ["/opt/homebrew/bin/minisign", "/usr/local/bin/minisign"] + .into_iter() + .find(|p| Path::new(p).exists()); + let Some(minisign) = minisign else { + return; + }; + if !have_system_tools() { + return; + } + let script = fs::read_to_string(repo_root().join("scripts/release.sh")).unwrap(); + let start = script.find("# >>> install check").unwrap(); + let end = script.find("# <<< install check").unwrap(); + let part = &script[start..end]; + let run = |tamper: bool| { + let dir = tempfile::tempdir().unwrap(); + let repo = dir.path().join("repo"); + let dist = dir.path().join("dist"); + let name = "codesmith-2.0.0-aarch64-apple-darwin"; + fs::create_dir_all(&repo).unwrap(); + fs::create_dir_all(dist.join(name)).unwrap(); + fs::copy(repo_root().join("install.sh"), repo.join("install.sh")).unwrap(); + let bin = dist.join(name).join("codesmith"); + fs::write(&bin, "#!/bin/sh\necho 'codesmith 2.0.0'\n").unwrap(); + fs::set_permissions(&bin, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap(); + let tarball = format!("{name}.tar.gz"); + let ok = Command::new("/usr/bin/tar") + .args(["-czf", &tarball, name]) + .current_dir(&dist) + .status() + .unwrap(); + assert!(ok.success()); + let mut sum = sha256(&dist.join(&tarball)); + if tamper { + sum = "0".repeat(64); + } + fs::write(dist.join("SHA256SUMS"), format!("{sum} {tarball}\n")).unwrap(); + let bin_dir = Path::new(minisign).parent().unwrap(); + let out = Command::new("/bin/sh") + .arg("-c") + .arg(format!( + "set -eu\nsay() {{ printf '== %s\\n' \"$*\" >&2; }}\n\ + die() {{ printf 'release: error: %s\\n' \"$*\" >&2; exit 1; }}\n\ + {part}\nprintf '%s\\n' \"$installed\"" + )) + .current_dir(&repo) + .env("dist", &dist) + .env("version", "2.0.0") + .env("PATH", format!("{}:/usr/bin:/bin", bin_dir.display())) + .env("TMPDIR", dir.path()) + .output() + .unwrap(); + let stderr = String::from_utf8_lossy(&out.stderr).into_owned(); + // The real install.sh and the checkout are untouched. + assert_eq!( + fs::read(repo.join("install.sh")).unwrap(), + fs::read(repo_root().join("install.sh")).unwrap() + ); + assert!(!dist.join("SHA256SUMS.minisig").exists()); + ( + out.status.success(), + String::from_utf8_lossy(&out.stdout).into_owned(), + stderr, + ) + }; + let (ok, stdout, stderr) = run(false); + assert!(ok, "{stderr}"); + assert_eq!(stdout.trim(), "codesmith 2.0.0"); + assert!(stderr.contains("signature ok"), "{stderr}"); + let (ok, _, stderr) = run(true); + assert!(!ok, "a tarball not matching SHA256SUMS installed: {stderr}"); + assert!(stderr.contains("checksum mismatch"), "{stderr}"); +} + // --------------------------------------------------------------------------- // release.sh --draft-upload preflight diff --git a/scripts/release.sh b/scripts/release.sh index b010446..b784bf1 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -297,11 +297,34 @@ fi case " $targets " in *" aarch64-apple-darwin "*) say "install.sh from dist/${version}" - bin_dir=$(mktemp -d) - CODESMITH_VERSION="$version" CODESMITH_BASE_URL="file://${dist}" \ - CODESMITH_INSTALL_DIR="$bin_dir" sh install.sh - check_output aarch64-apple-darwin install.sh "$("${bin_dir}/codesmith" --version)" - rm -rf "$bin_dir" + # >>> install check + # Nothing is signed yet (that happens on the signing Macs), and + # install.sh refuses an unsigned release. So it runs against a copy + # of the files signed with a throwaway key, and a copy of install.sh + # that trusts only that key: the signature check still runs, and the + # real install.sh and release key are untouched. + check_dir=$(mktemp -d) + bin_dir="${check_dir}/bin" + mkdir "${check_dir}/release" "$bin_dir" + cp "${dist}/SHA256SUMS" "${dist}/codesmith-${version}-aarch64-apple-darwin.tar.gz" "${check_dir}/release/" + if command -v minisign >/dev/null 2>&1; then + minisign -G -W -p "${check_dir}/check.pub" -s "${check_dir}/check.key" >/dev/null + minisign -S -s "${check_dir}/check.key" -m "${check_dir}/release/SHA256SUMS" \ + -t "codesmith ${version} SHA256SUMS" >/dev/null + check_key=$(sed -n 2p "${check_dir}/check.pub") + sed "s|^RELEASE_KEYS=.*|RELEASE_KEYS=\"${check_key}\"|" install.sh > "${check_dir}/install.sh" + grep -q "^RELEASE_KEYS=\"${check_key}\"$" "${check_dir}/install.sh" \ + || die "could not point the install.sh copy at the throwaway key" + else + printf ' note: minisign is not installed; install.sh checks SHA256SUMS only\n' >&2 + cp install.sh "${check_dir}/install.sh" + fi + CODESMITH_VERSION="$version" CODESMITH_BASE_URL="file://${check_dir}/release" \ + CODESMITH_INSTALL_DIR="$bin_dir" CODESMITH_NO_PROMPT=1 sh "${check_dir}/install.sh" + installed=$("${bin_dir}/codesmith" --version) + rm -rf "$check_dir" + # <<< install check + check_output aarch64-apple-darwin install.sh "$installed" ;; esac