From edfcf9e2b3a21ac6d6f279b847f281e82a34fe6d Mon Sep 17 00:00:00 2001 From: Jim Manico Date: Sat, 7 Nov 2026 18:21:58 -0800 Subject: [PATCH] Sign release tags explicitly in publication workflow --- .github/workflows/release.yml | 7 +++ .github/workflows/repair-release-tag.yml | 32 ++++++++++ MODELS.md | 4 ++ pom.xml | 4 +- scripts/sign-release-tag.sh | 75 ++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/repair-release-tag.yml create mode 100755 scripts/sign-release-tag.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6c6ed8e..e47a661a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -106,6 +106,13 @@ jobs: id: build run: ./mvnw -ntp -B -Ppublication + - name: Sign release tag + 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)" + - name: Release env: JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/repair-release-tag.yml b/.github/workflows/repair-release-tag.yml new file mode 100644 index 00000000..1a8c5172 --- /dev/null +++ b/.github/workflows/repair-release-tag.yml @@ -0,0 +1,32 @@ +name: Repair release tag + +on: + workflow_dispatch: + inputs: + version: + description: 'Version of the published release to repair' + required: true + type: string + commit: + description: 'Exact release commit (40-character SHA)' + required: true + type: string + +jobs: + repair: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + - name: Sign and replace lightweight tag + env: + VERSION: ${{ inputs.version }} + RELEASE_COMMIT: ${{ inputs.commit }} + 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" "$RELEASE_COMMIT" repair diff --git a/MODELS.md b/MODELS.md index badf57e5..b46ce863 100644 --- a/MODELS.md +++ b/MODELS.md @@ -117,3 +117,7 @@ Report actual checks and review coverage, unresolved findings, and compatibility impact. Record user-visible changes under `Next release` in `change_log.md`. Follow the README contribution process and AGENTS.md release restrictions; model recommendations do not replace required human approvals. +For releases, verify the published tag resolves to the release commit and is +an annotated PGP-signed tag (`git cat-file -t` and `git tag -v`). JReleaser's +GitHub `sign` option signs commits, not tags; check the actual remote tag type +and signature after publication. diff --git a/pom.xml b/pom.xml index 99777097..3bee8fa8 100644 --- a/pom.xml +++ b/pom.xml @@ -362,8 +362,8 @@ application while protecting against XSS. release-{{projectVersion}} Release {{projectVersion}} - - true + + true ALWAYS true diff --git a/scripts/sign-release-tag.sh b/scripts/sign-release-tag.sh new file mode 100755 index 00000000..3c549114 --- /dev/null +++ b/scripts/sign-release-tag.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause + +set -euo pipefail + +tag=${1:?release tag required} +commit=${2:?release commit required} +mode=${3:-create} + +if [[ ! $tag =~ ^release-[0-9]{8}\.[0-9]+$ || ! $commit =~ ^[0-9a-f]{40}$ ]]; then + echo 'Invalid release tag or commit' >&2 + exit 1 +fi +if [[ $mode != create && $mode != repair ]]; then + echo 'Mode must be create or repair' >&2 + exit 1 +fi +: "${GPG_SECRET_KEY:?GPG_SECRET_KEY required}" +: "${GPG_PUBLIC_KEY:?GPG_PUBLIC_KEY required}" +: "${GPG_PASSPHRASE:?GPG_PASSPHRASE required}" + +remote_ref=$(git ls-remote --refs origin "refs/tags/$tag") +if [[ $mode == create ]]; then + if [[ -n $remote_ref ]] || git show-ref --verify --quiet "refs/tags/$tag"; then + echo "Tag $tag already exists" >&2 + exit 1 + fi +else + if [[ $remote_ref != "$commit"$'\t'"refs/tags/$tag" ]]; then + echo "Remote tag $tag has changed or is not a lightweight tag at $commit" >&2 + exit 1 + fi + if [[ $(git rev-parse "refs/tags/$tag^{commit}") != "$commit" || + $(git cat-file -t "refs/tags/$tag") != commit ]]; then + echo "Local tag $tag is not a lightweight tag at $commit" >&2 + exit 1 + fi +fi + +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 +printf '%s\n' "$GPG_PUBLIC_KEY" | gpg --batch --quiet --import +printf '%s\n' "$GPG_SECRET_KEY" | gpg --batch --quiet --import + +fingerprint=$(gpg --batch --with-colons --list-secret-keys | + awk -F: '$1 == "sec" { primary = 1; next } $1 == "fpr" && primary { print $10; primary = 0 }') +if [[ ! $fingerprint =~ ^[0-9A-F]{40}$ ]]; then + echo 'Expected exactly one release signing key' >&2 + exit 1 +fi + +cat > "$signing_home/gpg-for-git" <<'EOF' +#!/usr/bin/env bash +exec gpg --batch --pinentry-mode loopback --passphrase-fd 3 "$@" 3<<<"$GPG_PASSPHRASE" +EOF +chmod 700 "$signing_home/gpg-for-git" + +if [[ $mode == repair ]]; then + git tag -d "$tag" +fi +git -c "gpg.program=$signing_home/gpg-for-git" tag -s -u "$fingerprint" \ + -m "Release ${tag#release-}" "$tag" "$commit" +git tag -v "$tag" +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 + git push origin "refs/tags/$tag" +fi