Skip to content

Commit 831408a

Browse files
authored
Merge pull request #102 from timoa/develop
Update dependencies + hardening CI/CD
2 parents f62343d + 2da9582 commit 831408a

File tree

8 files changed

+328
-300
lines changed

8 files changed

+328
-300
lines changed

.github/workflows/code-review.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13+
- name: Harden GitHub Actions Runner
14+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
15+
with:
16+
egress-policy: block
17+
allowed-endpoints: >
18+
api.github.com:443
19+
github.com:443
20+
objects.githubusercontent.com:443
21+
raw.githubusercontent.com:443
22+
registry.npmjs.org:443
23+
snyk.io:443
24+
1325
- name: Checkout
1426
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
1527

@@ -24,6 +36,16 @@ jobs:
2436
runs-on: ubuntu-latest
2537

2638
steps:
39+
- name: Harden GitHub Actions Runner
40+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
41+
with:
42+
egress-policy: block
43+
allowed-endpoints: >
44+
api.github.com:443
45+
github.com:443
46+
objects.githubusercontent.com:443
47+
raw.githubusercontent.com:443
48+
2749
- name: Checkout
2850
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
2951

.github/workflows/codeql-analysis.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,28 @@ jobs:
3131
contents: read
3232

3333
steps:
34+
- name: Harden GitHub Actions Runner
35+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
36+
with:
37+
egress-policy: block
38+
allowed-endpoints: >
39+
api.github.com:443
40+
github.com:443
41+
3442
- name: Checkout repository
3543
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
3644

3745
# Initializes the CodeQL tools for scanning.
3846
- name: Initialize CodeQL
39-
uses: github/codeql-action/init@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
47+
uses: github/codeql-action/init@27ea8f8fe5977c00f5b37e076ab846c5bd783b96 # tag=v2.1.12
4048
# Override language selection by uncommenting this and choosing your languages
4149
# with:
4250
# languages: go, javascript, csharp, python, cpp, java
4351

4452
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
4553
# If this step fails, then you should remove it and run the build manually (see below).
4654
- name: Autobuild
47-
uses: github/codeql-action/autobuild@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
55+
uses: github/codeql-action/autobuild@27ea8f8fe5977c00f5b37e076ab846c5bd783b96 # tag=v2.1.12
4856

4957
# ℹ️ Command-line programs to run using the OS shell.
5058
# 📚 https://git.io/JvXDl
@@ -58,4 +66,4 @@ jobs:
5866
# make release
5967

6068
- name: Perform CodeQL Analysis
61-
uses: github/codeql-action/analyze@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
69+
uses: github/codeql-action/analyze@27ea8f8fe5977c00f5b37e076ab846c5bd783b96 # tag=v2.1.12

.github/workflows/nodejs.yml

Lines changed: 121 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,26 @@ jobs:
1515
mongodb: ['5.0']
1616

1717
steps:
18+
- name: Harden GitHub Actions Runner
19+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
20+
with:
21+
egress-policy: block
22+
allowed-endpoints: >
23+
api.github.com:443
24+
auth.docker.io:443
25+
github.com:443
26+
objects.githubusercontent.com:443
27+
pipelines.actions.githubusercontent.com:443
28+
production.cloudflare.docker.com:443
29+
registry-1.docker.io:443
30+
registry.npmjs.org:443
31+
snyk.io:443
32+
1833
- name: Checkout
1934
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
2035

2136
- name: Setup Node.js ${{ matrix.node }}
22-
uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3.1.1
37+
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # tag=v3.3.0
2338
with:
2439
node-version: ${{ matrix.node }}
2540
check-latest: true
@@ -37,7 +52,7 @@ jobs:
3752
run: npm run test:coverage
3853

3954
- name: Save Code Coverage
40-
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # tag=v3.0.0
55+
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0
4156
with:
4257
name: code-coverage
4358
path: coverage
@@ -49,6 +64,16 @@ jobs:
4964
needs: tests
5065

