Skip to content

Commit 45d182e

Browse files
Run vulnerability scan on latest release version (#441)
Previously the scan ran on the current state of the codebase. This fails to identify vulnerabilities in dependencies for the latest release version if those dependencies have already been updated in the development codebase. The gating factor for whether a new release is required should be whether the previous release contains vulnerabilities. This change runs the scheduled vulnerability scan on the latest release tag. It also adds vulnerability scanning to pull request builds. This is purely informational. A scan failure does not fail the pull request build. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent 7887093 commit 45d182e

File tree

3 files changed

+60
-25
lines changed

3 files changed

+60
-25
lines changed

.github/workflows/pull_request.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ jobs:
1717
test:
1818
uses: ./.github/workflows/test.yaml
1919

20+
scan:
21+
uses: ./.github/workflows/scan.yaml
22+
2023
pull-request:
2124
needs: test
2225
name: Pull request success
2326
runs-on: ubuntu-latest
2427
steps:
25-
- run: 'true'
28+
- run: "true"

.github/workflows/scan.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: "Security vulnerability scan"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
description: Branch, tag or SHA to scan.
8+
type: string
9+
required: false
10+
default: ""
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
# Job to handle the auditing of the code
17+
# NPM audit is run on a 'fake' installation of the libraries
18+
# Pulling in all the dependencies it will be able to run NPM AUDIT, and if that returns a
19+
# error code the job will fail.
20+
scan:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
ref: ${{ inputs.ref }}
26+
- uses: actions/setup-node@v4
27+
with:
28+
node-version: 18
29+
- name: Install
30+
run: node common/scripts/install-run-rush.js install
31+
- name: Build packages
32+
run: node common/scripts/install-run-rush.js publish --include-all --pack --release-folder tgz --publish
33+
- name: Start local NPM registry
34+
run: node common/scripts/install-run-rush.js start-verdaccio # script will check for the ci variable and use built images
35+
- name: Deploy scan project
36+
run: |
37+
mkdir -p audit
38+
cd audit
39+
npm init --yes
40+
npm install --save --package-lock-only --registry http://localhost:4873 fabric-shim fabric-shim-api fabric-contract-api
41+
- name: Scan
42+
working-directory: audit
43+
run: npm audit --omit=dev

.github/workflows/vulnerability-scan.yaml

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,18 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
# Job to handle the auditing of the code
13-
# NPM audit is run on a 'fake' installation of the libraries
14-
# Pulling in all the dependencies it will be able to run NPM AUDIT, and if that returns a
15-
# error code the job will fail.
16-
scan:
12+
latest-release-version:
13+
name: Get latest release tag
1714
runs-on: ubuntu-latest
15+
outputs:
16+
tag_name: ${{ steps.tag-name.outputs.value }}
1817
steps:
19-
- uses: actions/checkout@v4
20-
- uses: actions/setup-node@v4
21-
with:
22-
node-version: 18
23-
- name: Install
24-
run: node common/scripts/install-run-rush.js install
25-
- name: Build packages
26-
run: node common/scripts/install-run-rush.js publish --include-all --pack --release-folder tgz --publish
27-
- name: Start local NPM registry
28-
run: node common/scripts/install-run-rush.js start-verdaccio # script will check for the ci variable and use built images
29-
- name: Deploy scan project
30-
run: |
31-
mkdir -p audit
32-
cd audit
33-
npm init --yes
34-
npm install --save --package-lock-only --registry http://localhost:4873 fabric-shim fabric-shim-api fabric-contract-api
35-
- name: Scan
36-
working-directory: audit
37-
run: npm audit --omit=dev
18+
- id: tag-name
19+
run: echo "value=$(curl --location --silent --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest" | jq --raw-output '.tag_name')" >> "${GITHUB_OUTPUT}"
20+
21+
scan:
22+
name: Scan ${{ needs.latest-release-version.outputs.tag_name }}
23+
needs: latest-release-version
24+
uses: ./.github/workflows/scan.yaml
25+
with:
26+
ref: ${{ needs.latest-release-version.outputs.tag_name }}

0 commit comments

Comments
 (0)