Skip to content

Commit 95b5035

Browse files
committed
Configure permissions of GITHUB_TOKEN in workflows
`GITHUB_TOKEN` is an access token that is automatically generated and made accessible for use in GitHub Actions workflow runs. The global default permissions of this token for workflow runs in a trusted context (i.e., not triggered by a `pull_request` event from a fork) are set in the GiHub enterprise/organization/repository's administrative settings, giving it either read-only or write permissions in all scopes. In the case of a read-only default configuration, any workflow operations that require write permissions would fail with an error like: > 403: Resource not accessible by integration In the case of a write default configuration, workflows have unnecessary permissions, which violates the security principle of least privilege. For this reason, GitHub Actions now allows fine grained control at a per-workflow or per-workflow job scope of the permissions provided to the token. This is done using the `permissions` workflow key, which is used here to configure the workflows for only the permissions require by each individual job. I chose to always configure permissions at the job level even though in some cases the same permissions configuration could be used for all jobs in a workflow. Even if functionally equivalent, I think it is semantically more appropriate to always set the permissions at the job scope since the intention is to make the most granular possible permissions configuration. Hopefully this approach will increase the likelihood that appropriate permissions configurations will be made in any additional jobs that are added to the workflows in the future. The automatic permissions downgrade from write to read for workflow runs in an untrusted context (e.g., triggered by a `pull_request` event from a fork) is unaffected by this change. Even when all permissions are withheld (`permissions: {}`), the token still provides the authenticated API request rate limiting allowance (authenticating API requests to avoid rate limiting is a one of the uses of the token in these workflows). Read permissions are required in the "contents" scope in order to checkout private repositories. Even though those permissions are not required when the workflows are installed in this public repository, the templates are intended to be applicable in public and private repositories both and so a small excess in permissions was chosen in order to use the upstream templates unmodified.
1 parent ab0590f commit 95b5035

21 files changed

+83
-0
lines changed

.github/workflows/check-certificates.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
(github.event_name != 'pull_request' && github.repository == 'arduino/arduino-lint') ||
2828
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'arduino/arduino-lint')
2929
runs-on: ubuntu-latest
30+
permissions: {}
3031
strategy:
3132
fail-fast: false
3233

.github/workflows/check-code-generation-task.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
runs-on: ubuntu-latest
2929
outputs:
3030
result: ${{ steps.determination.outputs.result }}
31+
permissions: {}
3132
steps:
3233
- name: Determine if the rest of the workflow should run
3334
id: determination
@@ -51,6 +52,7 @@ jobs:
5152
needs: run-determination
5253
if: needs.run-determination.outputs.result == 'true'
5354
runs-on: ubuntu-latest
55+
permissions: {}
5456

5557
steps:
5658
- name: Checkout local repository

.github/workflows/check-general-formatting-task.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ on:
1414
jobs:
1515
check:
1616
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1719

1820
steps:
1921
- name: Set environment variables

.github/workflows/check-go-dependencies-task.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ on:
3737
jobs:
3838
run-determination:
3939
runs-on: ubuntu-latest
40+
permissions: {}
4041
outputs:
4142
result: ${{ steps.determination.outputs.result }}
4243
steps:
@@ -62,6 +63,8 @@ jobs:
6263
needs: run-determination
6364
if: needs.run-determination.outputs.result == 'true'
6465
runs-on: ubuntu-latest
66+
permissions:
67+
contents: read
6568

6669
steps:
6770
- name: Checkout repository
@@ -118,6 +121,8 @@ jobs:
118121
needs: run-determination
119122
if: needs.run-determination.outputs.result == 'true'
120123
runs-on: ubuntu-latest
124+
permissions:
125+
contents: read
121126

122127
steps:
123128
- name: Checkout repository

.github/workflows/check-go-task.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ on:
2828
jobs:
2929
run-determination:
3030
runs-on: ubuntu-latest
31+
permissions: {}
3132
outputs:
3233
result: ${{ steps.determination.outputs.result }}
3334
steps:
@@ -54,6 +55,8 @@ jobs:
5455
needs: run-determination
5556
if: needs.run-determination.outputs.result == 'true'
5657
runs-on: ubuntu-latest
58+
permissions:
59+
contents: read
5760

5861
strategy:
5962
fail-fast: false
@@ -89,6 +92,8 @@ jobs:
8992
needs: run-determination
9093
if: needs.run-determination.outputs.result == 'true'
9194
runs-on: ubuntu-latest
95+
permissions:
96+
contents: read
9297

