Skip to content

Commit b224d2b

Browse files
committed
ci: harden workflows and pin dependencies for OpenSSF Scorecard
- Declare a read-only top-level permissions block in every workflow and move the write scopes each job actually uses to the job level, including the caller jobs of the zxc-* reusable workflows (Token-Permissions) - Pin the node:21 and node:21-slim base images by digest and switch the Dockerfile to npm ci so installs honour package-lock.json (Pinned-Dependencies) - Add fast-check as a devDependency with a property-based test for normalizeBalance (Fuzzing) No CodeQL workflow is added: the repository already runs CodeQL through GitHub's default setup, which rejects analysis uploads from a workflow-based configuration while it is enabled. Signed-off-by: Michael Garber <michael.garber@hashgraph.com>
1 parent 224830e commit b224d2b

10 files changed

Lines changed: 235 additions & 26 deletions

.github/workflows/flow-build-application.yaml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,30 @@ defaults:
4343
shell: bash
4444

4545
permissions:
46-
id-token: write
4746
contents: read
48-
actions: read
49-
pull-requests: write
50-
checks: write
51-
statuses: write
5247

5348
jobs:
5449
code:
5550
name: Code
5651
uses: ./.github/workflows/zxc-compile-code.yaml
52+
permissions:
53+
id-token: write
54+
contents: read
55+
actions: read
56+
pull-requests: write
57+
checks: write
58+
statuses: write
5759

5860
code-style:
5961
name: Code Style
6062
uses: ./.github/workflows/zxc-compile-code.yaml
63+
permissions:
64+
id-token: write
65+
contents: read
66+
actions: read
67+
pull-requests: write
68+
checks: write
69+
statuses: write
6170
needs:
6271
- code
6372
with:
@@ -67,6 +76,13 @@ jobs:
6776
unit-tests:
6877
name: Unit Tests
6978
uses: ./.github/workflows/zxc-compile-code.yaml
79+
permissions:
80+
id-token: write
81+
contents: read
82+
actions: read
83+
pull-requests: write
84+
checks: write
85+
statuses: write
7086
if: ${{ github.event_name == 'push' || github.event.inputs.enable-unit-tests == 'true' }}
7187
with:
7288
custom-job-label: Standard
@@ -75,6 +91,13 @@ jobs:
7591
integration-tests:
7692
name: Integration Tests
7793
uses: ./.github/workflows/zxc-compile-code.yaml
94+
permissions:
95+
id-token: write
96+
contents: read
97+
actions: read
98+
pull-requests: write
99+
checks: write
100+
statuses: write
78101
if: ${{ github.event_name == 'push' || github.event.inputs.enable-integration-tests == 'true' }}
79102
with:
80103
custom-job-label: Standard
@@ -87,6 +110,12 @@ jobs:
87110
analyze:
88111
name: Analyze
89112
uses: ./.github/workflows/zxc-code-analysis.yaml
113+
permissions:
114+
contents: read
115+
actions: read
116+
pull-requests: write
117+
checks: write
118+
statuses: write
90119
needs:
91120
- unit-tests
92121
- integration-tests

.github/workflows/flow-deploy-release-artifact.yaml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@ defaults:
2929
shell: bash
3030

3131
permissions:
32-
id-token: write
33-
checks: write
34-
statuses: write
35-
pull-requests: write
36-
contents: write
37-
issues: write
38-
actions: read
32+
contents: read
3933

4034
jobs:
4135
prepare-release:
4236
name: Release / Prepare
4337
runs-on: hiero-cli-linux-medium
38+
permissions:
39+
id-token: write
40+
checks: write
41+
statuses: write
42+
pull-requests: write
43+
contents: write
44+
issues: write
45+
actions: read
4446
outputs:
4547
version: ${{ steps.set-outputs.outputs.version }}
4648
need-release: ${{ steps.set-outputs.outputs.need-release }}
@@ -133,6 +135,13 @@ jobs:
133135
safety-checks:
134136
name: Release
135137
uses: ./.github/workflows/zxc-compile-code.yaml
138+
permissions:
139+
id-token: write
140+
contents: read
141+
actions: read
142+
pull-requests: write
143+
checks: write
144+
statuses: write
136145
with:
137146
custom-job-label: 'Safety Checks'
138147
enable-unit-tests: true
@@ -147,6 +156,14 @@ jobs:
147156
name: Github / Release
148157
if: ${{ needs.prepare-release.outputs.need-release == 'true' }}
149158
runs-on: hiero-cli-linux-medium
159+
permissions:
160+
id-token: write
161+
checks: write
162+
statuses: write
163+
pull-requests: write
164+
contents: write
165+
issues: write
166+
actions: read
150167
needs:
151168
- prepare-release
152169
- safety-checks
@@ -291,6 +308,14 @@ jobs:
291308
name: Publish Hiero CLI NPM Package
292309
if: ${{ needs.prepare-release.outputs.need-release == 'true' && inputs.dry-run-enabled != true }}
293310
runs-on: ubuntu-latest
311+
permissions:
312+
id-token: write
313+
checks: write
314+
statuses: write
315+
pull-requests: write
316+
contents: write
317+
issues: write
318+
actions: read
294319
needs:
295320
- create-github-release
296321
- prepare-release

.github/workflows/flow-pull-request-checks.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ defaults:
2727
run:
2828
shell: bash
2929

