Skip to content

Commit 273aca0

Browse files
authored
Merge pull request #100 from timoa/develop
Update security + dependencies
2 parents 7943822 + f2ad318 commit 273aca0

File tree

11 files changed

+282
-132
lines changed

11 files changed

+282
-132
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@timoa

.github/workflows/code-review.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Code Review
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
7+
# -- ESLINT -----------------------------------------------------------------
8+
eslint:
9+
name: ESLint
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
15+
16+
- name: Run ESLint
17+
uses: reviewdog/action-eslint@d3395027ea2cfc5cf8f460b1ea939b6c86fea656 # tag=v1.17.0
18+
env:
19+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
21+
# -- DOCKER -----------------------------------------------------------------
22+
hadolint:
23+
name: Hadolint
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
29+
30+
- name: Run hadolint
31+
uses: reviewdog/action-hadolint@55be5d2c4b0b80d439247b128a9ded3747f92a29 # tag=v1.33.0
32+
env:
33+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,61 @@
1-
name: "CodeQL"
1+
name: "CodeQL analysis"
22

33
on:
44
push:
5-
branches: [master, ]
5+
branches: [main]
66
pull_request:
7-
# The branches below must be a subset of the branches above
8-
branches: [master]
7+
branches: [main]
98
schedule:
10-
- cron: '0 7 * * 0'
9+
# ┌───────────── minute (0 - 59)
10+
# │ ┌───────────── hour (0 - 23)
11+
# │ │ ┌───────────── day of the month (1 - 31)
12+
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
13+
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
14+
# │ │ │ │ │
15+
# │ │ │ │ │
16+
# │ │ │ │ │
17+
# * * * * *
18+
- cron: '30 1 * * 0'
1119

1220
jobs:
13-
analyze:
14-
name: Analyze
21+
CodeQL-Build:
22+
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
1523
runs-on: ubuntu-latest
1624

25+
permissions:
26+
# required for all workflows
27+
security-events: write
28+
29+
# only required for workflows in private repositories
30+
actions: read
31+
contents: read
32+
1733
steps:
18-
- name: Checkout repository
19-
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
20-
with:
21-
# We must fetch at least the immediate parents so that if this is
22-
# a pull request then we can checkout the head.
23-
fetch-depth: 2
24-
25-
# If this run was triggered by a pull request event, then checkout
26-
# the head of the pull request instead of the merge commit.
27-
- run: git checkout HEAD^2
28-
if: ${{ github.event_name == 'pull_request' }}
29-
30-
# Initializes the CodeQL tools for scanning.
31-
- name: Initialize CodeQL
32-
uses: github/codeql-action/init@e2cc7cc006b87d43538b16d71752753e7b85224d # tag=v1.1.8
33-
# Override language selection by uncommenting this and choosing your languages
34-
# with:
35-
# languages: go, javascript, csharp, python, cpp, java
36-
37-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
38-
# If this step fails, then you should remove it and run the build manually (see below)
39-
- name: Autobuild
40-
uses: github/codeql-action/autobuild@e2cc7cc006b87d43538b16d71752753e7b85224d # tag=v1.1.8
41-
42-
# ℹ️ Command-line programs to run using the OS shell.
43-
# 📚 https://git.io/JvXDl
44-
45-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
46-
# and modify them (or add more) to build your code if your project
47-
# uses a compiled language
48-
49-
#- run: |
50-
# make bootstrap
51-
# make release
52-
53-
- name: Perform CodeQL Analysis
54-
uses: github/codeql-action/analyze@e2cc7cc006b87d43538b16d71752753e7b85224d # tag=v1.1.8
34+
- name: Checkout repository
35+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
36+
37+
# Initializes the CodeQL tools for scanning.
38+
- name: Initialize CodeQL
39+
uses: github/codeql-action/init@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
40+
# Override language selection by uncommenting this and choosing your languages
41+
# with:
42+
# languages: go, javascript, csharp, python, cpp, java
43+
44+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
45+
# If this step fails, then you should remove it and run the build manually (see below).
46+
- name: Autobuild
47+
uses: github/codeql-action/autobuild@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10
48+
49+
# ℹ️ Command-line programs to run using the OS shell.
50+
# 📚 https://git.io/JvXDl
51+
52+
# ✏️ If the Autobuild fails above, remove it and uncomment the following
53+
# three lines and modify them (or add more) to build your code if your
54+
# project uses a compiled language
55+
56+
#- run: |
57+
# make bootstrap
58+
# make release
59+
60+
- name: Perform CodeQL Analysis
61+
uses: github/codeql-action/analyze@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b # tag=v2.1.10

