Skip to content

Commit 5574a37

Browse files
committed
ci: harden workflow token permissions and add CodeQL analysis
Declare a read-only top-level permissions block in every workflow and move write scopes to the jobs that use them, add a CodeQL workflow, and replace the unpinned npm install in the PR label check with npm ci. - release.yml: top-level actions/checks/contents/id-token/issues/ pull-requests/packages write replaced by contents: read; each job now declares only the scopes its steps use (dispatch-rc: actions+contents write; create-github-release: contents/issues/pull-requests write; create-snapshot-pr: contents/pull-requests write; publish-npm-package: id-token/packages write) - tests.yml, manual-testing.yml: checks: write and pull-requests: write moved from the top level to each job calling test-workflow.yml and to PublishResults; effective job permissions are unchanged - pr-label-milestone-check.yml: add the missing permissions block (contents: read top level, issues/pull-requests read on the job) and use npm ci --omit=dev instead of npm install axios - add .github/workflows/codeql.yml (actions + javascript-typescript, build-mode none) on pull_request, push to main/release/** and weekly Scorecard checks affected: Token-Permissions (0 -> 10), SAST (0 -> 10 locally), Pinned-Dependencies (8 -> 9). Signed-off-by: Michael Garber <michael.garber@hashgraph.com>
1 parent 99cf869 commit 5574a37

5 files changed

Lines changed: 199 additions & 12 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CodeQL
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- release/**
8+
push:
9+
branches:
10+
- main
11+
- release/**
12+
schedule:
13+
- cron: '17 3 * * 1'
14+
15+
concurrency:
16+
group: codeql-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
runs-on: hl-contr-lin-md
26+
permissions:
27+
contents: read
28+
actions: read
29+
packages: read
30+
security-events: write
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- language: actions
36+
build-mode: none
37+
- language: javascript-typescript
38+
build-mode: none
39+
40+
steps:
41+
- name: Harden Runner
42+
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
43+
with:
44+
egress-policy: audit
45+
46+
- name: Checkout code
47+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
48+
49+
- name: Initialize CodeQL
50+
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
51+
with:
52+
languages: ${{ matrix.language }}
53+
build-mode: ${{ matrix.build-mode }}
54+
55+
- name: Perform CodeQL Analysis
56+
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
57+
with:
58+
category: '/language:${{ matrix.language }}'

.github/workflows/manual-testing.yml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ run-name: Manual Test with N:${{ inputs.networkNodeTag }}, M:${{ inputs.mirrorNo
1818

1919
permissions:
2020
contents: read
21-
checks: write
22-
pull-requests: write
2321

2422
defaults:
2523
run:
@@ -29,6 +27,10 @@ jobs:
2927
ERC20Contract:
3028
name: ERC20 Contract Test Suite
3129
uses: ./.github/workflows/test-workflow.yml
30+
permissions:
31+
contents: read
32+
checks: write
33+
pull-requests: write
3234
with:
3335
testfilter: ERC20
3436
networkTag: ${{inputs.networkNodeTag}}
@@ -38,6 +40,10 @@ jobs:
3840
ERC721Contract:
3941
name: ERC721 Contract Test Suite
4042
uses: ./.github/workflows/test-workflow.yml
43+
permissions:
44+
contents: read
45+
checks: write
46+
pull-requests: write
4147
with:
4248
testfilter: ERC721
4349
networkTag: ${{inputs.networkNodeTag}}
@@ -47,6 +53,10 @@ jobs:
4753
ERC1155Contract:
4854
name: ERC1155 Contract Test Suite
4955
uses: ./.github/workflows/test-workflow.yml
56+
permissions:
57+
contents: read
58+
checks: write
59+
pull-requests: write
5060
with:
5161
testfilter: ERC1155
5262
networkTag: ${{inputs.networkNodeTag}}
@@ -56,6 +66,10 @@ jobs:
5666
TokenCreateContract:
5767
name: Token Create Test Suite
5868
uses: ./.github/workflows/test-workflow.yml
69+
permissions:
70+
contents: read
71+
checks: write
72+
pull-requests: write
5973
with:
6074
testfilter: TokenCreateContract
6175
networkTag: ${{inputs.networkNodeTag}}
@@ -65,6 +79,10 @@ jobs:
6579
TokenQueryContract:
6680
name: Token Query Test Suite
6781
uses: ./.github/workflows/test-workflow.yml
82+
permissions:
83+
contents: read
84+
checks: write
85+
pull-requests: write
6886
with:
6987
testfilter: TokenQueryContract
7088
networkTag: ${{inputs.networkNodeTag}}
@@ -74,6 +92,10 @@ jobs:
7492
TokenManagmentContract:
7593
name: Token Managment Test Suite
7694
uses: ./.github/workflows/test-workflow.yml
95+
permissions:
96+
contents: read
97+
checks: write
98+
pull-requests: write
7799
with:
78100
testfilter: TokenManagmentContract
79101
networkTag: ${{inputs.networkNodeTag}}
@@ -83,6 +105,10 @@ jobs:
83105
TokenTransferContract:
84106
name: Token Transfer Test Suite
85107
uses: ./.github/workflows/test-workflow.yml
108+
permissions:
109+
contents: read
110+
checks: write
111+
pull-requests: write
86112
with:
87113
testfilter: TokenTransferContract
88114
networkTag: ${{inputs.networkNodeTag}}
@@ -92,6 +118,10 @@ jobs:
92118
HIP583:
93119
name: HIP583 Test Suite
94120
uses: ./.github/workflows/test-workflow.yml
121+
permissions:
122+
contents: read
123+
checks: write
124+
pull-requests: write
95125
with:
96126
testfilter: HIP583
97127
networkTag: ${{inputs.networkNodeTag}}
@@ -101,6 +131,10 @@ jobs:
101131
HRC:
102132
name: HRC Test Suite
103133
uses: ./.github/workflows/test-workflow.yml
134+
permissions:
135+
contents: read
136+
checks: write
137+
pull-requests: write
104138
with:
105139
testfilter: HRC
106140
networkTag: ${{inputs.networkNodeTag}}
@@ -110,6 +144,10 @@ jobs:
110144
PrngSystemContract:
111145
name: PrngSystemContract Test Suite
112146
uses: ./.github/workflows/test-workflow.yml
147+
permissions:
148+
contents: read
149+
checks: write
150+
pull-requests: write
113151
with:
114152
testfilter: PrngSystemContract
115153
networkTag: ${{inputs.networkNodeTag}}
@@ -119,6 +157,10 @@ jobs:
119157
HIP904Batch1:
120158
name: HIP904 Contract Test Suite Batch 1
121159
uses: ./.github/workflows/test-workflow.yml
160+
permissions:
161+
contents: read
162+
checks: write
163+
pull-requests: write
122164
with:
123165
testfilter: 'HIP904Batch1'
124166
networkTag: ${{inputs.networkNodeTag}}
@@ -128,6 +170,10 @@ jobs:
128170
HIP904Batch2:
129171
name: HIP904 Contract Test Suite Batch 2
130172
uses: ./.github/workflows/test-workflow.yml
173+
permissions:
174+
contents: read
175+
checks: write
176+
pull-requests: write
131177
with:
132178
testfilter: 'HIP904Batch2'
133179
networkTag: ${{inputs.networkNodeTag}}
@@ -137,6 +183,10 @@ jobs:
137183
HIP904Batch3:
138184
name: HIP904 Contract Test Suite Batch 3
139185
uses: ./.github/workflows/test-workflow.yml
186+
permissions:
187+
contents: read
188+
checks: write
189+
pull-requests: write
140190
with:
141191
testfilter: 'HIP904Batch3'
142192
networkTag: ${{inputs.networkNodeTag}}
@@ -146,6 +196,10 @@ jobs:
146196
HIP1215:
147197
name: HIP1215 Test Suite
148198
uses: ./.github/workflows/test-workflow.yml
199+
permissions:
200+
contents: read
201+
checks: write
202+
pull-requests: write
149203
with:
150204
testfilter: HIP1215
151205
networkTag: ${{inputs.networkNodeTag}}

.github/workflows/pr-label-milestone-check.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ on:
44
pull_request:
55
types: [opened, edited, labeled, unlabeled, synchronize]
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
check_pr:
912
runs-on: hl-contr-lin-md
13+
permissions:
14+
contents: read
15+
issues: read
16+
pull-requests: read
1017

1118
steps:
1219
- name: Harden Runner
@@ -23,7 +30,7 @@ jobs:
2330
node-version: '20'
2431

2532
- name: Install dependencies
26-
run: npm install axios
33+
run: npm ci --omit=dev
2734

2835
- name: Check PR labels and milestones
2936
env:

.github/workflows/release.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ env:
2626
RELEASE_TYPE: ${{ inputs.release-type }}
2727

2828
permissions:
29-
actions: write
30-
checks: write
31-
contents: write
32-
id-token: write
33-
issues: write
34-
pull-requests: write
35-
packages: write
29+
contents: read
3630

3731
jobs:
3832
# ─────────────────────────────────────────────────────────────────────────────
@@ -43,6 +37,9 @@ jobs:
4337
name: Release / Dispatch RC
4438
if: ${{ inputs.release-type == 'rc' && github.ref_name == github.event.repository.default_branch }}
4539
runs-on: hl-contr-lin-lg
40+
permissions:
41+
actions: write
42+
contents: write
4643
steps:
4744
- name: Harden the runner (Audit all outbound calls)
4845
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
@@ -91,6 +88,8 @@ jobs:
9188
name: Release / Prepare
9289
if: ${{ (inputs.release-type == 'standard' && github.ref_name == github.event.repository.default_branch) || (inputs.release-type == 'rc' && startsWith(github.ref_name, 'rc/')) }}
9390
runs-on: hl-contr-lin-lg
91+
permissions:
92+
contents: read
9493
outputs:
9594
version: ${{ steps.set-outputs.outputs.version }}
9695
need-release: ${{ steps.set-outputs.outputs.need-release }}
@@ -227,6 +226,10 @@ jobs:
227226
name: Release / Github
228227
if: ${{ needs.prepare-release.outputs.need-release == 'true' }}
229228
runs-on: hl-contr-lin-lg
229+
permissions:
230+
contents: write
231+
issues: write
232+
pull-requests: write
230233
needs:
231234
- prepare-release
232235
outputs:
@@ -355,6 +358,9 @@ jobs:
355358
create-snapshot-pr:
356359
name: Release / Snapshot
357360
runs-on: hl-contr-lin-lg
361+
permissions:
362+
contents: write
363+
pull-requests: write
358364
needs:
359365
- prepare-release
360366
- create-github-release
@@ -439,6 +445,10 @@ jobs:
439445
name: Release / Publish Hiero Contracts NPM package
440446
if: ${{ needs.prepare-release.outputs.need-release == 'true' && !inputs.dry-run-enabled }}
441447
runs-on: ubuntu-latest
448+
permissions:
449+
contents: read
450+
id-token: write
451+
packages: write
442452
needs:
443453
- prepare-release
444454
- create-github-release

0 commit comments

Comments
 (0)