Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/verify-release-signing.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 29 additions & 4 deletions scripts/sign-release-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -72,13 +88,22 @@ 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
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
57 changes: 57 additions & 0 deletions scripts/verify-artifact-signatures.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading