From 86fcb0719e950d45605e412d844546edeba3d18b Mon Sep 17 00:00:00 2001 From: Martin Mitrevski Date: Wed, 25 Nov 2026 10:34:59 +0100 Subject: [PATCH 1/3] ci(release): run publish and upload in a release environment and verify publish_tag Run the jobs that use the signing, Maven Central and R2 credentials in the release environment, so those secrets can move out of org scope. Check out publish_tag as refs/tags/, and publish it only if its commit is on the release branch the run was dispatched from. Part of SEC-2514, SEC-2515. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7c278e7e..1926db70 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -225,6 +225,9 @@ jobs: (inputs.publish_tag != '' || needs.release.outputs.release_created == 'true') runs-on: { group: github-public-amd64 } timeout-minutes: 30 + # The signing key and the Maven Central credentials belong in this environment's secrets, + # not in org or repository secrets that a workflow on any branch can read. + environment: release permissions: contents: read outputs: @@ -241,11 +244,39 @@ jobs: - uses: actions/checkout@v5.0.1 with: - ref: ${{ steps.target.outputs.tag }} + # refs/tags/ so that a publish_tag naming a branch or a SHA is not checked out. + ref: refs/tags/${{ steps.target.outputs.tag }} + # Full history, for the ancestry check below. + fetch-depth: 0 # The Gradle build runs project code, and nothing here writes to the # repository, so do not leave GITHUB_TOKEN in .git/config. persist-credentials: false + # publish_tag is free text, so without this any tag, including one pushed on a commit + # that was never reviewed, could be signed and published. Only publish a tag whose + # commit is already on the release branch this run belongs to. + - name: Verify the tag is on this release branch + env: + TAG: ${{ steps.target.outputs.tag }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: | + case "$GITHUB_REF_NAME" in + "$DEFAULT_BRANCH"|*.x) ;; + *) + echo "::error::Publishing runs only from ${DEFAULT_BRANCH} or a *.x release branch, not ${GITHUB_REF_NAME}." + exit 1 + ;; + esac + if ! commit="$(git rev-parse --verify --quiet "refs/tags/${TAG}^{commit}")"; then + echo "::error::${TAG} is not a tag of this repository." + exit 1 + fi + if ! git merge-base --is-ancestor "$commit" "$GITHUB_SHA"; then + echo "::error::Tag ${TAG} points at ${commit}, which is not on ${GITHUB_REF_NAME}. Dispatch the workflow from the branch that release was cut from." + exit 1 + fi + echo "Tag ${TAG} (${commit}) is on ${GITHUB_REF_NAME}." + - name: Setup JDK 17 uses: actions/setup-java@v5.1.0 with: @@ -304,6 +335,9 @@ jobs: if: ${{ !cancelled() && needs.publish.result == 'success' && contains(inputs.publish-targets || 'streamRepo', 'streamRepo') }} runs-on: { group: github-public-amd64 } timeout-minutes: 30 + # The R2 credential belongs in this environment's secrets, for the same reason as the + # signing key above. + environment: release permissions: contents: read steps: From b3add571d4daf8addbfd2ca0f10e0d3342a095b1 Mon Sep 17 00:00:00 2001 From: Martin Mitrevski Date: Wed, 25 Nov 2026 10:49:25 +0100 Subject: [PATCH 2/3] ci(release): require an exact tag and an N.x branch in the publish_tag check Review follow-up. Reject revision syntax such as v1.2.3~1, which resolved to an untagged commit, and accept only the default branch or a branch named N.x, since *.x also matched feature/foo.x. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1926db70..8ead676d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -260,17 +260,19 @@ jobs: TAG: ${{ steps.target.outputs.tag }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | - case "$GITHUB_REF_NAME" in - "$DEFAULT_BRANCH"|*.x) ;; - *) - echo "::error::Publishing runs only from ${DEFAULT_BRANCH} or a *.x release branch, not ${GITHUB_REF_NAME}." - exit 1 - ;; - esac - if ! commit="$(git rev-parse --verify --quiet "refs/tags/${TAG}^{commit}")"; then + # The environment's deployment branches are what enforce this; the check here only + # gives a clear error before they are configured. + if [ "$GITHUB_REF" != "refs/heads/${DEFAULT_BRANCH}" ] && [[ ! "$GITHUB_REF" =~ ^refs/heads/[0-9]+\.x$ ]]; then + echo "::error::Publishing runs only from ${DEFAULT_BRANCH} or an N.x release branch, not ${GITHUB_REF}." + exit 1 + fi + # Exactly a tag. Revision syntax such as v1.2.3~1 would otherwise resolve to a commit + # that was never tagged. + if ! git show-ref --verify --quiet "refs/tags/${TAG}"; then echo "::error::${TAG} is not a tag of this repository." exit 1 fi + commit="$(git rev-parse "refs/tags/${TAG}^{commit}")" if ! git merge-base --is-ancestor "$commit" "$GITHUB_SHA"; then echo "::error::Tag ${TAG} points at ${commit}, which is not on ${GITHUB_REF_NAME}. Dispatch the workflow from the branch that release was cut from." exit 1 From 8d6161b78eedef248542a792206775e29dd2211f Mon Sep 17 00:00:00 2001 From: Martin Mitrevski Date: Wed, 25 Nov 2026 11:12:34 +0100 Subject: [PATCH 3/3] ci(release): accept N.M.x release branches in the publish_tag check The workflow triggers on any *.x branch, so a 4.1.x hotfix branch has to pass this check too. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8ead676d..cff8fec2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -262,7 +262,7 @@ jobs: run: | # The environment's deployment branches are what enforce this; the check here only # gives a clear error before they are configured. - if [ "$GITHUB_REF" != "refs/heads/${DEFAULT_BRANCH}" ] && [[ ! "$GITHUB_REF" =~ ^refs/heads/[0-9]+\.x$ ]]; then + if [ "$GITHUB_REF" != "refs/heads/${DEFAULT_BRANCH}" ] && [[ ! "$GITHUB_REF" =~ ^refs/heads/[0-9]+(\.[0-9]+)*\.x$ ]]; then echo "::error::Publishing runs only from ${DEFAULT_BRANCH} or an N.x release branch, not ${GITHUB_REF}." exit 1 fi