Skip to content

Commit f41a58c

Browse files
committed
Make GHA permissions explicit and often narrower
This adds `permissions` keys at workflow or job level in a number of places, usually specifying minimal required permissions. When a `permissions` key contains at least one subkey setting some permission (in any way), all permissions it does not have subkeys for are treated as if they were present with a value of `none`. This relies on that rather than listing all unneeded permissions everywhere with `none`. So most `permissions` added here have only `contents: read`, and: - The only place where `none` is specified explicitly is in the CIFuzz workflow, where no permissions (of those controllable through `permissions`) are needed. - The only place any `write` permissions are specified are `contents: write` in the jobs of the release workflow that need it. All jobs involved in preparing a release currently have at least one step that requires this. But `contents: read` is still applied at the workflow level, because the `installation` job (which tests installing) does not need any `write` permissions. Note that some jobs that don't have any write permissions of the kind that is controlled under a `permissions` key do still perform writes to data accessible outside of their run: caching (including creating new caches), and uploading artifacts, still works. Relevant documentation: - https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#permissions - https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions - https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps
1 parent 7eeeee2 commit f41a58c

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
- main
1414
workflow_dispatch:
1515

16+
permissions:
17+
contents: read
18+
1619
env:
1720
CARGO_TERM_COLOR: always
1821
CLICOLOR: 1

.github/workflows/cifuzz.yml

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ jobs:
2020
Fuzzing:
2121
runs-on: ubuntu-latest
2222

23+
permissions:
24+
contents: none # The fuzzing actions don't use our github.token at all.
25+
2326
steps:
2427
- name: Build Fuzzers
2528
id: build

.github/workflows/cron.yml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
- cron: '0 13,1 * * *'
66
workflow_dispatch:
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
stress:
1013
runs-on: ubuntu-latest

.github/workflows/msrv.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
- main
1414
workflow_dispatch:
1515

16+
permissions:
17+
contents: read
18+
1619
jobs:
1720
check-msrv:
1821
name: cargo check MSRV

.github/workflows/release.yml

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
- 'v*'
1313
workflow_dispatch:
1414

15+
permissions:
16+
contents: read # Set more permissively in jobs that need `write`.
17+
1518
defaults:
1619
run:
1720
shell: bash
@@ -21,6 +24,9 @@ jobs:
2124
create-release:
2225
runs-on: ubuntu-latest
2326

27+
permissions:
28+
contents: write
29+
2430
# env:
2531
# # Set to force version number, e.g., when no tag exists.
2632
# VERSION: TEST-0.0.0
@@ -204,6 +210,9 @@ jobs:
204210

205211
runs-on: ${{ matrix.os }}
206212

213+
permissions:
214+
contents: write
215+
207216
env:
208217
RUST_BACKTRACE: '1' # Emit backtraces on panics.
209218
CARGO_TERM_COLOR: always
@@ -295,6 +304,9 @@ jobs:
295304
# These features need to be exactly the same as the features in build-release.
296305
feature: [ small, lean, max, max-pure ]
297306

307+
permissions:
308+
contents: write
309+
298310
env:
299311
BASH_ENV: ./helpers.sh
300312
REPOSITORY: ${{ github.repository }}
@@ -354,6 +366,9 @@ jobs:
354366

355367
needs: [ create-release, build-release, build-macos-universal2-release ]
356368

369+
permissions:
370+
contents: write
371+
357372
env:
358373
REPOSITORY: ${{ github.repository }}
359374
VERSION: ${{ needs.create-release.outputs.version }}

0 commit comments

Comments
 (0)