Skip to content

Commit 53c3c90

Browse files
authored
chore: harden GitHub Actions permissions (#1656)
1 parent a6e6361 commit 53c3c90

7 files changed

Lines changed: 52 additions & 33 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
required: true
1111
default: 'main'
1212

13+
permissions: {}
14+
1315
jobs:
1416
benchmark:
1517
runs-on: ubuntu-24.04
@@ -23,7 +25,7 @@ jobs:
2325
run: echo "TODO:\ Support benchmark in Rstest, this job is only a placeholder for the time being."
2426

2527
# - name: Checkout
26-
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
28+
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2729
# with:
2830
# fetch-depth: 10
2931
# ref: ${{ inputs.ref || 'main' }}
@@ -34,7 +36,7 @@ jobs:
3436
# corepack enable
3537

3638
# - name: Setup Node.js ${{ matrix.node-version }}
37-
# uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
39+
# uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3840
# with:
3941
# node-version: ${{ matrix.node-version }}
4042
# cache: 'pnpm'
@@ -44,7 +46,7 @@ jobs:
4446

4547
# # only run benchmark in Ubuntu
4648
# - name: Benchmarks (Rstest)
47-
# uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3
49+
# uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3.5.0
4850
# with:
4951
# run: pnpm run test:benchmark
5052
# # token retrieved from the CodSpeed app at the previous step

.github/workflows/ecosystem-ci.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@ on:
1111
required: true
1212
default: 'main'
1313

14-
permissions:
15-
contents: write
16-
issues: write
17-
pull-requests: write
14+
permissions: {}
1815

1916
jobs:
2017
changes:
2118
runs-on: ubuntu-latest
2219
if: github.repository == 'web-infra-dev/rslib' && github.event_name != 'workflow_dispatch'
20+
permissions:
21+
contents: read
2322
outputs:
2423
changed: ${{ steps.changes.outputs.changed }}
2524
steps:
2625
- name: Checkout
27-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
26+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2827
with:
2928
fetch-depth: 1
3029
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
@@ -41,9 +40,13 @@ jobs:
4140
name: Dispatch ecosystem CI
4241
runs-on: ubuntu-latest
4342
if: github.repository == 'web-infra-dev/rslib' && github.event_name == 'workflow_dispatch'
43+
permissions:
44+
contents: read
45+
issues: write
46+
pull-requests: read
4447
steps:
4548
- name: Trigger Ecosystem CI
46-
uses: rstackjs/rstack-ecosystem-ci/.github/actions/ecosystem_ci_dispatch@4949c44494d7fd3503abd791f11534c798a2a1d0 # main
49+
uses: rstackjs/rstack-ecosystem-ci/.github/actions/ecosystem_ci_dispatch@ca8d345a115158ea5ab3807378357f2162be7467 # main
4750
with:
4851
github-token: ${{ secrets.REPO_RSLIB_ECO_CI_GITHUB_TOKEN }}
4952
ecosystem-owner: web-infra-dev
@@ -56,9 +59,11 @@ jobs:
5659
needs: changes
5760
runs-on: ubuntu-latest
5861
if: github.repository == 'web-infra-dev/rslib' && github.event_name != 'workflow_dispatch' && needs.changes.outputs.changed == 'true'
62+
permissions:
63+
contents: read
5964
steps:
6065
- name: Trigger Ecosystem CI
61-
uses: rstackjs/rstack-ecosystem-ci/.github/actions/ecosystem_ci_per_commit@4949c44494d7fd3503abd791f11534c798a2a1d0 # main
66+
uses: rstackjs/rstack-ecosystem-ci/.github/actions/ecosystem_ci_per_commit@ca8d345a115158ea5ab3807378357f2162be7467 # main
6267
with:
6368
github-token: ${{ secrets.REPO_RSLIB_ECO_CI_GITHUB_TOKEN }}
6469
ecosystem-owner: web-infra-dev

.github/workflows/lint.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ on:
99

1010
workflow_dispatch:
1111

12-
permissions:
13-
contents: read
12+
permissions: {}
1413

1514
jobs:
1615
lint:
1716
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1819

1920
steps:
2021
- name: Checkout
21-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
22+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2223
with:
2324
fetch-depth: 1
2425

@@ -28,10 +29,10 @@ jobs:
2829
corepack enable
2930
3031
- name: Setup Node.js
31-
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
32+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
3233
with:
3334
node-version: 24
34-
cache: 'pnpm'
35+
package-manager-cache: false
3536

3637
- name: Install Dependencies
3738
run: pnpm install

.github/workflows/preview.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ on:
1111
required: true
1212
default: 'main'
1313

14-
permissions:
15-
contents: read
14+
permissions: {}
1615

1716
jobs:
1817
preview:
1918
if: github.repository == 'web-infra-dev/rslib'
2019
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
2122

2223
steps:
2324
- name: Checkout
24-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2526
with:
2627
fetch-depth: 1
2728
ref: ${{ github.event.inputs.branch }}
@@ -41,10 +42,10 @@ jobs:
4142
4243
- name: Setup Node.js
4344
if: steps.changes.outputs.changed == 'true'
44-
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
45+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
4546
with:
4647
node-version: 24
47-
cache: 'pnpm'
48+
package-manager-cache: false
4849

4950
- name: Install Dependencies
5051
if: steps.changes.outputs.changed == 'true'

.github/workflows/release.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ on:
1919
required: true
2020
default: 'main'
2121

22-
permissions:
23-
# Provenance generation in GitHub Actions requires "write" access to the "id-token"
24-
id-token: write
22+
permissions: {}
2523

2624
jobs:
2725
release:
2826
name: Release
2927
if: github.repository == 'web-infra-dev/rslib' && github.event_name == 'workflow_dispatch'
3028
runs-on: ubuntu-latest
3129
environment: npm
30+
permissions:
31+
contents: read
32+
# Provenance generation in GitHub Actions requires "write" access to the "id-token"
33+
id-token: write
3234
steps:
3335
- name: Checkout
34-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
36+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3537
with:
3638
fetch-depth: 1
3739
ref: ${{ github.event.inputs.branch }}
@@ -42,10 +44,10 @@ jobs:
4244
corepack enable
4345
4446
- name: Setup Node.js
45-
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
47+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
4648
with:
4749
node-version: 24
48-
cache: 'pnpm'
50+
package-manager-cache: false
4951

5052
# Update npm to the latest version to enable OIDC
5153
- name: Update npm

.github/workflows/reusable-test.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ on:
1313
required: true
1414
type: string
1515

16-
permissions:
17-
contents: read
16+
permissions: {}
1817

1918
jobs:
2019
test:
2120
runs-on: ${{ inputs.runner }}
21+
permissions:
22+
contents: read
2223
steps:
2324
- name: Checkout
24-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2526
with:
2627
fetch-depth: 1
2728

@@ -49,10 +50,10 @@ jobs:
4950
5051
- name: Setup Node.js ${{ inputs.node-version }}
5152
if: ${{ steps.changes.outputs.changed == 'true' }}
52-
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
53+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
5354
with:
5455
node-version: ${{ inputs.node-version }}
55-
cache: 'pnpm'
56+
package-manager-cache: false
5657

5758
- name: Install Dependencies
5859
if: ${{ steps.changes.outputs.changed == 'true' }}

.github/workflows/test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ on:
99

1010
workflow_dispatch:
1111

12-
permissions:
13-
contents: read
12+
permissions: {}
1413

1514
jobs:
1615
ut:
@@ -19,6 +18,8 @@ jobs:
1918
runner: [ubuntu-latest, windows-latest]
2019
node-version: [24]
2120
uses: ./.github/workflows/reusable-test.yml
21+
permissions:
22+
contents: read
2223
with:
2324
runner: ${{ matrix.runner }}
2425
node-version: ${{ matrix.node-version }}
@@ -31,6 +32,8 @@ jobs:
3132
node-version: [24]
3233

3334
uses: ./.github/workflows/reusable-test.yml
35+
permissions:
36+
contents: read
3437
with:
3538
runner: ${{ matrix.runner }}
3639
node-version: ${{ matrix.node-version }}
@@ -43,6 +46,8 @@ jobs:
4346
node-version: ['25']
4447

4548
uses: ./.github/workflows/reusable-test.yml
49+
permissions:
50+
contents: read
4651
with:
4752
runner: ${{ matrix.runner }}
4853
node-version: ${{ matrix.node-version }}
@@ -54,6 +59,8 @@ jobs:
5459
runner: [ubuntu-latest, windows-latest]
5560
node-version: [24]
5661
uses: ./.github/workflows/reusable-test.yml
62+
permissions:
63+
contents: read
5764
with:
5865
runner: ${{ matrix.runner }}
5966
node-version: ${{ matrix.node-version }}

0 commit comments

Comments
 (0)