Skip to content

Commit bdb66b1

Browse files
committed
Configure permissions of GITHUB_TOKEN in workflows
`GITHUB_TOKEN` is an access token provided automatically by GitHub Actions. The default permissions of this token for workflow runs in a trusted context (i.e., not triggered by a PR from a fork) are set in the enterprise/organization/ epository'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 of the permissions provided to the token, which are used here to configure the workflows for only the permissions they require in each job. The automatic permissions downgrade from write to read for workflows triggered by events generated by a PR from a fork is unaffected. Even when all permissions are withheld (`permissions: {}`), the token still provides the authenticated API request rate limiting allowance, which is a common use 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 for this public repository, the standardized "Sync Labels" workflow template is 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 template unmodified.
1 parent ed6838d commit bdb66b1

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

.github/workflows/compile-examples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ on:
2323
jobs:
2424
compile-test:
2525
runs-on: ubuntu-latest
26+
permissions: {}
2627

2728
env:
2829
# sketch paths to compile (recursive) for all boards

.github/workflows/report-size-deltas.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
jobs:
88
report:
99
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
1012

1113
steps:
1214
- name: Comment size deltas reports to PRs

.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:
@@ -81,6 +84,9 @@ jobs:
8184
sync:
8285
needs: download
8386
runs-on: ubuntu-latest
87+
permissions:
88+
contents: read
89+
issues: write
8490

8591
steps:
8692
- name: Set environment variables

0 commit comments

Comments
 (0)