diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml index 70a3d4070..a898d567a 100644 --- a/.github/workflows/launcher.yml +++ b/.github/workflows/launcher.yml @@ -218,13 +218,49 @@ jobs: path: launcher/out/* retention-days: 3 - release: + sign: needs: [decide, build] runs-on: ubuntu-latest - timeout-minutes: 15 - # The signing key is a secret of the `release` environment (docs/security.md), which only main's real releases - # enter; a dry run signs with a throwaway key. + timeout-minutes: 10 + # The only job that holds the release signing key, a secret of the `release` environment, which only main's real + # releases enter (dry runs sign with a throwaway key). It runs no code from the repository but + # tools/ci/sign_release.sh, which calls only the runner's sha256sum and OpenSSL (docs/release-flow.md). environment: ${{ needs.decide.outputs.dry_run != 'true' && 'release' || '' }} + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: tools/ci/sign_release.sh + sparse-checkout-cone-mode: false + persist-credentials: false + - uses: actions/download-artifact@v4 + with: + path: dist + pattern: horizon-launcher-* + merge-multiple: true + - name: Sign the checksums (SHA256SUMS, SHA256SUMS.sig) + env: + RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }} + RELEASE_SIGNING_KEY_NEXT: ${{ secrets.RELEASE_SIGNING_KEY_NEXT }} + EPHEMERAL: ${{ needs.decide.outputs.dry_run == 'true' && 'yes' || '' }} + TAG: ${{ needs.decide.outputs.tag }} + run: bash tools/ci/sign_release.sh "$TAG" dist/horizon-launcher-* + - uses: actions/upload-artifact@v4 + with: + name: signature + path: dist/SHA256SUMS* + if-no-files-found: error + retention-days: 3 + - uses: actions/upload-artifact@v4 + if: needs.decide.outputs.dry_run == 'true' + with: + name: ephemeral.pub + path: dist/ephemeral.pub + retention-days: 3 + + release: + needs: [decide, build, sign] + runs-on: ubuntu-latest + timeout-minutes: 15 permissions: contents: write steps: @@ -242,13 +278,13 @@ jobs: with: path: dist merge-multiple: true - - name: Sign the checksums (SHA256SUMS, SHA256SUMS.sig), checked as the launcher checks them + - name: The signature, checked as launchers check it env: - RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }} - RELEASE_SIGNING_KEY_NEXT: ${{ secrets.RELEASE_SIGNING_KEY_NEXT }} TAG: ${{ needs.decide.outputs.tag }} EPHEMERAL: ${{ needs.decide.outputs.dry_run == 'true' && 'yes' || '' }} - run: cargo run --locked --quiet -p horizon-release-sign -- sign --tag "$TAG" ${EPHEMERAL:+--ephemeral} dist/horizon-launcher-* + run: | + key=(); [[ -n "$EPHEMERAL" ]] && key=(--key "$(cat dist/ephemeral.pub)") + cargo run --locked --quiet -p horizon-release-sign -- verify --tag "$TAG" --publishing "${key[@]}" dist # Never marked latest: Horizon's own releases stay the repository's latest. - name: Publish ${{ needs.decide.outputs.tag }} if: needs.decide.outputs.dry_run != 'true' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b30fa6663..b774ae7c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -217,13 +217,50 @@ jobs: if-no-files-found: error retention-days: 3 - publish: + sign: needs: [decide, build] runs-on: ubuntu-latest - timeout-minutes: 15 - # The signing key is a secret of the `release` environment (docs/security.md), which only main's real releases - # enter; a dry run signs with a throwaway key. + timeout-minutes: 10 + # The only job that holds the release signing key, a secret of the `release` environment, which only main's real + # releases enter (dry runs sign with a throwaway key). It runs no code from the repository but + # tools/ci/sign_release.sh, which calls only the runner's sha256sum and OpenSSL (docs/release-flow.md). environment: ${{ needs.decide.outputs.dry_run != 'true' && 'release' || '' }} + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: tools/ci/sign_release.sh + sparse-checkout-cone-mode: false + persist-credentials: false + - uses: actions/download-artifact@v4 + with: + path: dist + pattern: horizon-* + merge-multiple: true + - name: Sign the checksums (SHA256SUMS, SHA256SUMS.sig) + env: + RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }} + RELEASE_SIGNING_KEY_NEXT: ${{ secrets.RELEASE_SIGNING_KEY_NEXT }} + EPHEMERAL: ${{ needs.decide.outputs.dry_run == 'true' && 'yes' || '' }} + TAG: ${{ needs.decide.outputs.tag }} + run: bash tools/ci/sign_release.sh "$TAG" dist/horizon-linux-x86_64.tar.gz dist/horizon-windows-x64.zip \ + dist/horizon-macos-arm64.zip dist/horizon-server-linux-x86_64.tar.gz + - uses: actions/upload-artifact@v4 + with: + name: signature + path: dist/SHA256SUMS* + if-no-files-found: error + retention-days: 3 + - uses: actions/upload-artifact@v4 + if: needs.decide.outputs.dry_run == 'true' + with: + name: ephemeral.pub + path: dist/ephemeral.pub + retention-days: 3 + + publish: + needs: [decide, build, sign] + runs-on: ubuntu-latest + timeout-minutes: 15 permissions: contents: write steps: @@ -241,16 +278,13 @@ jobs: with: path: dist merge-multiple: true - - name: Sign the checksums (SHA256SUMS, SHA256SUMS.sig), checked as the launcher checks them + - name: The signature, checked as launchers check it env: - RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }} - RELEASE_SIGNING_KEY_NEXT: ${{ secrets.RELEASE_SIGNING_KEY_NEXT }} TAG: ${{ needs.decide.outputs.tag }} EPHEMERAL: ${{ needs.decide.outputs.dry_run == 'true' && 'yes' || '' }} run: | - cargo run --locked --quiet -p horizon-release-sign -- sign --tag "$TAG" ${EPHEMERAL:+--ephemeral} \ - dist/horizon-linux-x86_64.tar.gz dist/horizon-windows-x64.zip dist/horizon-macos-arm64.zip \ - dist/horizon-server-linux-x86_64.tar.gz + key=(); [[ -n "$EPHEMERAL" ]] && key=(--key "$(cat dist/ephemeral.pub)") + cargo run --locked --quiet -p horizon-release-sign -- verify --tag "$TAG" --publishing "${key[@]}" dist - name: Publish ${{ needs.decide.outputs.tag }} if: needs.decide.outputs.dry_run != 'true' env: diff --git a/crates/horizon-release-sign/src/lib.rs b/crates/horizon-release-sign/src/lib.rs index 7b1255921..96ad60e9c 100644 --- a/crates/horizon-release-sign/src/lib.rs +++ b/crates/horizon-release-sign/src/lib.rs @@ -3,9 +3,10 @@ //! Every release carries `SHA256SUMS` (`sha256sum`'s format, ` ` per line) and //! `SHA256SUMS.sig`: one base64 Ed25519 signature per line, each over `horizon release \n` //! followed by SHA256SUMS's bytes, so a signed list can't be passed off under another tag. -//! release.yml and launcher.yml sign with the key(s) in the `release` environment's secrets; the -//! launcher and `horizon-server update` check a download against the public keys built in from -//! `release-keys.txt` before installing it, and refuse it otherwise. +//! release.yml and launcher.yml sign with the key(s) in the `release` environment's secrets +//! (tools/ci/sign_release.sh, OpenSSL only); the launcher and `horizon-server update` check a +//! download against the public keys built in from `release-keys.txt` before installing it, and +//! refuse it otherwise. use base64::{Engine, engine::general_purpose::STANDARD}; use ring::signature::{ED25519, Ed25519KeyPair, KeyPair, UnparsedPublicKey}; @@ -14,8 +15,6 @@ use ring::signature::{ED25519, Ed25519KeyPair, KeyPair, UnparsedPublicKey}; pub const SUMS: &str = "SHA256SUMS"; /// Its signatures' asset name. pub const SIGNATURE: &str = "SHA256SUMS.sig"; -/// The secrets release.yml signs with: the key in use and, while rotating, the next one. -pub const KEY_VARIABLES: [&str; 2] = ["RELEASE_SIGNING_KEY", "RELEASE_SIGNING_KEY_NEXT"]; const KEYS: &str = include_str!("../release-keys.txt"); @@ -175,7 +174,8 @@ pub fn sha256_hex(bytes: &[u8]) -> String { hash.hex() } -/// A private signing key (release.yml only). +/// A private signing key: `keygen` makes them, and tests sign with them (releases are signed by +/// OpenSSL in tools/ci/sign_release.sh, from the same PKCS#8 document). pub struct SigningKey(Ed25519KeyPair); impl SigningKey { diff --git a/crates/horizon-release-sign/src/main.rs b/crates/horizon-release-sign/src/main.rs index 85255e4b7..108b5192a 100644 --- a/crates/horizon-release-sign/src/main.rs +++ b/crates/horizon-release-sign/src/main.rs @@ -1,20 +1,17 @@ -//! horizon-release-sign: signs a release's checksums in release.yml and launcher.yml, checks a -//! downloaded release, and makes new keys (docs/security.md, "Signed updates"). +//! horizon-release-sign: checks a release's signed checksums, and makes new keys +//! (docs/release-flow.md, "Signed checksums"). The signing itself is tools/ci/sign_release.sh: the +//! job that holds the private key runs only the runner's sha256sum and OpenSSL, no code from the +//! repository. //! -//! horizon-release-sign sign --tag v2026.10.19 dist/*.zip dist/*.tar.gz -//! horizon-release-sign sign --tag v2026.10.19 --ephemeral dist/* # a dry run: a throwaway key -//! horizon-release-sign verify --tag v2026.10.19 +//! horizon-release-sign verify --tag v2026.10.19 [--key ] [--publishing] //! horizon-release-sign keygen --public-out key.pub | gh secret set RELEASE_SIGNING_KEY --env release //! -//! `sign` reads the private keys from RELEASE_SIGNING_KEY (and RELEASE_SIGNING_KEY_NEXT while -//! rotating), writes SHA256SUMS and SHA256SUMS.sig beside the first file, and checks the result -//! the way the launcher does, against the keys built in from release-keys.txt. Until that file -//! lists a key it publishes SHA256SUMS alone with a warning; once it does, a missing or unknown -//! signing key fails the release instead of publishing something launchers would refuse. +//! `verify` checks SHA256SUMS.sig and every file SHA256SUMS lists with the keys built in from +//! release-keys.txt (or `--key`), as the launcher does. With `--publishing` (release.yml) a release +//! may go out unsigned, or signed with a key nobody can check yet, only while release-keys.txt +//! lists no key; once it lists one, anything launchers would refuse fails the release. -use horizon_release_sign::{ - KEY_VARIABLES, SIGNATURE, SUMS, Sha256, SigningKey, parse_sums, sums_file, trusted_keys, verify, -}; +use horizon_release_sign::{SIGNATURE, SUMS, Sha256, SigningKey, parse_keys, trusted_keys, verify}; use std::io::{IsTerminal, Read, Write}; use std::path::{Path, PathBuf}; use std::process::ExitCode; @@ -22,12 +19,11 @@ use std::process::ExitCode; fn main() -> ExitCode { let args: Vec = std::env::args().skip(1).collect(); let result = match args.first().map(String::as_str) { - Some("sign") => sign(&args[1..]), Some("verify") => check_folder(&args[1..]), Some("keygen") => keygen(&args[1..]), _ => Err( - "usage: horizon-release-sign sign --tag [--ephemeral] ... | \ - verify --tag | keygen --public-out " + "usage: horizon-release-sign verify --tag [--key ]... [--publishing] \ + | keygen --public-out " .into(), ), }; @@ -40,19 +36,25 @@ fn main() -> ExitCode { } } -/// `--name value` from `args`, and the rest. -fn option(args: &[String], name: &str) -> (Option, Vec) { - let mut value = None; +/// The values of every `--name value` in `args`, and the other arguments. +fn options(args: &[String], name: &str) -> (Vec, Vec) { + let mut values = Vec::new(); let mut rest = Vec::new(); let mut it = args.iter(); while let Some(arg) = it.next() { if arg == name { - value = it.next().cloned(); + values.extend(it.next().cloned()); } else { rest.push(arg.clone()); } } - (value, rest) + (values, rest) +} + +fn tag_of(args: &[String]) -> Result<(String, Vec), String> { + let (tags, rest) = options(args, "--tag"); + let tag = tags.into_iter().next().ok_or("--tag is needed")?; + Ok((tag, rest)) } fn file_hash(path: &Path) -> Result { @@ -70,111 +72,59 @@ fn file_hash(path: &Path) -> Result { } } -fn sign(args: &[String]) -> Result<(), String> { - let (tag, rest) = option(args, "--tag"); - let tag = tag.ok_or("sign needs --tag")?; - let ephemeral = rest.iter().any(|a| a == "--ephemeral"); - let files: Vec = rest - .iter() - .filter(|a| *a != "--ephemeral") - .map(PathBuf::from) - .collect(); - let first = files.first().ok_or("sign needs the files to sign")?; - let folder = first.parent().unwrap_or(Path::new(".")); - let mut listed = Vec::new(); - for file in &files { - let name = file - .file_name() - .and_then(|n| n.to_str()) - .ok_or_else(|| format!("{}: no file name", file.display()))?; - if name != SUMS && name != SIGNATURE { - listed.push((name.to_string(), file_hash(file)?)); - } - } - let sums = sums_file(&listed); - std::fs::write(folder.join(SUMS), &sums).map_err(|e| e.to_string())?; - - let trusted = trusted_keys(); - let keys: Vec = if ephemeral { - vec![SigningKey::generate()?.0] +/// Checks a folder holding a release's assets, as the launcher does. +fn check_folder(args: &[String]) -> Result<(), String> { + let (tag, rest) = tag_of(args)?; + let (keys, rest) = options(&rest, "--key"); + let publishing = rest.iter().any(|a| a == "--publishing"); + let folder = PathBuf::from( + rest.iter() + .find(|a| *a != "--publishing") + .ok_or("verify needs the release's folder")?, + ); + let keys = if keys.is_empty() { + trusted_keys() } else { - KEY_VARIABLES - .iter() - .filter_map(|name| std::env::var(name).ok().filter(|v| !v.trim().is_empty())) - .map(|secret| SigningKey::from_base64(&secret)) - .collect::>()? + parse_keys(&keys.join("\n"))? }; - if keys.is_empty() { - if !trusted.is_empty() { + let sums = std::fs::read(folder.join(SUMS)).map_err(|e| format!("{SUMS}: {e}"))?; + let listed = match std::fs::read_to_string(folder.join(SIGNATURE)) { + Ok(signature) if !keys.is_empty() => verify(&tag, &sums, &signature, &keys)?, + Ok(_) if publishing => { + println!( + "::warning::{tag}: signed, but release-keys.txt lists no key yet, so launchers can't check it" + ); + horizon_release_sign::parse_sums(&String::from_utf8_lossy(&sums))? + } + Err(_) if publishing && keys.is_empty() => { + println!( + "::warning::{tag}: published with {SUMS} but unsigned: release-keys.txt lists no key yet" + ); + horizon_release_sign::parse_sums(&String::from_utf8_lossy(&sums))? + } + Ok(_) => return Err("no key to check the signature with".into()), + Err(_) => { return Err(format!( - "no signing key (the release environment's {}): launchers would refuse an unsigned \ - release, so it is not published", - KEY_VARIABLES[0] + "{tag} has no {SIGNATURE}: launchers would refuse it (is the release environment's \ + RELEASE_SIGNING_KEY set?)" )); } - println!( - "::warning::{tag}: published with {SUMS} but unsigned: release-keys.txt lists no key yet" - ); - return Ok(()); - } - let signature: String = keys - .iter() - .map(|key| key.sign(&tag, sums.as_bytes()) + "\n") - .collect(); - std::fs::write(folder.join(SIGNATURE), &signature).map_err(|e| e.to_string())?; - let check_with = if ephemeral || trusted.is_empty() { - if !ephemeral { - println!( - "::warning::{tag}: signed, but release-keys.txt lists no key yet: add {} to it", - keys[0].public_base64() - ); - } - keys.iter().map(SigningKey::public).collect() - } else { - trusted }; - verify(&tag, sums.as_bytes(), &signature, &check_with).map_err(|_| { - "the signing key is not one release-keys.txt lists: launchers would refuse this release" - .to_string() - })?; - println!( - "{tag}: {} files signed with {} key(s){}", - listed.len(), - keys.len(), - if ephemeral { - " (a throwaway key: dry run)" - } else { - "" - } - ); - Ok(()) -} - -/// Checks a folder holding a release's assets with the built-in keys, as the launcher does. -fn check_folder(args: &[String]) -> Result<(), String> { - let (tag, rest) = option(args, "--tag"); - let tag = tag.ok_or("verify needs --tag")?; - let folder = PathBuf::from(rest.first().ok_or("verify needs the release's folder")?); - let read = |name: &str| std::fs::read(folder.join(name)).map_err(|e| format!("{name}: {e}")); - let sums = read(SUMS)?; - let signature = String::from_utf8(read(SIGNATURE)?).map_err(|e| e.to_string())?; - let listed = verify(&tag, &sums, &signature, &trusted_keys())?; for (name, hex) in &listed { horizon_release_sign::check(name, hex, &file_hash(&folder.join(name))?)?; } - let text = String::from_utf8_lossy(&sums); - println!( - "{tag}: signature good, {} files match", - parse_sums(&text)?.len() - ); + println!("{tag}: {} files match {SUMS}", listed.len()); Ok(()) } /// Prints a new private key to stdout, which must be a pipe (into `gh secret set`), never a /// terminal, and writes its public key to `--public-out`. fn keygen(args: &[String]) -> Result<(), String> { - let (public_out, _) = option(args, "--public-out"); - let public_out = public_out.ok_or("keygen needs --public-out ")?; + let (public_out, _) = options(args, "--public-out"); + let public_out = public_out + .into_iter() + .next() + .ok_or("keygen needs --public-out ")?; if std::io::stdout().is_terminal() { return Err( "keygen writes the private key to its output: pipe it into `gh secret set`".into(), diff --git a/crates/horizon-release-sign/tests/cli.rs b/crates/horizon-release-sign/tests/cli.rs index 50e4c2856..8e9d5f047 100644 --- a/crates/horizon-release-sign/tests/cli.rs +++ b/crates/horizon-release-sign/tests/cli.rs @@ -1,8 +1,11 @@ -//! The signing command as release.yml runs it. -use horizon_release_sign::{SIGNATURE, SUMS, SigningKey, signed_digest, trusted_keys}; -use std::process::Command; +//! The release steps as release.yml runs them: `sums`, tools/ci/sign_release.sh (OpenSSL), `verify`. +use horizon_release_sign::{SIGNATURE, SUMS, SigningKey, trusted_keys}; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; -fn folder(name: &str) -> std::path::PathBuf { +const TAG: &str = "v2026.10.19"; + +fn folder(name: &str) -> PathBuf { let dir = std::env::temp_dir().join(format!( "horizon-release-sign-{name}-{}", std::process::id() @@ -11,73 +14,156 @@ fn folder(name: &str) -> std::path::PathBuf { std::fs::create_dir_all(&dir).unwrap(); std::fs::write(dir.join("horizon-linux-x86_64.tar.gz"), b"linux build").unwrap(); std::fs::write(dir.join("horizon-windows-x64.zip"), b"windows build").unwrap(); + let sums = horizon_release_sign::sums_file(&[ + ( + "horizon-linux-x86_64.tar.gz".into(), + horizon_release_sign::sha256_hex(b"linux build"), + ), + ( + "horizon-windows-x64.zip".into(), + horizon_release_sign::sha256_hex(b"windows build"), + ), + ]); + std::fs::write(dir.join(SUMS), sums).unwrap(); dir } -fn sign(dir: &std::path::Path, extra: &[&str], key: Option<&str>) -> std::process::Output { - let mut cmd = Command::new(env!("CARGO_BIN_EXE_horizon-release-sign")); - cmd.args(["sign", "--tag", "v2026.10.19"]) - .args(extra) +fn tool(args: &[&str], paths: &[&Path]) -> Output { + Command::new(env!("CARGO_BIN_EXE_horizon-release-sign")) + .args(args) + .args(paths) + .output() + .unwrap() +} + +fn verify(dir: &Path, extra: &[&str]) -> Output { + let mut args = vec!["verify", "--tag", TAG]; + args.extend(extra); + tool(&args, &[dir]) +} + +/// An OpenSSL 3 (the runner's), or None on a machine without one (macOS ships LibreSSL). +fn openssl() -> Option { + [ + "openssl", + "/opt/homebrew/opt/openssl@3/bin/openssl", + "/usr/local/opt/openssl@3/bin/openssl", + ] + .into_iter() + .find(|o| { + Command::new(o) + .arg("version") + .output() + .is_ok_and(|v| v.stdout.starts_with(b"OpenSSL 3")) + }) + .map(String::from) +} + +fn sign_script(dir: &Path, env: &[(&str, &str)]) -> Output { + let script = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../tools/ci/sign_release.sh"); + let mut cmd = Command::new("bash"); + cmd.arg(script) + .arg(TAG) .arg(dir.join("horizon-linux-x86_64.tar.gz")) .arg(dir.join("horizon-windows-x64.zip")) .env_remove("RELEASE_SIGNING_KEY") .env_remove("RELEASE_SIGNING_KEY_NEXT"); - if let Some(key) = key { - cmd.env("RELEASE_SIGNING_KEY", key); + cmd.env("OPENSSL", openssl().unwrap()); + for (k, v) in env { + cmd.env(k, v); } cmd.output().unwrap() } #[test] -fn a_dry_run_signs_with_a_throwaway_key() { - let dir = folder("dry"); - let out = sign(&dir, &["--ephemeral"], None); +fn a_signature_made_like_openssls_checks_and_tampering_fails() { + let dir = folder("lib"); + let (key, _) = SigningKey::generate().unwrap(); + let sums = std::fs::read(dir.join(SUMS)).unwrap(); + std::fs::write(dir.join(SIGNATURE), key.sign(TAG, &sums) + "\n").unwrap(); + assert!( + verify(&dir, &["--key", &key.public_base64()]) + .status + .success() + ); + std::fs::write(dir.join("horizon-windows-x64.zip"), b"tampered").unwrap(); + let out = verify(&dir, &["--key", &key.public_base64()]); + assert!(!out.status.success()); + assert!(String::from_utf8_lossy(&out.stderr).contains("doesn't match its signed checksum")); + std::fs::remove_dir_all(dir).unwrap(); +} + +#[test] +fn unsigned_releases_go_out_only_until_a_key_is_listed() { + let dir = folder("unsigned"); + assert_eq!( + verify(&dir, &["--publishing"]).status.success(), + trusted_keys().is_empty() + ); + assert!(!verify(&dir, &[]).status.success()); + std::fs::remove_dir_all(dir).unwrap(); +} + +#[test] +fn the_openssl_script_signs_what_the_launcher_checks() { + if openssl().is_none() { + eprintln!("no OpenSSL 3 here: tools/ci/sign_release.sh is tested on Linux"); + return; + } + // A dry run: a throwaway key, its public key for the check. + let dir = folder("ephemeral"); + std::fs::remove_file(dir.join(SUMS)).unwrap(); // the script writes its own + let out = sign_script(&dir, &[("EPHEMERAL", "yes")]); assert!( out.status.success(), "{}", String::from_utf8_lossy(&out.stderr) ); - assert!(dir.join(SUMS).exists() && dir.join(SIGNATURE).exists()); + let key = std::fs::read_to_string(dir.join("ephemeral.pub")).unwrap(); + assert!(verify(&dir, &["--key", key.trim()]).status.success()); std::fs::remove_dir_all(dir).unwrap(); -} -#[test] -fn a_release_signs_with_the_secret_and_launchers_can_check_it() { - let dir = folder("key"); - let (key, secret) = SigningKey::generate().unwrap(); - let out = sign(&dir, &[], Some(&secret)); - let stdout = String::from_utf8_lossy(&out.stdout); - assert!(!stdout.contains(&secret) && !String::from_utf8_lossy(&out.stderr).contains(&secret)); - if trusted_keys().is_empty() { - // Before release-keys.txt lists a key: signed, with a warning naming the public key. - assert!(out.status.success()); - assert!(stdout.contains(&key.public_base64()), "{stdout}"); - let sums = std::fs::read(dir.join(SUMS)).unwrap(); - let signature = std::fs::read_to_string(dir.join(SIGNATURE)).unwrap(); - let digest = signed_digest( - "v2026.10.19", - "horizon-windows-x64.zip", - Some(&sums), - Some(&signature), - &[key.public()], - ); - assert_eq!( - digest, - Ok(horizon_release_sign::sha256_hex(b"windows build")) - ); - } else { - // A key release-keys.txt doesn't list fails the release. - assert!(!out.status.success()); - } - std::fs::remove_dir_all(dir).unwrap(); -} - -#[test] -fn without_a_secret_it_publishes_unsigned_only_until_a_key_is_listed() { - let dir = folder("none"); - let out = sign(&dir, &[], None); - assert_eq!(out.status.success(), trusted_keys().is_empty()); - assert!(!dir.join(SIGNATURE).exists()); + // A release: both secrets (rotating), as keygen makes them; each signature line checks alone. + let dir = folder("secret"); + let (old, old_secret) = SigningKey::generate().unwrap(); + let (new, new_secret) = SigningKey::generate().unwrap(); + let out = sign_script( + &dir, + &[ + ("RELEASE_SIGNING_KEY", &old_secret), + ("RELEASE_SIGNING_KEY_NEXT", &new_secret), + ], + ); + let printed = format!( + "{}{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); + assert!(out.status.success(), "{printed}"); + assert!(!printed.contains(&old_secret) && !printed.contains(&new_secret)); + assert_eq!( + std::fs::read_to_string(dir.join(SIGNATURE)) + .unwrap() + .lines() + .count(), + 2 + ); + assert!( + verify(&dir, &["--key", &old.public_base64()]) + .status + .success() + ); + assert!( + verify(&dir, &["--key", &new.public_base64()]) + .status + .success() + ); + let (other, _) = SigningKey::generate().unwrap(); + assert!( + !verify(&dir, &["--key", &other.public_base64()]) + .status + .success() + ); std::fs::remove_dir_all(dir).unwrap(); } @@ -85,11 +171,7 @@ fn without_a_secret_it_publishes_unsigned_only_until_a_key_is_listed() { fn keygen_writes_the_secret_to_a_pipe_and_the_public_key_to_a_file() { let dir = folder("keygen"); let public = dir.join("key.pub"); - let out = Command::new(env!("CARGO_BIN_EXE_horizon-release-sign")) - .args(["keygen", "--public-out"]) - .arg(&public) - .output() - .unwrap(); + let out = tool(&["keygen", "--public-out"], &[&public]); assert!(out.status.success()); let key = SigningKey::from_base64(&String::from_utf8(out.stdout).unwrap()).unwrap(); assert_eq!( diff --git a/docs/release-flow.md b/docs/release-flow.md index 2947a6cb7..5bb5e2ff9 100644 --- a/docs/release-flow.md +++ b/docs/release-flow.md @@ -157,16 +157,19 @@ Kira posts every published release in #releases and pings the releases role only Every game and launcher release carries `SHA256SUMS` (the archives' SHA-256, `sha256sum`'s format) and `SHA256SUMS.sig`: one base64 Ed25519 signature per line over `horizon release \n` followed by SHA256SUMS, -so a signed list can't be reused under another tag. The publish job signs with -`cargo run -p horizon-release-sign -- sign` (crates/horizon-release-sign), then checks the result the way -launchers do, against the public keys built in from `crates/horizon-release-sign/release-keys.txt`: +so a signed list can't be reused under another tag. -- The private key is the `RELEASE_SIGNING_KEY` secret of the repository's `release` environment, which only real - releases from main enter (`environment:` is empty in dry runs, which sign with a throwaway key). It is in no - file, no log and no password vault; nobody needs to read it. -- While release-keys.txt lists no key, releases go out with SHA256SUMS alone and a warning (today's releases keep - working). Once it lists one, a missing secret or a key it doesn't list fails the release before anything is - published, instead of publishing something launchers would refuse. +- A `sign` job of its own makes them: `tools/ci/sign_release.sh` runs the runner's `sha256sum` and OpenSSL and + nothing else. It is the only job that holds the private key, the `RELEASE_SIGNING_KEY` secret of the + repository's `release` environment, which only real releases from main enter (`environment:` is empty in dry + runs, which sign with a throwaway key). No code from the repository runs beside the key, so no pull request + can read it by changing what a build compiles; the key is in no file, no log and no password vault, and nobody + needs to read it. +- The publish job then checks the signature the way launchers do (`horizon-release-sign verify --publishing`, + crates/horizon-release-sign), against the public keys built in from + `crates/horizon-release-sign/release-keys.txt`. While that file lists no key, releases go out with SHA256SUMS + alone and a warning (today's releases keep working). Once it lists one, a missing secret or a key it doesn't + list fails the release before anything is published, instead of publishing something launchers would refuse. - Making the key: `tools/ci/new_release_key.sh` pipes a new key from `horizon-release-sign keygen` straight into `gh secret set RELEASE_SIGNING_KEY --env release` and prints only the public key, which then goes into release-keys.txt by pull request. diff --git a/tools/ci/sign_release.sh b/tools/ci/sign_release.sh new file mode 100755 index 000000000..4fa03ebd1 --- /dev/null +++ b/tools/ci/sign_release.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Signs a release (docs/release-flow.md, "Signed checksums"): writes SHA256SUMS for the files given, then +# SHA256SUMS.sig beside them, one base64 Ed25519 signature per line over "horizon release \n" + SHA256SUMS, +# for every key set in RELEASE_SIGNING_KEY and RELEASE_SIGNING_KEY_NEXT (base64 PKCS#8, the `release` +# environment's secrets). The job that runs this holds the private keys, so it runs nothing from the repository +# but this file, which calls only the runner's sha256sum and OpenSSL; the publish job then checks the result +# with horizon-release-sign, as launchers do. +# EPHEMERAL=yes (dry runs) signs with a throwaway key instead and writes its public key to ephemeral.pub. +# tools/ci/sign_release.sh v2026.10.19 dist/horizon-linux-x86_64.tar.gz dist/horizon-windows-x64.zip ... +set -euo pipefail +tag=$1; shift +dir=$(dirname "$1") +openssl=${OPENSSL:-openssl} +if command -v sha256sum > /dev/null; then sha=(sha256sum); else sha=(shasum -a 256); fi +umask 077 +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT + +names=() +for file in "$@"; do + [[ "$(dirname "$file")" == "$dir" ]] || { echo "$file: every file must be in $dir" >&2; exit 1; } + names+=("$(basename "$file")") +done +(cd "$dir" && "${sha[@]}" -- "${names[@]}") > "$dir/SHA256SUMS" +{ printf 'horizon release %s\n' "$tag"; cat "$dir/SHA256SUMS"; } > "$work/message" +rm -f "$dir/SHA256SUMS.sig" "$dir/ephemeral.pub" + +sign_with() { # the key file in $1 + "$openssl" pkeyutl -sign -rawin -inkey "$1" -keyform DER -in "$work/message" -out "$work/signature" + # base64 of the 64 bytes on one line (GNU base64 wraps at 76 characters). + base64 < "$work/signature" | tr -d '\n' >> "$dir/SHA256SUMS.sig" + echo >> "$dir/SHA256SUMS.sig" + rm -f "$1" "$work/signature" +} + +if [[ -n "${EPHEMERAL:-}" ]]; then + "$openssl" genpkey -algorithm ed25519 -outform DER -out "$work/key" + "$openssl" pkey -inform DER -in "$work/key" -pubout -outform DER | tail -c 32 | base64 > "$dir/ephemeral.pub" + sign_with "$work/key" +else + for name in RELEASE_SIGNING_KEY RELEASE_SIGNING_KEY_NEXT; do + if [[ -n "${!name:-}" ]]; then + # From the environment into a private temporary file: never an argument, never printed. + printf '%s' "${!name}" | base64 --decode > "$work/key" + sign_with "$work/key" + fi + done +fi +echo "$tag: SHA256SUMS lists ${#names[@]} files; $( [[ -f "$dir/SHA256SUMS.sig" ]] && echo "signed with $(wc -l < "$dir/SHA256SUMS.sig" | tr -d ' ') key(s)" || echo "no signing key, so unsigned")"