Skip to content

Commit 18cdbb4

Browse files
authored
use scoped token for release workflow (#28484)
fetch a short-lived repo-scoped app token with `contents: write` and `workflows: write` for the `gh release create` call, dropping the workflow's permissions to `contents: read`. `STS_API_URL` secret has been set in the `release` environment
1 parent c3813a5 commit 18cdbb4

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎.github/secure-token-service.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
"on": ["workflow_dispatch"],
1616
"permissions": { "contents": "write", "pull_requests": "write" },
1717
"target": "ruff"
18+
},
19+
{
20+
"caller": "ruff",
21+
"environment": "release",
22+
"caller_workflow": "release.yml",
23+
"on": ["workflow_dispatch"],
24+
"permissions": { "contents": "write", "workflows": "write" },
25+
"target": "ruff"
1826
}
1927
]
2028
}

‎.github/workflows/release.yml‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,12 @@ jobs:
385385
# not block the rest of the release.
386386
if: ${{ always() && needs.host.result == 'success' && needs.release-gate.result == 'success' && (needs.custom-publish-pypi.result == 'skipped' || needs.custom-publish-pypi.result == 'success') && (needs.custom-publish-wasm.result == 'skipped' || needs.custom-publish-wasm.result == 'success') }}
387387
runs-on: "depot-ubuntu-24.04-4"
388+
environment:
389+
name: release
388390
permissions:
389391
"attestations": "write"
390-
"contents": "write"
392+
"contents": "read"
391393
"id-token": "write"
392-
env:
393-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
394394
steps:
395395
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
396396
with:
@@ -416,8 +416,20 @@ jobs:
416416
artifacts/*.ps1
417417
artifacts/*.zip
418418
artifacts/*.tar.gz
419+
- name: Get release token
420+
id: release-token
421+
uses: open-security-tools/ost-simple-sts@974a63a2daaaa40f7c6dec40d334f3da4421469e
422+
with:
423+
exchange-url: ${{ secrets.STS_API_URL }}/exchange
424+
audience: ${{ secrets.STS_API_URL }}
425+
repository: astral-sh/ruff
426+
# Workflow permission is required to create a release tag after `main` advances across workflow changes.
427+
permissions: |
428+
contents: write
429+
workflows: write
419430
- name: Create GitHub Release
420431
env:
432+
GH_TOKEN: ${{ steps.release-token.outputs.token }}
421433
PRERELEASE_FLAG: "${{ fromJson(needs.host.outputs.val).announcement_is_prerelease && '--prerelease' || '' }}"
422434
ANNOUNCEMENT_TITLE: "${{ fromJson(needs.host.outputs.val).announcement_title }}"
423435
ANNOUNCEMENT_BODY: "${{ fromJson(needs.host.outputs.val).announcement_github_body }}"

0 commit comments

Comments
 (0)