From a85cd54cd27efa353f74f746fc3c43155f0c2f7b Mon Sep 17 00:00:00 2001 From: darkobas Date: Mon, 16 Nov 2026 13:04:11 +0100 Subject: [PATCH 1/9] ci: create release tags only via an approved cut-release workflow --- .github/workflows/cut-release.yaml | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/cut-release.yaml diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml new file mode 100644 index 0000000..72dcd22 --- /dev/null +++ b/.github/workflows/cut-release.yaml @@ -0,0 +1,90 @@ +# Creates a release tag and publishes a GitHub release. Tag creation is restricted by a ruleset, so tags are +# only made here (as the bee-runner app) after a second person approves the +# `release` environment. The commit is resolved before approval, so the +# reviewer approves an exact SHA (shown in the run summary). +# The published release then triggers publish_docker.yaml. +name: Cut release +run-name: Cut ${{ inputs.tag }} from ${{ inputs.ref }} (by ${{ github.actor }}) + +on: + workflow_dispatch: + inputs: + tag: + description: "Tag to create, e.g. 1.1.12" + required: true + ref: + description: "Branch or full commit SHA to tag" + required: true + default: main + +permissions: {} + +concurrency: + group: cut-release + cancel-in-progress: false + +env: + # Allowed tag format for this repo. + TAG_PATTERN: '^[0-9]+\.[0-9]+\.[0-9]+$' + +jobs: + resolve: + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + sha: ${{ steps.resolve.outputs.sha }} + steps: + - name: Validate tag and resolve commit + id: resolve + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + TAG: ${{ inputs.tag }} + REF: ${{ inputs.ref }} + with: + script: | + const { TAG, REF, TAG_PATTERN } = process.env + const { owner, repo } = context.repo + if (!new RegExp(TAG_PATTERN).test(TAG)) { + return core.setFailed(`tag must match ${TAG_PATTERN}, got '${TAG}'`) + } + try { + await github.rest.git.getRef({ owner, repo, ref: `tags/${TAG}` }) + return core.setFailed(`tag ${TAG} already exists`) + } catch (e) { + if (e.status !== 404) throw e + } + const { data: c } = await github.rest.repos.getCommit({ owner, repo, ref: REF }) + core.setOutput('sha', c.sha) + core.summary + .addHeading(`${TAG} will tag ${c.sha.slice(0, 12)}`) + .addRaw(`[${c.commit.message.split('\n')[0]}](${c.html_url}) (${REF})`) + await core.summary.write() + + tag: + needs: resolve + runs-on: ubuntu-latest + environment: release + steps: + - name: Generate GitHub App token + id: app-token + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + app-id: ${{ secrets.BEE_RUNNER_APP_ID }} + private-key: ${{ secrets.BEE_RUNNER_KEY }} + # Least privilege: only creates the tag and the release. + permission-contents: write + + - name: Create tag and release + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + TAG: ${{ inputs.tag }} + SHA: ${{ needs.resolve.outputs.sha }} + with: + github-token: ${{ steps.app-token.outputs.token }} + script: | + const { TAG, SHA } = process.env + await github.rest.git.createRef({ ...context.repo, ref: `refs/tags/${TAG}`, sha: SHA }) + await github.rest.repos.createRelease({ ...context.repo, tag_name: TAG, name: TAG, generate_release_notes: true }) + core.summary.addHeading(`Tagged ${TAG} at ${SHA.slice(0, 12)}`) + await core.summary.write() From b70745b7a5a6b455c79723ca3e0dabdb27e70376 Mon Sep 17 00:00:00 2001 From: darkobas Date: Mon, 16 Nov 2026 13:37:06 +0100 Subject: [PATCH 2/9] ci: create release tags with the ethersphere-release app key from an environment The bee-runner key is an org secret, so any workflow on any branch can read it and mint a token that creates tags, bypassing the approval. The new release app's key lives only in this repo's release environment, which only runs from the default branch (and, for cut-release, after a second person approves). --- .github/workflows/cut-release.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml index 72dcd22..095b23f 100644 --- a/.github/workflows/cut-release.yaml +++ b/.github/workflows/cut-release.yaml @@ -1,5 +1,5 @@ # Creates a release tag and publishes a GitHub release. Tag creation is restricted by a ruleset, so tags are -# only made here (as the bee-runner app) after a second person approves the +# only made here (as the ethersphere-release app) after a second person approves the # `release` environment. The commit is resolved before approval, so the # reviewer approves an exact SHA (shown in the run summary). # The published release then triggers publish_docker.yaml. @@ -70,8 +70,8 @@ jobs: id: app-token uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 with: - app-id: ${{ secrets.BEE_RUNNER_APP_ID }} - private-key: ${{ secrets.BEE_RUNNER_KEY }} + app-id: ${{ vars.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_KEY }} # Least privilege: only creates the tag and the release. permission-contents: write From b14342c5e1c106d5168b23d8ec1afe2a375e1c35 Mon Sep 17 00:00:00 2001 From: darkobas Date: Mon, 16 Nov 2026 13:48:54 +0100 Subject: [PATCH 3/9] ci: name the release app correctly (bee-releaser) --- .github/workflows/cut-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml index 095b23f..5da30cd 100644 --- a/.github/workflows/cut-release.yaml +++ b/.github/workflows/cut-release.yaml @@ -1,5 +1,5 @@ # Creates a release tag and publishes a GitHub release. Tag creation is restricted by a ruleset, so tags are -# only made here (as the ethersphere-release app) after a second person approves the +# only made here (as the bee-releaser app) after a second person approves the # `release` environment. The commit is resolved before approval, so the # reviewer approves an exact SHA (shown in the run summary). # The published release then triggers publish_docker.yaml. From b17424f29247ae36391699aed3b3e2148857f361 Mon Sep 17 00:00:00 2001 From: darkobas Date: Mon, 16 Nov 2026 20:06:59 +0100 Subject: [PATCH 4/9] ci: scope Docker Hub credentials to the release-ci environment Publishing jobs now read DOCKERHUB_USERNAME/PASSWORD from the release-ci environment (per-repo token, limited to this repo's images; default branch and release tags only) instead of the shared org secret. --- .github/workflows/publish_docker.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish_docker.yaml b/.github/workflows/publish_docker.yaml index 85fbcde..f037fd9 100644 --- a/.github/workflows/publish_docker.yaml +++ b/.github/workflows/publish_docker.yaml @@ -5,6 +5,8 @@ on: jobs: docker-release: runs-on: ubuntu-latest + # Docker Hub credentials are scoped to this environment (default branch / release tags only). + environment: release-ci steps: - name: Checkout uses: actions/checkout@v4 From a5ada2ba0819e233a4e37083d474f0cc15eba788 Mon Sep 17 00:00:00 2001 From: darkobas Date: Tue, 17 Nov 2026 12:23:46 +0100 Subject: [PATCH 5/9] ci: only tag commits on the default branch or a release/* branch repos.getCommit also resolves commits that are on no branch, such as fork PR heads under refs/pull/*. Refuse to tag unless the commit is on the default branch or a release/* branch, and show that branch in the run summary. --- .github/workflows/cut-release.yaml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml index 5da30cd..adeab8f 100644 --- a/.github/workflows/cut-release.yaml +++ b/.github/workflows/cut-release.yaml @@ -13,7 +13,7 @@ on: description: "Tag to create, e.g. 1.1.12" required: true ref: - description: "Branch or full commit SHA to tag" + description: "Branch or full commit SHA to tag (must be on the default branch or a release/* branch)" required: true default: main @@ -55,10 +55,25 @@ jobs: if (e.status !== 404) throw e } const { data: c } = await github.rest.repos.getCommit({ owner, repo, ref: REF }) + // getCommit also resolves commits that are on no branch, e.g. fork PR heads + // (refs/pull/*). Only tag commits on the default branch or a release/* branch. + const def = context.payload.repository.default_branch + const branches = (await github.paginate(github.rest.repos.listBranches, { owner, repo, per_page: 100 })) + .map(b => b.name) + .filter(n => n === def || n.startsWith('release/')) + .sort((a, b) => (a === def ? -1 : b === def ? 1 : a.localeCompare(b))) + let onBranch = '' + for (const b of branches) { + const { data: cmp } = await github.rest.repos.compareCommitsWithBasehead({ owner, repo, basehead: `${b}...${c.sha}`, per_page: 1 }) + if (cmp.status === 'identical' || cmp.status === 'behind') { onBranch = b; break } + } + if (!onBranch) { + return core.setFailed(`${c.sha} is not on ${def} or a release/* branch, refusing to tag it`) + } core.setOutput('sha', c.sha) core.summary .addHeading(`${TAG} will tag ${c.sha.slice(0, 12)}`) - .addRaw(`[${c.commit.message.split('\n')[0]}](${c.html_url}) (${REF})`) + .addRaw(`[${c.commit.message.split('\n')[0]}](${c.html_url}) (${REF}, on ${onBranch})`) await core.summary.write() tag: From c06e16c510a7163e90eb97e568ee69cbbb234c3d Mon Sep 17 00:00:00 2001 From: darkobas Date: Wed, 18 Nov 2026 09:15:05 +0100 Subject: [PATCH 6/9] ci: escape commit subject and ref in the cut-release summary The run summary is what the release approver reviews. Escape the commit subject, ref and branch so a crafted subject can't alter it, and show the full SHA. --- .github/workflows/cut-release.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml index adeab8f..81cc953 100644 --- a/.github/workflows/cut-release.yaml +++ b/.github/workflows/cut-release.yaml @@ -71,9 +71,12 @@ jobs: return core.setFailed(`${c.sha} is not on ${def} or a release/* branch, refusing to tag it`) } core.setOutput('sha', c.sha) + // Escape everything user-controlled: the summary is what the release approver reviews. + const esc = s => s.replace(/[&<>"'`\[\]]/g, ch => `&#${ch.charCodeAt(0)};`) + const subject = c.commit.message.split('\n')[0] core.summary - .addHeading(`${TAG} will tag ${c.sha.slice(0, 12)}`) - .addRaw(`[${c.commit.message.split('\n')[0]}](${c.html_url}) (${REF}, on ${onBranch})`) + .addHeading(`${TAG} will tag ${c.sha}`) + .addRaw(`${esc(subject)} (${esc(REF)}, on ${esc(onBranch)})`, true) await core.summary.write() tag: From 14d6e4070d5328d7c5140dc8cce46415f2884df7 Mon Sep 17 00:00:00 2001 From: darkobas Date: Wed, 18 Nov 2026 11:38:47 +0100 Subject: [PATCH 7/9] ci: render the cut-release commit line as an HTML block A line that starts with an inline is still parsed as markdown by GitHub, so a commit URL in the subject was autolinked to another commit and a trailing backslash escaped . Wrap the line in

