Skip to content

Commit e2bb1ef

Browse files
committed
GH Actions: set permissions for each workflow/job
> Users frequently over-scope their workflow and job permissions, or set broad workflow-level permissions without realizing that all jobs inherit those permissions. > > Furthermore, users often don't realize that the _default_ `GITHUB_TOKEN` permissions can be very broad, meaning that workflows that don't configure any permissions at all can _still_ provide excessive credentials to their individual jobs. > > **Remediation** > In general, permissions should be declared as minimally as possible, and as close to their usage site as possible. > > In practice, this means that workflows should almost always set `permissions: {}` at the workflow level to disable all permissions by default, and then set specific job-level permissions as needed. Needed permissions have been verified using the monitor action from GitHubSecurityLab. Refs: * https://docs.zizmor.sh/audits/#excessive-permissions * https://github.com/GitHubSecurityLab/actions-permissions/tree/main/monitor
1 parent d1705d6 commit e2bb1ef

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

.github/workflows/publish-website.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ on:
99
# Allow running this workflow manually from the Actions tab.
1010
workflow_dispatch:
1111

12-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13-
permissions:
14-
contents: read
15-
pages: write
16-
id-token: write
12+
permissions: {}
1713

1814
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
1915
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
@@ -28,6 +24,10 @@ jobs:
2824

2925
name: "Build the website"
3026
runs-on: ubuntu-latest
27+
28+
permissions:
29+
contents: read # to read the contents of the repo
30+
3131
steps:
3232
# By default use the `gh-pages` branch.
3333
# For testing changes to the workflow or the scripts, use the PR branch
@@ -84,6 +84,10 @@ jobs:
8484
name: github-pages
8585
url: ${{ steps.deployment.outputs.page_url }}
8686

87+
permissions:
88+
pages: write # to deploy to Pages
89+
id-token: write # to verify the deployment originates from an appropriate source
90+
8791
steps:
8892
- name: Deploy to GitHub Pages
8993
id: deployment

0 commit comments

Comments
 (0)