Skip to content

Commit 327fcf8

Browse files
committed
GitHub workflows: limit "content:write" to minimum
permissions can be defined on workflow and job level, but not on step level. Currently permissions are defined at workflow level which is not ideal. Create a new "release_candidate" job so that we can minimize the "content:write" permission exposure. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 53521bf commit 327fcf8

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

.github/workflows/cd.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ on:
66
tags:
77
- v*
88

9-
permissions:
10-
contents: write
9+
permissions: {}
1110

1211
jobs:
1312
test:
@@ -17,8 +16,6 @@ jobs:
1716
name: Build
1817
runs-on: ubuntu-latest
1918
needs: test
20-
outputs:
21-
release_id: ${{ steps.gh-release.outputs.id }}
2219
steps:
2320
- name: Checkout release tag
2421
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
@@ -36,6 +33,30 @@ jobs:
3633
- name: Build binary wheel and source tarball
3734
run: python3 -m build --sdist --wheel --outdir dist/ .
3835

36+
- name: Store build artifacts
37+
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb
38+
# NOTE: The GitHub release page contains the release artifacts too, but using
39+
# GitHub upload/download actions seems robuster: there is no need to compute
40+
# download URLs and tampering with artifacts between jobs is more limited.
41+
with:
42+
name: build-artifacts
43+
path: dist
44+
45+
candidate_release:
46+
name: Release candidate on Github for review
47+
runs-on: ubuntu-latest
48+
needs: build
49+
permissions:
50+
contents: write # to modify GitHub releases
51+
outputs:
52+
release_id: ${{ steps.gh-release.outputs.id }}
53+
steps:
54+
- name: Fetch build artifacts
55+
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7
56+
with:
57+
name: build-artifacts
58+
path: dist
59+
3960
- id: gh-release
4061
name: Publish GitHub release candidate
4162
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
@@ -45,20 +66,14 @@ jobs:
4566
body: "Release waiting for review..."
4667
files: dist/*
4768

48-
- name: Store build artifacts
49-
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb
50-
# NOTE: The GitHub release page contains the release artifacts too, but using
51-
# GitHub upload/download actions seems robuster: there is no need to compute
52-
# download URLs and tampering with artifacts between jobs is more limited.
53-
with:
54-
name: build-artifacts
55-
path: dist
5669

5770
release:
5871
name: Release
5972
runs-on: ubuntu-latest
60-
needs: build
73+
needs: candidate_release
6174
environment: release
75+
permissions:
76+
contents: write # to modify GitHub releases
6277
steps:
6378
- name: Fetch build artifacts
6479
uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7
@@ -79,7 +94,7 @@ jobs:
7994
await github.rest.repos.updateRelease({
8095
owner: context.repo.owner,
8196
repo: context.repo.repo,
82-
release_id: '${{ needs.build.outputs.release_id }}',
97+
release_id: '${{ needs.candidate_release.outputs.release_id }}',
8398
name: '${{ github.ref_name }}',
8499
body: 'See [CHANGELOG.md](https://github.com/' +
85100
context.repo.owner + '/' + context.repo.repo +

0 commit comments

Comments
 (0)