9398
strategy:
9499
fail-fast: false
@@ -127,6 +132,8 @@ jobs:
127132
needs: run-determination
128133
if: needs.run-determination.outputs.result == 'true'
129134
runs-on: ubuntu-latest
135+
permissions:
136+
contents: read
130137

131138
strategy:
132139
fail-fast: false
@@ -165,6 +172,8 @@ jobs:
165172
needs: run-determination
166173
if: needs.run-determination.outputs.result == 'true'
167174
runs-on: ubuntu-latest
175+
permissions:
176+
contents: read
168177

169178
strategy:
170179
fail-fast: false
@@ -203,6 +212,8 @@ jobs:
203212
needs: run-determination
204213
if: needs.run-determination.outputs.result == 'true'
205214
runs-on: ubuntu-latest
215+
permissions:
216+
contents: read
206217

207218
strategy:
208219
fail-fast: false

.github/workflows/check-license.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ on:
3131
jobs:
3232
check-license:
3333
runs-on: ubuntu-latest
34+
permissions:
35+
contents: read
3436

3537
steps:
3638
- name: Checkout repository

.github/workflows/check-markdown-task.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ on:
3636
jobs:
3737
lint:
3838
runs-on: ubuntu-latest
39+
permissions:
40+
contents: read
3941

4042
steps:
4143
- name: Checkout repository
@@ -55,6 +57,8 @@ jobs:
5557

5658
links:
5759
runs-on: ubuntu-latest
60+
permissions:
61+
contents: read
5862

5963
steps:
6064
- name: Checkout repository

.github/workflows/check-mkdocs-task.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ on:
3737
jobs:
3838
check:
3939
runs-on: ubuntu-latest
40+
permissions:
41+
contents: read
4042

4143
steps:
4244
- name: Checkout repository

.github/workflows/check-prettier-formatting-task.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ on:
201201
jobs:
202202
check:
203203
runs-on: ubuntu-latest
204+
permissions:
205+
contents: read
204206

205207
steps:
206208
- name: Checkout repository

.github/workflows/check-python-task.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ on:
3333
jobs:
3434
lint:
3535
runs-on: ubuntu-latest
36+
permissions:
37+
contents: read
3638

3739
steps:
3840
- name: Checkout repository
@@ -60,6 +62,8 @@ jobs:
6062

6163
formatting:
6264
runs-on: ubuntu-latest
65+
permissions:
66+
contents: read
6367

6468
steps:
6569
- name: Checkout repository

.github/workflows/check-shell-task.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
lint:
2828
name: ${{ matrix.configuration.name }}
2929
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
3032

3133
env:
3234
# See: https://github.com/koalaman/shellcheck/releases/latest
@@ -89,6 +91,8 @@ jobs:
8991

9092
formatting:
9193
runs-on: ubuntu-latest
94+
permissions:
95+
contents: read
9296

9397
steps:
9498
- name: Set environment variables
@@ -132,6 +136,8 @@ jobs:
132136

133137
executable:
134138
runs-on: ubuntu-latest
139+
permissions:
140+
contents: read
135141

136142
steps:
137143
- name: Checkout repository

.github/workflows/check-workflows-task.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ on:
2020
jobs:
2121
validate:
2222
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
2325

2426
steps:
2527
- name: Checkout repository

.github/workflows/deploy-cobra-mkdocs-versioned-poetry.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ on:
3232
jobs:
3333
publish-determination:
3434
runs-on: ubuntu-latest
35+
permissions: {}
3536
outputs:
3637
result: ${{ steps.determination.outputs.result }}
3738
steps:
@@ -51,6 +52,8 @@ jobs:
5152
runs-on: ubuntu-latest
5253
needs: publish-determination
5354
if: needs.publish-determination.outputs.result == 'true'
55+
permissions:
56+
contents: write
5457

5558
steps:
5659
- name: Checkout repository

.github/workflows/publish-go-nightly-task.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ on:
2121
jobs:
2222
create-nightly-artifacts:
2323
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
2426

2527
strategy:
2628
matrix:
@@ -66,6 +68,9 @@ jobs:
6668
checksum-darwin_amd64: ${{ steps.re-package.outputs.checksum-darwin_amd64 }}
6769
checksum-darwin_arm64: ${{ steps.re-package.outputs.checksum-darwin_arm64 }}
6870

