Skip to content

Commit 2992f13

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 public repositories, the templates are intended to be applicable in public and private repositories both and so a small excess in permissions was chosen instead of the alternative of having to maintain separate variants of each workflow for use in public or private repos.
1 parent 94d73e5 commit 2992f13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+216
-12
lines changed

.github/workflows/check-ci-sync.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ on:
2727
jobs:
2828
check-sync:
2929
runs-on: ubuntu-latest
30+
permissions: {}
3031

3132
steps:
3233
- name: Checkout repository

.github/workflows/check-clang-format.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ on:
3939
jobs:
4040
validate:
4141
runs-on: ubuntu-latest
42+
permissions: {}
4243

4344
steps:
4445
- name: Checkout repository
@@ -60,6 +61,7 @@ jobs:
6061

6162
check-config:
6263
runs-on: ubuntu-latest
64+
permissions: {}
6365

6466
steps:
6567
- name: Checkout repository
@@ -136,6 +138,7 @@ jobs:
136138

137139
check-output:
138140
runs-on: ubuntu-latest
141+
permissions: {}
139142

140143
steps:
141144
- name: Checkout repository
@@ -195,6 +198,7 @@ jobs:
195198

196199
check-testdata:
197200
runs-on: ubuntu-latest
201+
permissions: {}
198202

199203
steps:
200204
- name: Checkout repository
@@ -211,6 +215,7 @@ jobs:
211215

212216
convert:
213217
runs-on: ubuntu-latest
218+
permissions: {}
214219

215220
steps:
216221
- name: Set environment variables

.github/workflows/check-community-health-sync.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ on:
3333
jobs:
3434
check-sync:
3535
runs-on: ubuntu-latest
36+
permissions: {}
3637

3738
steps:
3839
- name: Checkout repository

.github/workflows/check-config-sync.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
jobs:
2020
check-sync:
2121
runs-on: ubuntu-latest
22+
permissions: {}
2223

2324
steps:
2425
- name: Checkout repository

.github/workflows/check-dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ on:
2121
jobs:
2222
validate:
2323
runs-on: ubuntu-latest
24+
permissions: {}
2425

2526
steps:
2627
- name: Checkout repository

.github/workflows/check-eslint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ on:
2929
jobs:
3030
validate:
3131
runs-on: ubuntu-latest
32+
permissions: {}
3233

3334
steps:
3435
- name: Checkout repository

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
outputs:
1919
result: ${{ steps.determination.outputs.result }}
20+
permissions: {}
2021
steps:
2122
- name: Determine if the rest of the workflow should run
2223
id: determination
@@ -40,6 +41,8 @@ jobs:
4041
needs: run-determination
4142
if: needs.run-determination.outputs.result == 'true'
4243
runs-on: ubuntu-latest
44+
permissions:
45+
contents: read
4346

4447
steps:
4548
- name: Checkout repository
@@ -58,6 +61,8 @@ jobs:
5861
needs: run-determination
5962
if: needs.run-determination.outputs.result == 'true'
6063
runs-on: ubuntu-latest
64+
permissions:
65+
contents: read
6166

6267
steps:
6368
- name: Checkout repository

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
jobs:
1616
run-determination:
1717
runs-on: ubuntu-latest
18+
permissions: {}
1819
outputs:
1920
result: ${{ steps.determination.outputs.result }}
2021
steps:
@@ -40,6 +41,8 @@ jobs:
4041
needs: run-determination
4142
if: needs.run-determination.outputs.result == 'true'
4243
runs-on: ubuntu-latest
44+
permissions:
45+
contents: read
4346

4447
steps:
4548
- name: Set environment variables

.github/workflows/check-issue-templates.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ on:
2121
jobs:
2222
validate:
2323
runs-on: ubuntu-latest
24+
permissions: {}
2425

2526
steps:
2627
- name: Checkout repository

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ on:
2929
workflow_dispatch:
3030
repository_dispatch:
3131

32-
permissions:
33-
contents: read
34-
3532
jobs:
3633
run-determination:
3734
runs-on: ubuntu-latest
35+
permissions: {}
3836
outputs:
3937
result: ${{ steps.determination.outputs.result }}
4038
steps:
@@ -60,6 +58,8 @@ jobs:
6058
needs: run-determination
6159
if: needs.run-determination.outputs.result == 'true'
6260
runs-on: ubuntu-latest
61+
permissions:
62+
contents: read
6363

6464
steps:
6565
- name: Checkout repository

0 commit comments

Comments
 (0)