so it is an HTML block with no markdown processing, and escape backslashes too. --- .github/workflows/cut-release.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml index 81cc953..65ae74d 100644 --- a/.github/workflows/cut-release.yaml +++ b/.github/workflows/cut-release.yaml @@ -72,11 +72,12 @@ jobs: } core.setOutput('sha', c.sha) // Escape everything user-controlled: the summary is what the release approver reviews. - const esc = s => s.replace(/[&<>"'`\[\]]/g, ch => `&#${ch.charCodeAt(0)};`) + const esc = s => s.replace(/[&<>"'`\[\]\\]/g, ch => `&#${ch.charCodeAt(0)};`) const subject = c.commit.message.split('\n')[0] core.summary .addHeading(`${TAG} will tag ${c.sha}`) - .addRaw(`${esc(subject)} (${esc(REF)}, on ${esc(onBranch)})`, true) + //

makes it an HTML block, so GitHub applies no markdown (autolinks, \ escapes) inside. + .addRaw(`

${esc(subject)} (${esc(REF)}, on ${esc(onBranch)})

`, true) await core.summary.write() tag: From 6ec9f4470a7d07ad3d8f91b3e3d28f6b39603919 Mon Sep 17 00:00:00 2001 From: darkobas Date: Wed, 18 Nov 2026 12:05:52 +0100 Subject: [PATCH 8/9] ci: show only the SHA in the cut-release summary Putting the commit subject, ref and branch into the summary and escaping them was too fragile. Each escaping attempt was bypassed: first raw HTML in the subject, then GitHub's markdown processing inside an inline (autolinked commit URLs, a trailing backslash escaping ). The summary is what the release approver trusts, so it should not render any text an outsider can influence. The summary now shows only the full SHA (in , so GitHub does not shorten it), fixed text saying whether the commit is on the default branch, and a commit link built from the SHA. Also: - fail if the ref does not resolve to a 40-hex SHA - drop the free-form ref from run-name --- .github/workflows/cut-release.yaml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml index 65ae74d..23a5ba7 100644 --- a/.github/workflows/cut-release.yaml +++ b/.github/workflows/cut-release.yaml @@ -4,7 +4,7 @@ # reviewer approves an exact SHA (shown in the run summary). # The published release then triggers publish_docker.yaml. name: Cut release -run-name: Cut ${{ inputs.tag }} from ${{ inputs.ref }} (by ${{ github.actor }}) +run-name: Cut ${{ inputs.tag }} (by ${{ github.actor }}) on: workflow_dispatch: @@ -55,6 +55,9 @@ jobs: if (e.status !== 404) throw e } const { data: c } = await github.rest.repos.getCommit({ owner, repo, ref: REF }) + if (!/^[0-9a-f]{40}$/.test(c.sha ?? '')) { + return core.setFailed('ref did not resolve to a commit') + } // getCommit also resolves commits that are on no branch, e.g. fork PR heads // (refs/pull/*). Only tag commits on the default branch or a release/* branch. const def = context.payload.repository.default_branch @@ -71,13 +74,13 @@ jobs: return core.setFailed(`${c.sha} is not on ${def} or a release/* branch, refusing to tag it`) } core.setOutput('sha', c.sha) - // Escape everything user-controlled: the summary is what the release approver reviews. - const esc = s => s.replace(/[&<>"'`\[\]\\]/g, ch => `&#${ch.charCodeAt(0)};`) - const subject = c.commit.message.split('\n')[0] + // Only the SHA, a link built from it and fixed text: nothing an outsider controls is rendered. + // stops GitHub shortening the SHA into a 7-char commit reference. + const url = `https://github.com/${owner}/${repo}/commit/${c.sha}` core.summary - .addHeading(`${TAG} will tag ${c.sha}`) - //