30+
permissions:
31+
contents: read
32+
3033
concurrency:
3134
group: pr-checks-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
3235
cancel-in-progress: true
@@ -35,10 +38,24 @@ jobs:
3538
build:
3639
name: Code
3740
uses: ./.github/workflows/zxc-compile-code.yaml
41+
permissions:
42+
id-token: write
43+
contents: read
44+
actions: read
45+
pull-requests: write
46+
checks: write
47+
statuses: write
3848

3949
code-style:
4050
name: Code Style
4151
uses: ./.github/workflows/zxc-compile-code.yaml
52+
permissions:
53+
id-token: write
54+
contents: read
55+
actions: read
56+
pull-requests: write
57+
checks: write
58+
statuses: write
4259
needs:
4360
- build
4461
with:
@@ -48,6 +65,13 @@ jobs:
4865
unit-tests:
4966
name: Unit Tests
5067
uses: ./.github/workflows/zxc-compile-code.yaml
68+
permissions:
69+
id-token: write
70+
contents: read
71+
actions: read
72+
pull-requests: write
73+
checks: write
74+
statuses: write
5175
needs:
5276
- code-style
5377
with:
@@ -57,6 +81,13 @@ jobs:
5781
integration-tests:
5882
name: Integration Tests
5983
uses: ./.github/workflows/zxc-compile-code.yaml
84+
permissions:
85+
id-token: write
86+
contents: read
87+
actions: read
88+
pull-requests: write
89+
checks: write
90+
statuses: write
6091
needs:
6192
- code-style
6293
with:
@@ -70,6 +101,12 @@ jobs:
70101
codecov:
71102
name: CodeCov
72103
uses: ./.github/workflows/zxc-code-analysis.yaml
104+
permissions:
105+
contents: read
106+
actions: read
107+
pull-requests: write
108+
checks: write
109+
statuses: write
73110
needs:
74111
- unit-tests
75112
- integration-tests
@@ -84,6 +121,12 @@ jobs:
84121
codacy-coverage:
85122
name: Codacy
86123
uses: ./.github/workflows/zxc-code-analysis.yaml
124+
permissions:
125+
contents: read
126+
actions: read
127+
pull-requests: write
128+
checks: write
129+
statuses: write
87130
needs:
88131
- unit-tests
89132
- integration-tests

.github/workflows/flow-pull-request-formatting.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defaults:
2929
shell: bash
3030

3131
permissions:
32-
statuses: write
32+
contents: read
3333

3434
concurrency:
3535
group: pr-formatting-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -39,6 +39,8 @@ jobs:
3939
title-check:
4040
name: Title Check
4141
runs-on: hiero-cli-linux-medium
42+
permissions:
43+
statuses: write
4244
steps:
4345
- name: Harden Runner
4446
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0

.github/workflows/zxc-code-analysis.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ defaults:
7272

7373
permissions:
7474
contents: read
75-
actions: read
76-
pull-requests: write
77-
checks: write
78-
statuses: write
7975

8076
jobs:
8177
analyze:
8278
name: ${{ inputs.custom-job-label || 'Analyze' }}
8379
runs-on: hiero-cli-linux-medium
80+
permissions:
81+
contents: read
82+
actions: read
83+
pull-requests: write
84+
checks: write
85+
statuses: write
8486
steps:
8587
- name: Harden Runner
8688
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0

.github/workflows/zxc-compile-code.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,19 @@ defaults:
6464
shell: bash
6565

6666
permissions:
67-
id-token: write
6867
contents: read
69-
actions: read
70-
pull-requests: write
71-
checks: write
72-
statuses: write
7368

7469
jobs:
7570
compile:
7671
name: ${{ inputs.custom-job-label || 'Compiles' }}
7772
runs-on: hiero-cli-linux-medium
73+
permissions:
74+
id-token: write
75+
contents: read
76+
actions: read
77+
pull-requests: write
78+
checks: write
79+
statuses: write
7880
steps:
7981
- name: Harden Runner
8082
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Build stage
2-
FROM node:21 AS build-stage
2+
FROM node:21@sha256:4b232062fa976e3a966c49e9b6279efa56c8d207a67270868f51b3d155c4e33d AS build-stage
33
WORKDIR /app
44

55
# Copy package.json and package-lock.json
66
COPY package*.json ./
77

88
# Install dependencies
9-
RUN npm install
9+
RUN npm ci
1010

1111
# Copy the rest of the application code
1212
COPY . .
@@ -15,7 +15,7 @@ COPY . .
1515
RUN npm run build
1616

1717
# Production stage
18-
FROM node:21-slim AS production-stage
18+
FROM node:21-slim@sha256:dfc05dee209a1d7adf2ef189bd97396daad4e97c6eaa85778d6f75205ba1b0fb AS production-stage
1919
WORKDIR /app
2020

2121
# Set CI environment variable to skip Husky setup
@@ -25,7 +25,7 @@ ENV CI=true
2525
COPY package*.json ./
2626

2727
# Install only production dependencies
28-
RUN npm install --omit=dev
28+
RUN npm ci --omit=dev
2929

3030
# Copy the built code from the build stage
3131
COPY --from=build-stage /app/dist ./dist

package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"eslint-plugin-no-relative-import-paths": "1.6.1",
106106
"eslint-plugin-prettier": "5.5.6",
107107
"eslint-plugin-simple-import-sort": "13.0.0",
108+
"fast-check": "4.9.0",
108109
"husky": "9.1.7",
109110
"jest": "30.4.2",
110111
"jest-junit": "17.0.0",

0 commit comments

Comments
 (0)