From c415aa8928989c0bd217ec494336d27aa34a269d Mon Sep 17 00:00:00 2001 From: vanderbr <11340250+vanderbr@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:26:41 +0000 Subject: [PATCH] Update release checks --- .github/dependency-maintenance.json | 4 +- .github/workflows/code-checks.yml | 6 +- .github/workflows/codeql.yml | 4 +- .../workflows/crates-package-preflight.yml | 4 +- .../kotlin-android-package-preflight.yml | 2 +- .github/workflows/npm-package-preflight.yml | 6 +- .github/workflows/release-readiness.yml | 4 +- .github/workflows/swift-package-preflight.yml | 2 +- Cargo.lock | 24 +++--- fuzz/Cargo.lock | 20 ++--- scripts/promote_maven_publications.sh | 30 +++++-- scripts/promote_maven_publications.test.mjs | 79 +++++++++++++++++++ scripts/upload_maven_central_bundle.mjs | 25 +++++- scripts/upload_maven_central_bundle.test.mjs | 45 ++++++++++- 14 files changed, 207 insertions(+), 48 deletions(-) create mode 100644 scripts/promote_maven_publications.test.mjs diff --git a/.github/dependency-maintenance.json b/.github/dependency-maintenance.json index b1131635..564f7627 100644 --- a/.github/dependency-maintenance.json +++ b/.github/dependency-maintenance.json @@ -52,7 +52,7 @@ "name": "syn", "current": "2.0.119", "latest": "3.0.10", - "reason": "match-lookup 0.1.3, multihash-derive-impl 0.1.3 and zerocopy-derive 0.8.63 require syn 2.x. Syn 3 is already selected for compatible parents; revisit after remaining parents migrate.", + "reason": "match-lookup 0.1.3, multihash-derive-impl 0.1.3 and zerocopy-derive 0.8.64 require syn 2.x. Syn 3 is already selected for compatible parents; revisit after remaining parents migrate.", "expires": "2026-12-20" }, { @@ -124,7 +124,7 @@ "name": "syn", "current": "2.0.119", "latest": "3.0.10", - "reason": "match-lookup 0.1.3, multihash-derive-impl 0.1.3 and zerocopy-derive 0.8.63 require syn 2.x. Syn 3 is already selected for compatible parents; revisit after remaining parents migrate.", + "reason": "match-lookup 0.1.3, multihash-derive-impl 0.1.3 and zerocopy-derive 0.8.64 require syn 2.x. Syn 3 is already selected for compatible parents; revisit after remaining parents migrate.", "expires": "2026-12-20" }, { diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml index 4fae2ec5..1d48cb9c 100644 --- a/.github/workflows/code-checks.yml +++ b/.github/workflows/code-checks.yml @@ -59,7 +59,7 @@ jobs: - name: Install ShellCheck if: matrix.os == 'ubuntu-24.04' - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7 with: tool: shellcheck@0.11.0 @@ -103,7 +103,7 @@ jobs: cache-bin: false - name: Install nextest - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6, nextest + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7, nextest with: tool: cargo-nextest@0.9.152 @@ -111,7 +111,7 @@ jobs: run: cargo +1.100.0 install cargo-deny --version '=0.22.0' --locked - name: Install cargo-audit - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6, cargo-audit + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7, cargo-audit with: tool: cargo-audit@0.23.0 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index fcabc6a8..22ace20e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -64,7 +64,7 @@ jobs: java-version: '21' - name: Initialize CodeQL - uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4 + uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} @@ -79,6 +79,6 @@ jobs: packages/kotlin/gradlew -p packages/kotlin-android --no-daemon --no-build-cache --rerun-tasks compileReleaseKotlin compileReleaseJavaWithJavac :consumer-r8-runtime:compileReleaseJavaWithJavac - name: Analyze CodeQL - uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4 + uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/crates-package-preflight.yml b/.github/workflows/crates-package-preflight.yml index 4e7ed0d1..a3831fe4 100644 --- a/.github/workflows/crates-package-preflight.yml +++ b/.github/workflows/crates-package-preflight.yml @@ -79,7 +79,7 @@ jobs: toolchain: 1.100.0 - name: Install dependency maintenance tools - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7 with: tool: cargo-audit@0.23.0 fallback: none @@ -147,7 +147,7 @@ jobs: toolchain: 1.100.0 - name: Install cargo-audit - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6, cargo-audit + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7, cargo-audit with: tool: cargo-audit@0.23.0 diff --git a/.github/workflows/kotlin-android-package-preflight.yml b/.github/workflows/kotlin-android-package-preflight.yml index c57a5269..f824305b 100644 --- a/.github/workflows/kotlin-android-package-preflight.yml +++ b/.github/workflows/kotlin-android-package-preflight.yml @@ -81,7 +81,7 @@ jobs: toolchain: 1.100.0 - name: Install dependency maintenance tools - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7 with: tool: cargo-audit@0.23.0 fallback: none diff --git a/.github/workflows/npm-package-preflight.yml b/.github/workflows/npm-package-preflight.yml index 6e74be22..f503304c 100644 --- a/.github/workflows/npm-package-preflight.yml +++ b/.github/workflows/npm-package-preflight.yml @@ -79,7 +79,7 @@ jobs: toolchain: 1.100.0 - name: Install dependency maintenance tools - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7 with: tool: cargo-audit@0.23.0 fallback: none @@ -166,12 +166,12 @@ jobs: targets: wasm32-unknown-unknown - name: Install wasm-pack - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6, wasm-pack + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7, wasm-pack with: tool: wasm-pack@0.15.1 - name: Install wasm-bindgen-cli - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6, wasm-bindgen-cli + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7, wasm-bindgen-cli with: tool: wasm-bindgen-cli@0.2.130 diff --git a/.github/workflows/release-readiness.yml b/.github/workflows/release-readiness.yml index 7a7938e6..616d1692 100644 --- a/.github/workflows/release-readiness.yml +++ b/.github/workflows/release-readiness.yml @@ -88,12 +88,12 @@ jobs: java-version: '21' - name: Install wasm-pack - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7 with: tool: wasm-pack@0.15.1 - name: Install wasm-bindgen-cli - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7 with: tool: wasm-bindgen-cli@0.2.130 diff --git a/.github/workflows/swift-package-preflight.yml b/.github/workflows/swift-package-preflight.yml index 84470b78..f23bf9e2 100644 --- a/.github/workflows/swift-package-preflight.yml +++ b/.github/workflows/swift-package-preflight.yml @@ -79,7 +79,7 @@ jobs: toolchain: 1.100.0 - name: Install dependency maintenance tools - uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f # v2.90.6 + uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7 with: tool: cargo-audit@0.23.0 fallback: none diff --git a/Cargo.lock b/Cargo.lock index 8da89132..96f83d7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,9 +113,9 @@ checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" [[package]] name = "cc" -version = "1.11.2" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ef9e3e8154a45c7a95cff4c1299702106ad94062d7bb85fdc5d3a5afd91d45" +checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69" dependencies = [ "find-msvc-tools", "shlex", @@ -1044,9 +1044,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.25.19+spec-1.1.0" +version = "0.25.20+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218" +checksum = "e76360e201d6dbd6583e17795ba71a88f47365a9139c8450a7979c32303b8e73" dependencies = [ "indexmap", "toml_datetime", @@ -1056,9 +1056,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.1.5+spec-1.1.0" +version = "1.1.6+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +checksum = "e6769c452d71ba30696c6b37770c439a9cc9110f47f7d5cdbeda79840ef5ea31" dependencies = [ "winnow", ] @@ -1089,9 +1089,9 @@ checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" [[package]] name = "walkdir" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +checksum = "b42e295b7452c4604982280d8586001fcad9b8b201cac67bca9771e7a7475403" dependencies = [ "same-file", "winapi-util", @@ -1176,18 +1176,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.63" +version = "0.8.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" +checksum = "ed43f3060383c64b000f3c630550aebdfa9d3b76d48de32390483dd2cc7e0865" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.63" +version = "0.8.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" +checksum = "a5cbd820fe3e35fb38c83b6dc7e6b1618bc46e0cd10073ae94e8d52dc468d8b9" dependencies = [ "proc-macro2", "quote", diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 08165670..89a0fd9c 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -101,9 +101,9 @@ checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" [[package]] name = "cc" -version = "1.11.2" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ef9e3e8154a45c7a95cff4c1299702106ad94062d7bb85fdc5d3a5afd91d45" +checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69" dependencies = [ "find-msvc-tools", "jobserver", @@ -800,9 +800,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.25.19+spec-1.1.0" +version = "0.25.20+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218" +checksum = "e76360e201d6dbd6583e17795ba71a88f47365a9139c8450a7979c32303b8e73" dependencies = [ "indexmap", "toml_datetime", @@ -812,9 +812,9 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.1.5+spec-1.1.0" +version = "1.1.6+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +checksum = "e6769c452d71ba30696c6b37770c439a9cc9110f47f7d5cdbeda79840ef5ea31" dependencies = [ "winnow", ] @@ -848,18 +848,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.63" +version = "0.8.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" +checksum = "ed43f3060383c64b000f3c630550aebdfa9d3b76d48de32390483dd2cc7e0865" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.63" +version = "0.8.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" +checksum = "a5cbd820fe3e35fb38c83b6dc7e6b1618bc46e0cd10073ae94e8d52dc468d8b9" dependencies = [ "proc-macro2", "quote", diff --git a/scripts/promote_maven_publications.sh b/scripts/promote_maven_publications.sh index ca734ca8..6123c45f 100755 --- a/scripts/promote_maven_publications.sh +++ b/scripts/promote_maven_publications.sh @@ -4,6 +4,7 @@ # SPDX-License-Identifier: MIT OR Apache-2.0 set -euo pipefail +set +x umask 077 fail() { @@ -15,10 +16,22 @@ if [[ $# != 3 || "$1" != /* || ! "$2" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[ fail 'expected an absolute package directory, stable version, and full source SHA' fi +# Keep credentials local until the individual signing or upload operation. +export -n signing_key signing_password portal_username portal_password +: "${MAVEN_SIGNING_KEY:?Maven signing key required}" +: "${MAVEN_SIGNING_PASSWORD:?Maven signing passphrase required}" +: "${CENTRAL_PORTAL_USERNAME:?Maven Central username required}" +: "${CENTRAL_PORTAL_PASSWORD:?Maven Central password required}" +signing_key="$MAVEN_SIGNING_KEY" +signing_password="$MAVEN_SIGNING_PASSWORD" +readonly portal_username="$CENTRAL_PORTAL_USERNAME" portal_password="$CENTRAL_PORTAL_PASSWORD" +unset MAVEN_SIGNING_KEY MAVEN_SIGNING_PASSWORD CENTRAL_PORTAL_USERNAME CENTRAL_PORTAL_PASSWORD + readonly packages="$1" version="$2" source_sha="$3" script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" work_dir="$(mktemp -d)" readonly script_dir work_dir +cd -- "$script_dir/.." export GNUPGHOME="$work_dir/gnupg" cleanup() { @@ -32,12 +45,12 @@ readonly bundle="$work_dir/bundle" mkdir -p "$bundle" node "$script_dir/stage_maven_publications.mjs" "$packages" "$version" "$source_sha" "$bundle" +node "$script_dir/run_pinned_release_readiness.mjs" --check-pins +node "$script_dir/../.release-readiness/scripts/repository-privacy.mjs" --artifact "$bundle" -: "${MAVEN_SIGNING_KEY:?Maven signing key required}" -: "${MAVEN_SIGNING_PASSWORD:?Maven signing passphrase required}" -printf '%s\n' "$MAVEN_SIGNING_KEY" | gpg --batch --import >/dev/null 2>&1 || +gpg --batch --import >/dev/null 2>&1 <<<"$signing_key" || fail 'could not import the Maven signing key' -unset MAVEN_SIGNING_KEY +unset signing_key # The isolated keyring must contain exactly one signing identity. fingerprints="$(gpg --batch --with-colons --list-secret-keys | awk -F: '$1 == "sec" { primary = 1; next } primary && $1 == "fpr" { print $10; primary = 0 }')" @@ -46,15 +59,18 @@ fingerprints="$(gpg --batch --with-colons --list-secret-keys | shopt -s nullglob for file in "$bundle"/me/really/*/"$version"/*; do gpg --batch --pinentry-mode loopback --passphrase-fd 0 --local-user "$fingerprints" \ - --armor --detach-sign --output "$file.asc" "$file" <<<"$MAVEN_SIGNING_PASSWORD" + --armor --detach-sign --output "$file.asc" "$file" <<<"$signing_password" + gpg --batch --no-tty --no-auto-key-retrieve --verify "$file.asc" "$file" >/dev/null 2>&1 for signed_file in "$file" "$file.asc"; do for algorithm in md5 sha1 sha256 sha512; do "${algorithm}sum" -- "$signed_file" | cut -d ' ' -f 1 >"$signed_file.$algorithm" done done done -unset MAVEN_SIGNING_PASSWORD +unset signing_password readonly archive="$work_dir/reallyme-maven-central-$version.zip" (cd "$bundle" && zip -X -q -r "$archive" me) -node "$script_dir/upload_maven_central_bundle.mjs" "$archive" "$version" +node "$script_dir/../.release-readiness/scripts/repository-privacy.mjs" --artifact "$archive" +CENTRAL_PORTAL_USERNAME="$portal_username" CENTRAL_PORTAL_PASSWORD="$portal_password" \ + node "$script_dir/upload_maven_central_bundle.mjs" "$archive" "$version" diff --git a/scripts/promote_maven_publications.test.mjs b/scripts/promote_maven_publications.test.mjs new file mode 100644 index 00000000..9da9f3c4 --- /dev/null +++ b/scripts/promote_maven_publications.test.mjs @@ -0,0 +1,79 @@ +// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +const script = fileURLToPath(new URL("promote_maven_publications.sh", import.meta.url)); + +for (const failure of ["privacy", "signature"]) { + test(`Maven promotion stops before upload on ${failure} failure and isolates credentials`, (t) => { + const directory = mkdtempSync(join(tmpdir(), "codec-promotion-test-")); + t.after(() => rmSync(directory, { recursive: true, force: true })); + const scripts = join(directory, "scripts"); + const bin = join(directory, "bin"); + const events = join(directory, "events"); + mkdirSync(scripts); + mkdirSync(bin); + copyFileSync(script, join(scripts, "promote.sh")); + writeFileSync(join(bin, "node"), `#!/bin/bash +set -euo pipefail +[[ -z "\${CENTRAL_PORTAL_USERNAME+x}" && -z "\${CENTRAL_PORTAL_PASSWORD+x}" && -z "\${MAVEN_SIGNING_KEY+x}" && -z "\${MAVEN_SIGNING_PASSWORD+x}" ]] || exit 91 +case "$1" in + */stage_maven_publications.mjs) + mkdir -p "$5/me/really/codec/0.4.5" + printf 'fixture' > "$5/me/really/codec/0.4.5/codec-0.4.5.pom" + printf 'stage\\n' >> "$TEST_EVENTS" ;; + */run_pinned_release_readiness.mjs) printf 'authenticate\\n' >> "$TEST_EVENTS" ;; + */repository-privacy.mjs) + printf 'privacy\\n' >> "$TEST_EVENTS" + [[ "$TEST_FAILURE" != privacy ]] ;; + */upload_maven_central_bundle.mjs) printf 'unexpected-upload\\n' >> "$TEST_EVENTS"; exit 92 ;; + *) exit 93 ;; +esac +`, { mode: 0o700 }); + writeFileSync(join(bin, "gpg"), `#!/bin/bash +set -euo pipefail +[[ -z "\${CENTRAL_PORTAL_USERNAME+x}" && -z "\${CENTRAL_PORTAL_PASSWORD+x}" && -z "\${MAVEN_SIGNING_KEY+x}" && -z "\${MAVEN_SIGNING_PASSWORD+x}" ]] || exit 94 +case " $* " in + *" --import "*) + read -r key + [[ "$key" == private-signing-key ]] + printf 'import\\n' >> "$TEST_EVENTS" ;; + *" --list-secret-keys "*) + printf 'sec:::::::::\\nfpr:::::::::0123456789ABCDEF0123456789ABCDEF01234567:\\n' ;; + *" --detach-sign "*) + read -r password + [[ "$password" == private-signing-password ]] + printf 'sign\\n' >> "$TEST_EVENTS" ;; + *" --verify "*) + [[ " $* " == *" --no-auto-key-retrieve "* ]] + printf 'verify\\n' >> "$TEST_EVENTS" + exit 1 ;; + *) exit 95 ;; +esac +`, { mode: 0o700 }); + writeFileSync(join(bin, "gpgconf"), "#!/bin/bash\nexit 0\n", { mode: 0o700 }); + const result = spawnSync("bash", ["-x", join(scripts, "promote.sh"), directory, "0.4.5", "a".repeat(40)], { + encoding: "utf8", timeout: 10_000, + env: { + ...process.env, PATH: `${bin}:${process.env.PATH}`, + TEST_EVENTS: events, TEST_FAILURE: failure, + MAVEN_SIGNING_KEY: "private-signing-key", MAVEN_SIGNING_PASSWORD: "private-signing-password", + CENTRAL_PORTAL_USERNAME: "private-portal-user", CENTRAL_PORTAL_PASSWORD: "private-portal-password", + }, + }); + assert.equal(result.error, undefined); + assert.equal(result.status, 1, result.stderr); + const expected = ["stage", "authenticate", "privacy"]; + if (failure === "signature") expected.push("import", "sign", "verify"); + assert.deepEqual(readFileSync(events, "utf8").trim().split("\n"), expected); + assert.doesNotMatch(`${result.stdout}${result.stderr}`, /private-(?:signing|portal)/u); + }); +} diff --git a/scripts/upload_maven_central_bundle.mjs b/scripts/upload_maven_central_bundle.mjs index 931fbccf..49e4fb70 100644 --- a/scripts/upload_maven_central_bundle.mjs +++ b/scripts/upload_maven_central_bundle.mjs @@ -3,10 +3,13 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 +import { spawnSync } from "node:child_process"; import { readFileSync, statSync } from "node:fs"; -import { basename } from "node:path"; +import { basename, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; const PORTAL = "https://central.sonatype.com/api/v1/publisher"; +const repositoryDirectory = fileURLToPath(new URL("../", import.meta.url)); const MAX_BUNDLE_BYTES = 536_870_912; const POLL_INTERVAL_MS = 20_000; const MAX_POLLS = 180; @@ -29,6 +32,10 @@ const main = async () => { const [, , bundlePath, version] = process.argv; const username = process.env.CENTRAL_PORTAL_USERNAME; const password = process.env.CENTRAL_PORTAL_PASSWORD; + // Privacy inspectors must not inherit publication or signing credentials. + for (const name of ["CENTRAL_PORTAL_USERNAME", "CENTRAL_PORTAL_PASSWORD", "MAVEN_SIGNING_KEY", "MAVEN_SIGNING_PASSWORD"]) { + delete process.env[name]; + } if (typeof bundlePath !== "string" || !bundlePath.endsWith(".zip") || typeof version !== "string" || !VERSION_PATTERN.test(version)) { fail("invalid-bundle-arguments"); @@ -48,6 +55,20 @@ const main = async () => { fail("bundle-size-invalid"); } + // Authenticate the shared policy, then inspect both source tracking and the + // actual archive before constructing authentication material or sending requests. + for (const arguments_ of [ + ["scripts/run_pinned_release_readiness.mjs", "--check-pins"], + [".release-readiness/scripts/repository-privacy.mjs", "--artifact", resolve(bundlePath)], + ]) { + const privacy = spawnSync(process.execPath, arguments_, { + cwd: repositoryDirectory, stdio: "inherit", timeout: 90_000, + }); + if (privacy.error !== undefined || privacy.status !== 0) { + fail("publication-privacy-rejected"); + } + } + const authentication = Buffer.from(`${username}:${password}`, "utf8"); const headers = { Authorization: `Bearer ${authentication.toString("base64")}` }; authentication.fill(0); @@ -60,6 +81,7 @@ const main = async () => { const upload = await fetch(uploadUrl, { method: "POST", + redirect: "error", headers, body: form, signal: AbortSignal.timeout(120_000), @@ -81,6 +103,7 @@ const main = async () => { statusUrl.searchParams.set("id", deploymentId); const response = await fetch(statusUrl, { method: "POST", + redirect: "error", headers, signal: AbortSignal.timeout(30_000), }); diff --git a/scripts/upload_maven_central_bundle.test.mjs b/scripts/upload_maven_central_bundle.test.mjs index db87244c..51fd5c52 100644 --- a/scripts/upload_maven_central_bundle.test.mjs +++ b/scripts/upload_maven_central_bundle.test.mjs @@ -13,6 +13,15 @@ import { fileURLToPath, pathToFileURL } from "node:url"; const script = fileURLToPath(new URL("upload_maven_central_bundle.mjs", import.meta.url)); const deploymentId = "28570f16-da32-4c14-bd2e-c1acc0782365"; +function writeArchive(path, entry = "me/really/codec/0.3.1/codec-0.3.1.pom") { + const result = spawnSync("python3", ["-c", ` +import sys, zipfile +with zipfile.ZipFile(sys.argv[1], 'w') as archive: + archive.writestr(sys.argv[2], 'bounded bundle fixture') +`, path, entry], { encoding: "utf8" }); + assert.equal(result.status, 0, result.stderr); +} + for (const [state, expectedStatus] of [ ["PUBLISHED", 0], ["FAILED", 1], @@ -23,9 +32,21 @@ for (const [state, expectedStatus] of [ t.after(() => rmSync(directory, { recursive: true, force: true })); const archive = join(directory, "bundle.zip"); const preload = join(directory, "portal.mjs"); - writeFileSync(archive, "bounded bundle fixture"); + writeArchive(archive); writeFileSync(preload, ` + import childProcess from 'node:child_process'; + import { syncBuiltinESMExports } from 'node:module'; + const spawnSync = childProcess.spawnSync; + childProcess.spawnSync = (...args) => { + const env = args[2]?.env ?? process.env; + if (['CENTRAL_PORTAL_USERNAME', 'CENTRAL_PORTAL_PASSWORD', 'MAVEN_SIGNING_KEY', 'MAVEN_SIGNING_PASSWORD'].some(key => key in env)) { + throw Error('credentials inherited by privacy inspector'); + } + return spawnSync(...args); + }; + syncBuiltinESMExports(); globalThis.fetch = async (url, options) => { + if (options.redirect !== 'error') throw Error('redirects must be rejected'); if (String(url).endsWith('/upload?publishingType=AUTOMATIC&name=reallyme-codec-0.3.1')) { if (options.method !== 'POST' || !String(options.headers.Authorization).startsWith('Bearer ')) throw Error('wrong upload request'); return { status: 201, text: async () => '${deploymentId}' }; @@ -39,7 +60,7 @@ for (const [state, expectedStatus] of [ const result = spawnSync(process.execPath, ["--import", pathToFileURL(preload).href, script, archive, "0.3.1"], { encoding: "utf8", env: { ...process.env, CENTRAL_PORTAL_USERNAME: "test-user", CENTRAL_PORTAL_PASSWORD: "private-test-password" }, - timeout: 10_000, + timeout: 30_000, }); assert.equal(result.error, undefined); assert.equal(result.status, expectedStatus, result.stderr); @@ -60,3 +81,23 @@ test("Central Portal upload requires credentials before making a request", (t) = assert.equal(result.status, 1); assert.match(result.stderr, /missing-portal-credentials/u); }); + +for (const entry of ["AGENTS.md", "me/really/codec/0.3.1/private.zip"]) { + test(`Central Portal rejects private or uninspectable archive content: ${entry}`, (t) => { + const directory = mkdtempSync(join(tmpdir(), "codec-portal-test-")); + t.after(() => rmSync(directory, { recursive: true, force: true })); + const archive = join(directory, "bundle.zip"); + const preload = join(directory, "portal.mjs"); + writeArchive(archive, entry); + writeFileSync(preload, "globalThis.fetch = () => { console.error('unexpected-network-request'); process.exit(99); };\n"); + const result = spawnSync(process.execPath, ["--import", pathToFileURL(preload).href, script, archive, "0.3.1"], { + encoding: "utf8", + env: { ...process.env, CENTRAL_PORTAL_USERNAME: "test-user", CENTRAL_PORTAL_PASSWORD: "private-test-password" }, + timeout: 30_000, + }); + assert.equal(result.error, undefined); + assert.equal(result.status, 1, result.stderr); + assert.match(result.stderr, /publication-privacy-rejected/u); + assert.doesNotMatch(`${result.stdout}${result.stderr}`, /unexpected-network-request|private-test-password/u); + }); +}