makes it an HTML block, so GitHub applies no markdown (autolinks, \ escapes) inside. - .addRaw(`

${esc(subject)} (${esc(REF)}, on ${esc(onBranch)})

`, true) + .addHeading(`${TAG} will tag ${c.sha}`) + .addRaw(`

${onBranch === def ? 'On the default branch.' : 'NOT on the default branch (on a release branch).'}

`, true) + .addLink(url, url) await core.summary.write() tag: From 5d82ad36d6794ff2fd7778609c10fca70a6030f5 Mon Sep 17 00:00:00 2001 From: darkobas Date: Wed, 18 Nov 2026 15:07:20 +0100 Subject: [PATCH 9/9] ci: make the beeport cut-release tag job safe to re-run If createRelease failed after the tag was created, re-running the job failed with 'already exists' and left a tag without a release. Accept an existing tag only when it points at the approved SHA, and create the release only if it is missing. --- .github/workflows/cut-release.yaml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cut-release.yaml b/.github/workflows/cut-release.yaml index 23a5ba7..0cc00f8 100644 --- a/.github/workflows/cut-release.yaml +++ b/.github/workflows/cut-release.yaml @@ -106,7 +106,23 @@ jobs: github-token: ${{ steps.app-token.outputs.token }} script: | const { TAG, SHA } = process.env - await github.rest.git.createRef({ ...context.repo, ref: `refs/tags/${TAG}`, sha: SHA }) - await github.rest.repos.createRelease({ ...context.repo, tag_name: TAG, name: TAG, generate_release_notes: true }) + const { owner, repo } = context.repo + // Safe to re-run this job if createRelease failed after the tag was created: + // an existing tag is accepted only at the approved SHA, and the release is created only if missing. + try { + await github.rest.git.createRef({ owner, repo, ref: `refs/tags/${TAG}`, sha: SHA }) + } catch (e) { + if (e.status !== 422) throw e + const { data: t } = await github.rest.git.getRef({ owner, repo, ref: `tags/${TAG}` }) + if (t.object.sha !== SHA) { + return core.setFailed(`tag ${TAG} already exists at ${t.object.sha}, not at the approved ${SHA}`) + } + } + try { + await github.rest.repos.getReleaseByTag({ owner, repo, tag: TAG }) + } catch (e) { + if (e.status !== 404) throw e + await github.rest.repos.createRelease({ owner, repo, tag_name: TAG, name: TAG, generate_release_notes: true }) + } core.summary.addHeading(`Tagged ${TAG} at ${SHA.slice(0, 12)}`) await core.summary.write()