Skip to content

Commit c2576ba

Browse files
Merge pull request #4332 from bcgov/506-add-trivy-container-scanning-to-CI
506 Add trivy container scanning to CI
2 parents 9f65e01 + 95f55be commit c2576ba

3 files changed

Lines changed: 71 additions & 3 deletions

File tree

.github/workflows/main.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ jobs:
132132
nx_project: compliance
133133
secrets: inherit
134134
trivy:
135+
needs:
136+
[
137+
build-backend,
138+
build-administration,
139+
build-compliance,
140+
build-dashboard,
141+
build-registration,
142+
build-reporting,
143+
]
135144
uses: ./.github/workflows/trivy.yaml
136145
codeql:
137146
uses: ./.github/workflows/codeql.yaml

.github/workflows/nightly.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ jobs:
127127
uses: ./.github/workflows/schemaspy.yaml
128128
secrets: inherit
129129
trivy:
130+
needs:
131+
[
132+
build-backend,
133+
build-administration,
134+
build-compliance,
135+
build-dashboard,
136+
build-registration,
137+
build-reporting,
138+
]
130139
uses: ./.github/workflows/trivy.yaml
131140
codeql:
132141
uses: ./.github/workflows/codeql.yaml

.github/workflows/trivy.yaml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
with:
1616
path: ~/.cache/trivy
1717
key: callee-trivy-${{ github.workflow }}-${{ github.run_id }}
18-
restore-keys: trivy-
18+
restore-keys: callee-trivy-${{ github.workflow }}-
1919
- name: Run Trivy vulnerability scanner in repo mode
20-
uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8
20+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
2121
with:
2222
scan-type: fs
2323
scan-ref: "."
@@ -29,7 +29,7 @@ jobs:
2929
timeout: 10m0s
3030
scanners: vuln,secret,config
3131
- name: Upload Trivy scan results to GitHub Security tab
32-
uses: github/codeql-action/upload-sarif@v3
32+
uses: github/codeql-action/upload-sarif@v4
3333
with:
3434
sarif_file: trivy-results.sarif
3535
category: trivy-code-scan
@@ -38,3 +38,53 @@ jobs:
3838
with:
3939
name: trivy-results
4040
path: trivy-results.sarif
41+
42+
scan-containers:
43+
runs-on: ubuntu-latest
44+
timeout-minutes: 60
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
include:
49+
- image: cas-reg-backend
50+
category: trivy-container-backend
51+
- image: cas-reg-frontend
52+
category: trivy-container-registration
53+
- image: cas-admin-frontend
54+
category: trivy-container-administration
55+
- image: cas-compliance-frontend
56+
category: trivy-container-compliance
57+
- image: cas-dash-frontend
58+
category: trivy-container-dashboard
59+
- image: cas-rep-frontend
60+
category: trivy-container-reporting
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v6
64+
- name: Cache Scan Dependencies
65+
uses: actions/cache@v4
66+
with:
67+
path: ~/.cache/trivy
68+
key: callee-trivy-${{ github.workflow }}-${{ github.run_id }}
69+
restore-keys: callee-trivy-${{ github.workflow }}-
70+
- name: Run Trivy vulnerability scanner on container image
71+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
72+
with:
73+
scan-type: image
74+
image-ref: ghcr.io/bcgov/${{ matrix.image }}:${{ github.sha }}
75+
format: sarif
76+
output: trivy-container-results.sarif
77+
exit-code: "0"
78+
ignore-unfixed: false
79+
severity: CRITICAL,HIGH,MEDIUM
80+
timeout: 10m0s
81+
- name: Upload Trivy container scan results to GitHub Security tab
82+
uses: github/codeql-action/upload-sarif@v4
83+
with:
84+
sarif_file: trivy-container-results.sarif
85+
category: ${{ matrix.category }}
86+
- name: Upload Trivy container scan results as artifact
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: trivy-container-results-${{ matrix.image }}
90+
path: trivy-container-results.sarif

0 commit comments

Comments
 (0)