From cdab7ea82296db77e6213a5abc2f06fa3be1de33 Mon Sep 17 00:00:00 2001 From: Jim Manico Date: Sat, 7 Nov 2026 19:21:10 -0800 Subject: [PATCH] Pin the release signing key and add a no-publish signing check The release tag step now refuses a signing key whose fingerprint is not the configured release key and confirms the tag's signer after signing. A manually dispatched workflow exercises the same path without publishing: it signs and verifies a placeholder tag on the runner and deletes it, then runs JReleaser's Maven Central deployer in dry-run mode with placeholder Central credentials, which signs every staged artifact but uploads nothing, and checks each signature against the pinned fingerprint. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 1 + .github/workflows/verify-release-signing.yml | 63 ++++++++++++++++++++ scripts/sign-release-tag.sh | 33 ++++++++-- scripts/verify-artifact-signatures.sh | 57 ++++++++++++++++++ 4 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/verify-release-signing.yml create mode 100755 scripts/verify-artifact-signatures.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e47a661a..ec68c0c8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -108,6 +108,7 @@ jobs: - name: Sign release tag env: + EXPECTED_GPG_FINGERPRINT: F6109A4F3F5616E1A7A62099E02DB03BAF6C438C GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} diff --git a/.github/workflows/verify-release-signing.yml b/.github/workflows/verify-release-signing.yml new file mode 100644 index 00000000..6c3c6668 --- /dev/null +++ b/.github/workflows/verify-release-signing.yml @@ -0,0 +1,63 @@ +name: Verify release signing + +# Exercises the release signing path with the repository's release key +# without publishing anything: the tag is created and deleted on the runner, +# and JReleaser deploys in dry-run mode with placeholder Central credentials. + +on: + workflow_dispatch: + +permissions: + contents: read + +env: + EXPECTED_GPG_FINGERPRINT: F6109A4F3F5616E1A7A62099E02DB03BAF6C438C + # Never released; the runner's copy of the POMs is set to it so the + # staging repository looks like a release, and nothing is pushed. + VERSION: 20000101.0 + +jobs: + verify: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Set up JDK + uses: actions/setup-java@v5 + with: + distribution: zulu + java-version: 11 + cache: maven + + - name: Set placeholder release version + run: ./mvnw -ntp -B versions:set -DgenerateBackupPoms=false -DnewVersion="$VERSION" + + - name: Build staged artifacts + run: ./mvnw -ntp -B -Ppublication + + - name: Check signed tag without publishing it + env: + GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} + GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: scripts/sign-release-tag.sh "release-$VERSION" "$(git rev-parse HEAD)" verify + + - name: Sign artifacts with JReleaser in dry-run mode + env: + JRELEASER_DRY_RUN: 'true' + JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME: dry-run-only + JRELEASER_MAVENCENTRAL_SONATYPE_PASSWORD: dry-run-only + JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} + JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} + run: ./mvnw -ntp -B -N -Ppublication -Djreleaser.dry.run=true jreleaser:deploy + + - name: Check artifact signatures + env: + GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} + run: scripts/verify-artifact-signatures.sh target/staging-deploy diff --git a/scripts/sign-release-tag.sh b/scripts/sign-release-tag.sh index 34b085fd..8f635189 100755 --- a/scripts/sign-release-tag.sh +++ b/scripts/sign-release-tag.sh @@ -11,16 +11,21 @@ if [[ ! $tag =~ ^release-[0-9]{8}\.[0-9]+$ || ! $commit =~ ^[0-9a-f]{40}$ ]]; th echo 'Invalid release tag or commit' >&2 exit 1 fi -if [[ $mode != create && $mode != repair ]]; then - echo 'Mode must be create or repair' >&2 +if [[ $mode != create && $mode != repair && $mode != verify ]]; then + echo 'Mode must be create, repair, or verify' >&2 exit 1 fi : "${GPG_SECRET_KEY:?GPG_SECRET_KEY required}" : "${GPG_PUBLIC_KEY:?GPG_PUBLIC_KEY required}" : "${GPG_PASSPHRASE:?GPG_PASSPHRASE required}" +: "${EXPECTED_GPG_FINGERPRINT:?EXPECTED_GPG_FINGERPRINT required}" +if [[ ! $EXPECTED_GPG_FINGERPRINT =~ ^[0-9A-F]{40}$ ]]; then + echo 'Invalid expected release signing fingerprint' >&2 + exit 1 +fi remote_ref=$(git ls-remote --refs origin "refs/tags/$tag") -if [[ $mode == create ]]; then +if [[ $mode != repair ]]; then if [[ -n $remote_ref ]] || git show-ref --verify --quiet "refs/tags/$tag"; then echo "Tag $tag already exists" >&2 exit 1 @@ -41,6 +46,13 @@ signing_home=$(mktemp -d) trap 'gpgconf --kill gpg-agent >/dev/null 2>&1 || true; rm -rf "$signing_home"' EXIT chmod 700 "$signing_home" export GNUPGHOME=$signing_home +public_fingerprint=$(printf '%s\n' "$GPG_PUBLIC_KEY" | + gpg --batch --show-keys --with-colons | + awk -F: '$1 == "fpr" { print $10; exit }') +if [[ $public_fingerprint != "$EXPECTED_GPG_FINGERPRINT" ]]; then + echo 'Release public key fingerprint does not match the configured key' >&2 + exit 1 +fi printf '%s\n' "$GPG_PUBLIC_KEY" | gpg --batch --quiet --import printf '%s\n' "$GPG_SECRET_KEY" | gpg --batch --quiet --import @@ -50,6 +62,10 @@ if [[ ! $fingerprint =~ ^[0-9A-F]{40}$ ]]; then echo 'Expected exactly one release signing key' >&2 exit 1 fi +if [[ $fingerprint != "$EXPECTED_GPG_FINGERPRINT" ]]; then + echo 'Release signing key fingerprint does not match the configured key' >&2 + exit 1 +fi uid=$(gpg --batch --with-colons --list-secret-keys | awk -F: '$1 == "uid" { print $10; exit }') if [[ ! $uid =~ ^(.+)\ \<([^\<\>]+)\>$ ]]; then @@ -72,6 +88,13 @@ GIT_COMMITTER_NAME=$tagger_name GIT_COMMITTER_EMAIL=$tagger_email \ git -c "gpg.program=$signing_home/gpg-for-git" tag -s -u "$fingerprint" \ -m "Release ${tag#release-}" "$tag" "$commit" git tag -v "$tag" +signer=$(git verify-tag --raw "$tag" 2>&1 | + awk '$1 == "[GNUPG:]" && $2 == "VALIDSIG" { print $NF; exit }') +if [[ $signer != "$EXPECTED_GPG_FINGERPRINT" ]]; then + echo 'Signed tag was not signed by the configured release key' >&2 + exit 1 +fi +echo "Tag $tag is signed by $signer" if [[ $(git rev-parse "$tag^{commit}") != "$commit" ]]; then echo 'Signed tag does not point to the expected commit' >&2 exit 1 @@ -79,6 +102,8 @@ fi if [[ $mode == repair ]]; then git push --force-with-lease="refs/tags/$tag:$commit" origin "refs/tags/$tag" -else +elif [[ $mode == create ]]; then git push origin "refs/tags/$tag" +else + git tag -d "$tag" fi diff --git a/scripts/verify-artifact-signatures.sh b/scripts/verify-artifact-signatures.sh new file mode 100755 index 00000000..e783d2b1 --- /dev/null +++ b/scripts/verify-artifact-signatures.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause + +# Checks that every artifact in a Maven staging repository has a detached +# signature made by the configured release key. + +set -euo pipefail + +repository=${1:?staging repository required} +: "${GPG_PUBLIC_KEY:?GPG_PUBLIC_KEY required}" +: "${EXPECTED_GPG_FINGERPRINT:?EXPECTED_GPG_FINGERPRINT required}" +if [[ ! $EXPECTED_GPG_FINGERPRINT =~ ^[0-9A-F]{40}$ ]]; then + echo 'Invalid expected release signing fingerprint' >&2 + exit 1 +fi +if [[ ! -d $repository ]]; then + echo "Staging repository $repository does not exist" >&2 + exit 1 +fi + +verify_home=$(mktemp -d) +trap 'gpgconf --kill gpg-agent >/dev/null 2>&1 || true; rm -rf "$verify_home"' EXIT +chmod 700 "$verify_home" +export GNUPGHOME=$verify_home +public_fingerprint=$(printf '%s\n' "$GPG_PUBLIC_KEY" | + gpg --batch --show-keys --with-colons | + awk -F: '$1 == "fpr" { print $10; exit }') +if [[ $public_fingerprint != "$EXPECTED_GPG_FINGERPRINT" ]]; then + echo 'Release public key fingerprint does not match the configured key' >&2 + exit 1 +fi +printf '%s\n' "$GPG_PUBLIC_KEY" | gpg --batch --quiet --import + +checked=0 +while IFS= read -r -d '' artifact; do + case $artifact in + *.asc | *.md5 | *.sha1 | *.sha256 | *.sha512 | */maven-metadata*) continue ;; + esac + if [[ ! -f $artifact.asc ]]; then + echo "Missing signature for ${artifact#"$repository"/}" >&2 + exit 1 + fi + signer=$(gpg --batch --status-fd 1 --verify "$artifact.asc" "$artifact" 2>/dev/null | + awk '$1 == "[GNUPG:]" && $2 == "VALIDSIG" { print $NF; exit }') || true + if [[ $signer != "$EXPECTED_GPG_FINGERPRINT" ]]; then + echo "Bad or unexpected signature on ${artifact#"$repository"/}" >&2 + exit 1 + fi + echo "Verified ${artifact#"$repository"/}" + checked=$((checked + 1)) +done < <(find "$repository" -type f -print0 | sort -z) + +if ((checked == 0)); then + echo "No artifacts found in $repository" >&2 + exit 1 +fi +echo "$checked artifacts are signed by $EXPECTED_GPG_FINGERPRINT"