5166
steps:
67+
- name: Harden GitHub Actions Runner
68+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
69+
with:
70+
egress-policy: block
71+
allowed-endpoints: >
72+
api.github.com:443
73+
github.com:443
74+
pipelines.actions.githubusercontent.com:443
75+
sonarcloud.io:443
76+
5277
- name: Checkout
5378
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
5479

@@ -67,32 +92,6 @@ jobs:
6792
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6893
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
6994

70-
# functional-tests:
71-
# runs-on: ubuntu-latest
72-
# needs: tests
73-
74-
# steps:
75-
# - name: Checkout
76-
# uses: actions/checkout@v2
77-
78-
# - name: Build docker image
79-
# run: docker build -t timoa/nodejs-encryption-api-example .
80-
81-
# - name: Start Docker container
82-
# run: docker-compose up -d
83-
84-
# - name: Check Docker container status
85-
# run: docker ps -a
86-
87-
# - name: Install dependencies
88-
# run: npm install
89-
90-
# - name: Run Functional tests
91-
# run: npm run test:functional
92-
93-
# - name: Stop Docker container
94-
# run: docker-compose down
95-
9695
# -- SAST SCAN --------------------------------------------------------------
9796
code-security:
9897
name: Code Security
@@ -102,32 +101,113 @@ jobs:
102101
if: (github.actor != 'dependabot[bot]')
103102

104103
steps:
104+
- name: Harden GitHub Actions Runner
105+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
106+
with:
107+
egress-policy: block
108+
allowed-endpoints: >
109+
github.com:443
110+
api.github.com:443
111+
pipelines.actions.githubusercontent.com:443
112+
registry.npmjs.org:443
113+
pypi.org:443
114+
115+
105116
- name: Checkout
106117
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
107118

108119
- name: Perform Scan
109120
uses: ShiftLeftSecurity/scan-action@master
110-
111121
env:
112122
WORKSPACE: https://github.com/${{ github.repository }}/blob/${{ github.sha }}
113123
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114124
SCAN_ANNOTATE_PR: true
115125

116-
- uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # tag=v3.0.0
126+
- name: Save the SCAN reports
127+
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0
117128
with:
118-
name: reports
129+
name: sast-reports
119130
path: reports
120131

132+
# -- ZAP Scan ---------------------------------------------------------------
133+
api-security:
134+
name: API Security
135+
runs-on: ubuntu-latest
136+
needs: tests
137+
# Skip any PR created by dependabot to avoid permission issues
138+
if: (github.actor != 'dependabot[bot]')
139+
140+
strategy:
141+
matrix:
142+
node: ['16']
143+
mongodb: ['5.0']
144+
145+
steps:
146+
- name: Harden GitHub Actions Runner
147+
uses: step-security/harden-runner@dd5681a7d0c66fb362664d618ef4a90d656f6516
148+
with:
149+
egress-policy: block
150+
allowed-endpoints: >
151+
api.github.com:443
152+
auth.docker.io:443
153+
bit.ly:443
154+
content-signature-2.cdn.mozilla.net:443
155+
firefox.settings.services.mozilla.com:443
156+
github.com:443
157+
news.zaproxy.org:443
158+
objects.githubusercontent.com:443
159+
pipelines.actions.githubusercontent.com:443
160+
production.cloudflare.docker.com:443
161+
raw.githubusercontent.com:443
162+
registry-1.docker.io:443
163+
registry.npmjs.org:443
164+
shavar.services.mozilla.com:443
165+
snyk.io:443
166+
tel.zaproxy.org:443
167+
tracking-protection.cdn.mozilla.net:443
168+
169+
- name: Checkout
170+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
171+
172+
- name: Setup Node.js ${{ matrix.node }}
173+
uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048 # tag=v3.2.0
174+
with:
175+
node-version: ${{ matrix.node }}
176+
check-latest: true
177+
178+
- name: Install dependencies
179+
run: npm install
180+
181+
- name: Start MongoDB
182+
uses: supercharge/mongodb-github-action@e815fd8a9dfede09fd6e6c144f2c9f4875e933df # tag=1.7.0
183+
with:
184+
mongodb-version: ${{ matrix.mongodb }}
185+
mongodb-db: encryptionAPI
186+
187+
- name: Start the app
188+
run: npm start > /dev/null &
189+
190+
- name: Run ZAP Scan
191+
uses: zaproxy/[email protected]
192+
with:
193+
target: http://localhost:3000
194+
121195
# -- PRE-RELEASE ------------------------------------------------------------
122196
pre-release:
123197
name: Prepare Release
124198
runs-on: ubuntu-latest
125199
needs:
126200
- code-quality
127201
- code-security
202+
- api-security
128203
if: github.ref == 'refs/heads/master'
129204

