Skip to content

Commit 142dfc8

Browse files
workflows: fix and cleanup permissions (#3797)
1 parent 6b5c8af commit 142dfc8

9 files changed

+57
-25
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name: CI
22
on: workflow_call
3-
permissions:
4-
contents: read
3+
permissions: {}
54
jobs:
65
lint:
76
name: Lint source files
87
runs-on: ubuntu-latest
8+
permissions:
9+
contents: read # for actions/checkout
910
steps:
1011
- name: Checkout repo
1112
uses: actions/checkout@v3
@@ -41,6 +42,8 @@ jobs:
4142
checkForCommonlyIgnoredFiles:
4243
name: Check for commonly ignored files
4344
runs-on: ubuntu-latest
45+
permissions:
46+
contents: read # for actions/checkout
4447
steps:
4548
- name: Checkout repo
4649
uses: actions/checkout@v3
@@ -64,6 +67,8 @@ jobs:
6467
checkPackageLock:
6568
name: Check health of package-lock.json file
6669
runs-on: ubuntu-latest
70+
permissions:
71+
contents: read # for actions/checkout
6772
steps:
6873
- name: Checkout repo
6974
uses: actions/checkout@v3
@@ -92,6 +97,8 @@ jobs:
9297
integrationTests:
9398
name: Run integration tests
9499
runs-on: ubuntu-latest
100+
permissions:
101+
contents: read # for actions/checkout
95102
steps:
96103
- name: Checkout repo
97104
uses: actions/checkout@v3
@@ -114,6 +121,8 @@ jobs:
114121
fuzz:
115122
name: Run fuzzing tests
116123
runs-on: ubuntu-latest
124+
permissions:
125+
contents: read # for actions/checkout
117126
steps:
118127
- name: Checkout repo
119128
uses: actions/checkout@v3
@@ -138,6 +147,8 @@ jobs:
138147
strategy:
139148
matrix:
140149
node_version_to_setup: [14, 16, 18]
150+
permissions:
151+
contents: read # for actions/checkout
141152
steps:
142153
- name: Checkout repo
143154
uses: actions/checkout@v3
@@ -160,7 +171,7 @@ jobs:
160171
name: Run CodeQL security scan
161172
runs-on: ubuntu-latest
162173
permissions:
163-
contents: read
174+
contents: read # for actions/checkout
164175
security-events: write
165176
steps:
166177
- name: Checkout repo
@@ -179,6 +190,8 @@ jobs:
179190
build-npm-dist:
180191
name: Build 'npmDist' artifact
181192
runs-on: ubuntu-latest
193+
permissions:
194+
contents: read # for actions/checkout
182195
steps:
183196
- name: Checkout repo
184197
uses: actions/checkout@v3
@@ -206,6 +219,8 @@ jobs:
206219
build-deno-dist:
207220
name: Build 'denoDist' artifact
208221
runs-on: ubuntu-latest
222+
permissions:
223+
contents: read # for actions/checkout
209224
steps:
210225
- name: Checkout repo
211226
uses: actions/checkout@v3
@@ -233,6 +248,8 @@ jobs:
233248
build-website-dist:
234249
name: Build website
235250
runs-on: ubuntu-latest
251+
permissions:
252+
contents: read # for actions/checkout
236253
steps:
237254
- name: Checkout repo
238255
uses: actions/checkout@v3

.github/workflows/cmd-publish-pr-on-npm.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ on:
1010
npm_canary_pr_publish_token:
1111
description: NPM token to publish canary release.
1212
required: true
13-
permissions:
14-
contents: read
13+
permissions: {}
1514
jobs:
1615
build-npm-dist:
1716
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read # for actions/checkout
1819
steps:
1920
- name: Checkout repo
2021
uses: actions/checkout@v3
@@ -45,6 +46,8 @@ jobs:
4546
name: Publish Canary
4647
environment: canary-pr-npm
4748
needs: [build-npm-dist]
49+
permissions:
50+
contents: read # for actions/checkout
4851
steps:
4952
- name: Checkout repo
5053
uses: actions/checkout@v3

.github/workflows/cmd-run-benchmark.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ on:
66
description: String that contain JSON payload for `pull_request` event.
77
required: true
88
type: string
9-
permissions:
10-
contents: read # for checkout
11-
actions: read # to list workflow runs
9+
permissions: {}
1210
jobs:
1311
benchmark:
1412
name: Run benchmark
1513
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read # for actions/checkout
16+
actions: read # to list workflow runs
1617
steps:
1718
- name: Checkout repo
1819
uses: actions/checkout@v3

.github/workflows/deploy-artifact-as-branch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ on:
2121
permissions: {}
2222
jobs:
2323
deploy-artifact-as-branch:
24-
permissions:
25-
contents: write # to push branch
2624
environment:
2725
name: ${{ inputs.environment }}
2826
url: ${{ github.server_url }}/${{ github.repository }}/tree/${{ inputs.target_branch }}
2927
runs-on: ubuntu-latest
28+
permissions:
29+
contents: write # for actions/checkout and to push branch
3030
steps:
3131
- name: Checkout `${{ inputs.target_branch }}` branch
3232
uses: actions/checkout@v3

.github/workflows/github-actions-bot.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ env:
2424
permissions: {}
2525
jobs:
2626
hello-message:
27+
if: github.event_name == 'workflow_run'
28+
runs-on: ubuntu-latest
2729
permissions:
2830
actions: read # to download event.json
2931
pull-requests: write # to add comment to pull request
30-
31-
if: github.event_name == 'workflow_run'
32-
runs-on: ubuntu-latest
3332
steps:
3433
- name: Download event.json
3534
run: gh run download "$WORKFLOW_ID" --repo "$REPO" --name event.json
@@ -54,14 +53,13 @@ jobs:
5453
})
5554
5655
accept-cmd:
57-
permissions:
58-
pull-requests: write # to add comment to pull request
59-
6056
if: |
6157
github.event_name == 'issue_comment' &&
6258
github.event.issue.pull_request &&
6359
startsWith(github.event.comment.body, '@github-actions ')
6460
runs-on: ubuntu-latest
61+
permissions:
62+
pull-requests: write # to add comment to pull request
6563
outputs:
6664
cmd: ${{ steps.parse-cmd.outputs.cmd }}
6765
pull_request_json: ${{ steps.parse-cmd.outputs.pull_request_json }}
@@ -90,7 +88,7 @@ jobs:
9088
needs: [accept-cmd]
9189
if: needs.accept-cmd.outputs.cmd == 'publish-pr-on-npm'
9290
permissions:
93-
contents: read
91+
contents: read # for actions/checkout
9492
uses: ./.github/workflows/cmd-publish-pr-on-npm.yml
9593
with:
9694
pull_request_json: ${{ needs.accept-cmd.outputs.pull_request_json }}
@@ -101,22 +99,21 @@ jobs:
10199
needs: [accept-cmd]
102100
if: needs.accept-cmd.outputs.cmd == 'run-benchmark'
103101
permissions:
104-
contents: read # for checkout
102+
contents: read # for actions/checkout
105103
actions: read # to list workflow runs
106104
uses: ./.github/workflows/cmd-run-benchmark.yml
107105
with:
108106
pull_request_json: ${{ needs.accept-cmd.outputs.pull_request_json }}
109107

