Skip to content

Commit

Permalink
Merge pull request #102 from timoa/develop
Browse files Browse the repository at this point in the history
Update dependencies + hardening CI/CD
  • Loading branch information
timoa authored Jun 19, 2022
2 parents f62343d + 2da9582 commit 831408a
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 300 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
raw.githubusercontent.com:443
registry.npmjs.org:443
snyk.io:443
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

Expand All @@ -24,6 +36,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
raw.githubusercontent.com:443
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,28 @@ jobs:
contents: read

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
- name: Checkout repository
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

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

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

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

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
uses: github/codeql-action/analyze@27ea8f8fe5977c00f5b37e076ab846c5bd783b96 # tag=v2.1.12
157 changes: 121 additions & 36 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ jobs:
mongodb: ['5.0']

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
auth.docker.io:443
github.com:443
objects.githubusercontent.com:443
pipelines.actions.githubusercontent.com:443
production.cloudflare.docker.com:443
registry-1.docker.io:443
registry.npmjs.org:443
snyk.io:443
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

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

- name: Save Code Coverage
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # tag=v3.0.0
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0
with:
name: code-coverage
path: coverage
Expand All @@ -49,6 +64,16 @@ jobs:
needs: tests

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
pipelines.actions.githubusercontent.com:443
sonarcloud.io:443
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

Expand All @@ -67,32 +92,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# functional-tests:
# runs-on: ubuntu-latest
# needs: tests

# steps:
# - name: Checkout
# uses: actions/checkout@v2

# - name: Build docker image
# run: docker build -t timoa/nodejs-encryption-api-example .

# - name: Start Docker container
# run: docker-compose up -d

# - name: Check Docker container status
# run: docker ps -a

# - name: Install dependencies
# run: npm install

# - name: Run Functional tests
# run: npm run test:functional

# - name: Stop Docker container
# run: docker-compose down

# -- SAST SCAN --------------------------------------------------------------
code-security:
name: Code Security
Expand All @@ -102,32 +101,113 @@ jobs:
if: (github.actor != 'dependabot[bot]')

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: block
allowed-endpoints: >
github.com:443
api.github.com:443
pipelines.actions.githubusercontent.com:443
registry.npmjs.org:443
pypi.org:443
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Perform Scan
uses: ShiftLeftSecurity/scan-action@master

env:
WORKSPACE: https://github.com/${{ github.repository }}/blob/${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SCAN_ANNOTATE_PR: true

- uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # tag=v3.0.0
- name: Save the SCAN reports
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0
with:
name: reports
name: sast-reports
path: reports

# -- ZAP Scan ---------------------------------------------------------------
api-security:
name: API Security
runs-on: ubuntu-latest
needs: tests
# Skip any PR created by dependabot to avoid permission issues
if: (github.actor != 'dependabot[bot]')

strategy:
matrix:
node: ['16']
mongodb: ['5.0']

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@dd5681a7d0c66fb362664d618ef4a90d656f6516
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
auth.docker.io:443
bit.ly:443
content-signature-2.cdn.mozilla.net:443
firefox.settings.services.mozilla.com:443
github.com:443
news.zaproxy.org:443
objects.githubusercontent.com:443
pipelines.actions.githubusercontent.com:443
production.cloudflare.docker.com:443
raw.githubusercontent.com:443
registry-1.docker.io:443
registry.npmjs.org:443
shavar.services.mozilla.com:443
snyk.io:443
tel.zaproxy.org:443
tracking-protection.cdn.mozilla.net:443
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048 # tag=v3.2.0
with:
node-version: ${{ matrix.node }}
check-latest: true

- name: Install dependencies
run: npm install

- name: Start MongoDB
uses: supercharge/mongodb-github-action@e815fd8a9dfede09fd6e6c144f2c9f4875e933df # tag=1.7.0
with:
mongodb-version: ${{ matrix.mongodb }}
mongodb-db: encryptionAPI

- name: Start the app
run: npm start > /dev/null &

- name: Run ZAP Scan
uses: zaproxy/[email protected]
with:
target: http://localhost:3000

# -- PRE-RELEASE ------------------------------------------------------------
pre-release:
name: Prepare Release
runs-on: ubuntu-latest
needs:
- code-quality
- code-security
- api-security
if: github.ref == 'refs/heads/master'

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

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

steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@cdea734fa57747b9831aa9d6fcb274c5f9669557
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2

- name: Docker meta
id: meta
uses: docker/metadata-action@b2391d37b4157fa4aa2e118d643f417910ff3242 # tag=v3.8.0
uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a # tag=v4.0.1
with:
images: ${{ github.repository }}
tags: |
Expand All @@ -163,19 +248,19 @@ jobs:
type=raw,value=latest
- name: Set up QEMU
uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 # tag=v1.2.0
uses: docker/setup-qemu-action@8b122486cedac8393e77aa9734c3528886e4a1a8 # tag=v2.0.0

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

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

- name: Build and push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a # tag=v2.10.0
uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8 # tag=v3.0.0
with:
context: .
push: true
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.15.0-alpine3.15@sha256:1a9a71ea86aad332aa7740316d4111ee1bd4e890df47d3b5eff3e5bded3b3d10
FROM node:16.15.1-alpine3.15@sha256:1fafca8cf41faf035192f5df1a5387656898bec6ac2f92f011d051ac2344f5c9
ARG appPort=3000
# ARG microScannerToken

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.3'

services:
api:
image: timoa/nodejs-encryption-api-example:latest@sha256:509d3424b92adb94f06ceedaa8044aaffed0e99015ae4b8dcb95be0a82c0a7b2
image: timoa/nodejs-encryption-api-example:latest@sha256:f73079c8045d361899b8c372566616cba1249e61edcc6288549a2f3729dd3de6
environment:
- NODE_ENV=production
- NODE_HOST=0.0.0.0
Expand All @@ -17,7 +17,7 @@ services:
- mongo
mongo:
container_name: mongo
image: mongo@sha256:82a55eb6d60997007ff390087d4e064218d477e9611a7becd78664a2ab490eff
image: mongo@sha256:37e84d3dd30cdfb5472ec42b8a6b4dc6ca7cacd91ebcfa0410a54528bbc5fa6d
volumes:
- ./data:/data/db
ports:
Expand Down
Loading

0 comments on commit 831408a

Please sign in to comment.