130205
steps:
206+
- name: Harden GitHub Actions Runner
207+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
208+
with:
209+
egress-policy: audit
210+
131211
- name: Checkout
132212
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
133213

@@ -144,12 +224,17 @@ jobs:
144224
if: github.ref == 'refs/heads/master'
145225

146226
steps:
227+
- name: Harden GitHub Actions Runner
228+
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
229+
with:
230+
egress-policy: audit
231+
147232
- name: Checkout
148233
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
149234

150235
- name: Docker meta
151236
id: meta
152-
uses: docker/metadata-action@b2391d37b4157fa4aa2e118d643f417910ff3242 # tag=v3.8.0
237+
uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a # tag=v4.0.1
153238
with:
154239
images: ${{ github.repository }}
155240
tags: |
@@ -163,19 +248,19 @@ jobs:
163248
type=raw,value=latest
164249
165250
- name: Set up QEMU
166-
uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 # tag=v1.2.0
251+
uses: docker/setup-qemu-action@8b122486cedac8393e77aa9734c3528886e4a1a8 # tag=v2.0.0
167252

168253
- name: Set up Docker Buildx
169-
uses: docker/setup-buildx-action@f211e3e9ded2d9377c8cadc4489a4e38014bc4c9 # tag=v1.7.0
254+
uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 # tag=v2.0.0
170255

171256
- name: Login to DockerHub
172-
uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 # tag=v1.14.1
257+
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b # tag=v2.0.0
173258
with:
174259
username: ${{ secrets.DOCKER_USERNAME }}
175260
password: ${{ secrets.DOCKER_PASSWORD }}
176261

177262
- name: Build and push
178-
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a # tag=v2.10.0
263+
uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8 # tag=v3.0.0
179264
with:
180265
context: .
181266
push: true

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16.15.0-alpine3.15@sha256:1a9a71ea86aad332aa7740316d4111ee1bd4e890df47d3b5eff3e5bded3b3d10
1+
FROM node:16.15.1-alpine3.15@sha256:1fafca8cf41faf035192f5df1a5387656898bec6ac2f92f011d051ac2344f5c9
22
ARG appPort=3000
33
# ARG microScannerToken
44

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.3'
22

33
services:
44
api:
5-
image: timoa/nodejs-encryption-api-example:latest@sha256:509d3424b92adb94f06ceedaa8044aaffed0e99015ae4b8dcb95be0a82c0a7b2
5+
image: timoa/nodejs-encryption-api-example:latest@sha256:f73079c8045d361899b8c372566616cba1249e61edcc6288549a2f3729dd3de6
66
environment:
77
- NODE_ENV=production
88
- NODE_HOST=0.0.0.0
@@ -17,7 +17,7 @@ services:
1717
- mongo
1818
mongo:
1919
container_name: mongo
20-
image: mongo@sha256:82a55eb6d60997007ff390087d4e064218d477e9611a7becd78664a2ab490eff
20+
image: mongo@sha256:37e84d3dd30cdfb5472ec42b8a6b4dc6ca7cacd91ebcfa0410a54528bbc5fa6d
2121
volumes:
2222
- ./data:/data/db
2323
ports:

0 commit comments

Comments
 (0)