.github/workflows/nodejs.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66

77
# -- TESTS ------------------------------------------------------------------
88
tests:
9+
name: Tests
910
runs-on: ubuntu-latest
1011

1112
strategy:
@@ -15,10 +16,10 @@ jobs:
1516

1617
steps:
1718
- name: Checkout
18-
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
19+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
1920

2021
- name: Setup Node.js ${{ matrix.node }}
21-
uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3
22+
uses: actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3.1.1
2223
with:
2324
node-version: ${{ matrix.node }}
2425
check-latest: true
@@ -43,12 +44,13 @@ jobs:
4344

4445
# -- SONARCLOUD -------------------------------------------------------------
4546
code-quality:
47+
name: Code Quality
4648
runs-on: ubuntu-latest
4749
needs: tests
4850

4951
steps:
5052
- name: Checkout
51-
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
53+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
5254

5355
- name: Download Code Coverage
5456
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
@@ -93,14 +95,15 @@ jobs:
9395

9496
# -- SAST SCAN --------------------------------------------------------------
9597
code-security:
98+
name: Code Security
9699
runs-on: ubuntu-latest
97100
needs: tests
98101
# Skip any PR created by dependabot to avoid permission issues
99102
if: (github.actor != 'dependabot[bot]')
100103

101104
steps:
102105
- name: Checkout
103-
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 # tag=v3
106+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
104107

105108
- name: Perform Scan
106109
uses: ShiftLeftSecurity/scan-action@master
@@ -115,8 +118,9 @@ jobs:
115118
name: reports
116119
path: reports
117120

118-
# -- RELEASE ----------------------------------------------------------------
119-
release:
121+
# -- PRE-RELEASE ------------------------------------------------------------
122+
pre-release:
123+
name: Prepare Release
120124
runs-on: ubuntu-latest
121125
needs:
122126
- code-quality
@@ -125,7 +129,7 @@ jobs:
125129

126130
steps:
127131
- name: Checkout
128-
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 # tag=v3
132+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
129133

130134
- name: Semantic Release
131135
uses: cycjimmy/semantic-release-action@v3
@@ -134,17 +138,18 @@ jobs:
134138

135139
# -- BUILD ------------------------------------------------------------------
136140
build:
141+
name: Build & Release
137142
runs-on: ubuntu-latest
138-
needs: release
143+
needs: pre-release
139144
if: github.ref == 'refs/heads/master'
140145

141146
steps:
142147
- name: Checkout
143-
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
148+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
144149

145150
- name: Docker meta
146151
id: meta
147-
uses: docker/metadata-action@e5622373a38e60fb6d795a4421e56882f2d7a681 # tag=v3.6.2
152+
uses: docker/metadata-action@b2391d37b4157fa4aa2e118d643f417910ff3242 # tag=v3.8.0
148153
with:
149154
images: ${{ github.repository }}
150155
tags: |
@@ -161,7 +166,7 @@ jobs:
161166
uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 # tag=v1.2.0
162167

163168
- name: Set up Docker Buildx
164-
uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # tag=v1.6.0
169+
uses: docker/setup-buildx-action@f211e3e9ded2d9377c8cadc4489a4e38014bc4c9 # tag=v1.7.0
165170

166171
- name: Login to DockerHub
167172
uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 # tag=v1.14.1