110108
respond-to-cmd:
111-
permissions:
112-
pull-requests: write # to add comment to pull request
113-
114109
needs:
115110
- accept-cmd
116111
- cmd-publish-pr-on-npm
117112
- cmd-run-benchmark
118113
if: needs.accept-cmd.result != 'skipped' && always()
119114
runs-on: ubuntu-latest
115+
permissions:
116+
pull-requests: write # to add comment to pull request
120117
steps:
121118
- uses: actions/download-artifact@v3
122119
with:

.github/workflows/mutation-testing.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ on:
33
workflow_dispatch:
44
schedule:
55
- cron: '0 0 * * *' # run once every day at 00:00 UTC
6-
7-
permissions:
8-
contents: read # to fetch code (actions/checkout)
9-
6+
permissions: {}
107
jobs:
118
lint:
129
name: Run mutation testing
1310
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read # for actions/checkout
1413
steps:
1514
- name: Checkout repo
1615
uses: actions/checkout@v3

.github/workflows/pull_request.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
name: PullRequest
22
on: pull_request
3+
permissions: {}
34
jobs:
45
ci:
6+
permissions:
7+
contents: read # for actions/checkout
58
uses: ./.github/workflows/ci.yml
69

710
dependency-review:
811
name: Security check of added dependencies
912
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read # for actions/checkout
1015
steps:
1116
- name: Checkout repo
1217
uses: actions/checkout@v3
@@ -19,6 +24,8 @@ jobs:
1924
diff-npm-package:
2025
name: Diff content of NPM package
2126
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read # for actions/checkout
2229
steps:
2330
- name: Checkout repo
2431
uses: actions/checkout@v3

.github/workflows/pull_request_opened.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: PullRequestOpened
22
on:
33
pull_request:
44
types: [opened]
5+
permissions: {}
56
jobs:
67
save-github-event:
78
name: "Save `github.event` as an artifact to use in subsequent 'workflow_run' actions"

.github/workflows/push.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ on: push
33
permissions: {}
44
jobs:
55
ci:
6+
permissions:
7+
contents: read # for actions/checkout
8+
security-events: write
69
uses: ./.github/workflows/ci.yml
710
deploy-to-npm-branch:
811
name: Deploy to `npm` branch
912
needs: ci
1013
if: github.ref == 'refs/heads/main'
14+
permissions:
15+
contents: write # for actions/checkout and to push branch
1116
uses: ./.github/workflows/deploy-artifact-as-branch.yml
1217
with:
1318
environment: npm-branch
@@ -19,6 +24,8 @@ jobs:
1924
name: Deploy to `deno` branch
2025
needs: ci
2126
if: github.ref == 'refs/heads/main'
27+
permissions:
28+
contents: write # for actions/checkout and to push branch
2229
uses: ./.github/workflows/deploy-artifact-as-branch.yml
2330
with:
2431
environment: deno-branch

0 commit comments

Comments
 (0)