71+
permissions:
72+
contents: read
73+
6974
env:
7075
GON_CONFIG_PATH: gon.config.hcl
7176

@@ -166,6 +171,7 @@ jobs:
166171
publish-nightly:
167172
runs-on: ubuntu-latest
168173
needs: notarize-macos
174+
permissions: {}
169175

170176
steps:
171177
- name: Download artifact
@@ -194,6 +200,7 @@ jobs:
194200
runs-on: ubuntu-latest
195201
needs: publish-nightly
196202
if: failure() # Run if publish-nightly or any of its job dependencies failed
203+
permissions: {}
197204

198205
steps:
199206
- name: Report failure

.github/workflows/publish-go-tester-task.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
runs-on: ubuntu-latest
3535
outputs:
3636
result: ${{ steps.determination.outputs.result }}
37+
permissions: {}
3738
steps:
3839
- name: Determine if the rest of the workflow should run
3940
id: determination
@@ -57,6 +58,7 @@ jobs:
5758
needs: run-determination
5859
if: needs.run-determination.outputs.result == 'true'
5960
runs-on: ubuntu-latest
61+
permissions: {}
6062
outputs:
6163
prefix: ${{ steps.calculation.outputs.prefix }}
6264
steps:
@@ -75,6 +77,8 @@ jobs:
7577
needs: package-name-prefix
7678
name: Build ${{ matrix.os.name }}
7779
runs-on: ubuntu-latest
80+
permissions:
81+
contents: read
7882

7983
strategy:
8084
matrix:
@@ -135,6 +139,8 @@ jobs:
135139
- build
136140
- package-name-prefix
137141
runs-on: ubuntu-latest
142+
permissions:
143+
contents: read
138144

139145
steps:
140146
- name: Download build artifacts

.github/workflows/release-go-task.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ on:
1818
jobs:
1919
create-release-artifacts:
2020
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
2123

2224
strategy:
2325
matrix:
@@ -71,6 +73,8 @@ jobs:
7173
outputs:
7274
checksum-darwin_amd64: ${{ steps.re-package.outputs.checksum-darwin_amd64 }}
7375
checksum-darwin_arm64: ${{ steps.re-package.outputs.checksum-darwin_arm64 }}
76+
permissions:
77+
contents: read
7478

7579
env:
7680
GON_CONFIG_PATH: gon.config.hcl
@@ -172,6 +176,8 @@ jobs:
172176
create-release:
173177
runs-on: ubuntu-latest
174178
needs: notarize-macos
179+
permissions:
180+
contents: write
175181

176182
steps:
177183
- name: Download artifact

.github/workflows/spell-check-task.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ on:
1818
jobs:
1919
spellcheck:
2020
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
2123

2224
steps:
2325
- name: Checkout repository

.github/workflows/sync-labels.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ env:
2424
jobs:
2525
check:
2626
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
2729

2830
steps:
2931
- name: Checkout repository
@@ -55,6 +57,7 @@ jobs:
5557
download:
5658
needs: check
5759
runs-on: ubuntu-latest
60+
permissions: {}
5861

5962
strategy:
6063
matrix:
@@ -82,6 +85,9 @@ jobs:
8285
sync:
8386
needs: download
8487
runs-on: ubuntu-latest
88+
permissions:
89+
contents: read
90+
issues: write
8591

8692
steps:
8793
- name: Set environment variables

.github/workflows/test-go-integration-task.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
runs-on: ubuntu-latest
3939
outputs:
4040
result: ${{ steps.determination.outputs.result }}
41+
permissions: {}
4142
steps:
4243
- name: Determine if the rest of the workflow should run
4344
id: determination
@@ -60,6 +61,8 @@ jobs:
6061
test:
6162
needs: run-determination
6263
if: needs.run-determination.outputs.result == 'true'
64+
permissions:
65+
contents: read
6366

6467
strategy:
6568
matrix:

.github/workflows/test-go-task.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
runs-on: ubuntu-latest
3535
outputs:
3636
result: ${{ steps.determination.outputs.result }}
37+
permissions: {}
3738
steps:
3839
- name: Determine if the rest of the workflow should run
3940
id: determination
@@ -57,6 +58,8 @@ jobs:
5758
name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
5859
needs: run-determination
5960
if: needs.run-determination.outputs.result == 'true'
61+
permissions:
62+
contents: read
6063

6164
strategy:
6265
fail-fast: false

0 commit comments

Comments
 (0)