.releaserc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"repositoryUrl": "https://github.com/timoa/nodejs-encryption-api-example.git",
23
"branches": [
34
"master",
45
"develop"

Dockerfile

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

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Encryption API endpoints with Node.js
22

3+
[![Latest Release][release-badge]][release-url]
34
[![Build Status][github-badge]][github-url]
45
[![Docker Pulls][docker-badge]][docker-url]
6+
57
[![Quality Gate Status][sonarcloud-status-badge]][sonarcloud-url]
68
[![Security Rating][sonarcloud-security-badge]][sonarcloud-url]
79
[![Maintainability Rating][sonarcloud-maintainability-badge]][sonarcloud-url]
@@ -21,17 +23,18 @@ The idea with this example is to test how to store encrypted data under a datast
2123
2224
## Features
2325

24-
- API storing endpoint that encrypts data with the provided key and stores it into a MongoDB collection (AES-256-CBC encryption)
26+
- API storing endpoint that encrypts data with the provided key and stores it into a MongoDB collection (AES-256-GCM encryption)
2527
- API retrieval endpoint that decrypts data with the provided key and returns the data
26-
- AES-256-CBC encryption that uses a random Initialization Vector (IV)
27-
- IV stored with the encrypted data (separated by a `:` character)
28+
- AES-256-GCM encryption that uses a random Initialization Vector (IV) and Auth TAG
29+
- IV and Auth TAG stored with the encrypted data (separated by a `:` character)
2830
- Logs with correlation ID
31+
- Hardening of the HTTP Headers with Helmet
2932
- MongoDB as a data store (using Mongoose)
3033
- Swagger support for API specifications/documentation (WIP)
3134
- Health check endpoint to check if the app is still alive
3235
- Dockerfile to generate the Docker image
3336
- Docker Compose file to launch the API and MongoDB official Docker images
34-
- Build, test and deploy to Docker Hub with Travis CI
37+
- Build, test and deploy to Docker Hub with GitHub Actions
3538
- SonarQube code quality check (SonarCloud)
3639
- Unit tests and functional tests
3740
- Postman collection and environment
@@ -247,6 +250,8 @@ This will return an array of results:
247250
[postman-run-button]: https://run.pstmn.io/button.svg
248251
[postman-run-url]: https://app.getpostman.com/run-collection/e34aee6688c0937c6643
249252
[sonarcloud]: https://sonarcloud.io/about
253+
[release-badge]: https://img.shields.io/github/v/release/timoa/nodejs-encryption-api-example?logoColor=orange
254+
[release-url]: https://github.com/timoa/nodejs-encryption-api-example/releases
250255
[github-badge]: https://github.com/timoa/nodejs-encryption-api-example/workflows/Build/badge.svg
251256
[github-url]: https://github.com/timoa/nodejs-encryption-api-example/actions?query=workflow%3ABuild
252257
[docker-badge]: https://img.shields.io/docker/pulls/timoa/nodejs-encryption-api-example.svg
@@ -258,4 +263,4 @@ This will return an array of results:
258263
[sonarcloud-bugs-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=bugs
259264
[sonarcloud-codesmells-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=code_smells
260265
[sonarcloud-coverage-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=coverage
261-
[sonarcloud-duplicated-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=duplicated_lines_densit
266+
[sonarcloud-duplicated-badge]: https://sonarcloud.io/api/project_badges/measure?project=timoa_nodejs-encryption-api-example&metric=duplicated_lines_density

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:7348a5690fde457457ef0b171c992ae877af7e2084e6b384c096c85047188f78
5+
image: timoa/nodejs-encryption-api-example:latest@sha256:509d3424b92adb94f06ceedaa8044aaffed0e99015ae4b8dcb95be0a82c0a7b2
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:1e72fdd16fc769e5200dad77eff5b2316730d42473c281d8192872698e1f8689
20+
image: mongo@sha256:82a55eb6d60997007ff390087d4e064218d477e9611a7becd78664a2ab490eff
2121
volumes:
2222
- ./data:/data/db
2323
ports:

0 commit comments

Comments
 (0)