Skip to content

Commit 5bdbf7b

Browse files
author
hubert.siwik
committed
feat: Add Trivy scanner to the pipeline
1 parent 1ef072c commit 5bdbf7b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

.github/workflows/cron.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# In your scan workflow, set TRIVY_SKIP_DB_UPDATE=true.
2+
name: Update the trivy cache
3+
4+
on:
5+
schedule:
6+
- cron: '0 0 * * *' # Run daily at midnight UTC
7+
workflow_dispatch: # Allow manual triggering
8+
9+
jobs:
10+
update-trivy-db:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Get current date
14+
id: date
15+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
16+
17+
- name: Download and extract the vulnerability DB
18+
run: |
19+
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db
20+
oras pull ghcr.io/aquasecurity/trivy-db:2
21+
tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db
22+
rm db.tar.gz
23+
24+
- name: Download and extract the Java DB
25+
run: |
26+
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db
27+
oras pull ghcr.io/aquasecurity/trivy-java-db:1
28+
tar -xzf javadb.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/java-db
29+
rm javadb.tar.gz
30+
31+
- name: Cache DBs
32+
uses: actions/cache/save@v4
33+
with:
34+
path: ${{ github.workspace }}/.cache/trivy
35+
key: cache-trivy-${{ steps.date.outputs.date }}

.github/workflows/verifyimage.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
outputs:
1616
targets: ${{ steps.generate.outputs.targets }}
17+
repo: ${{ steps.metadata.outputs.repo }}
1718
steps:
1819
- name: Checkout
1920
uses: actions/checkout@v4
@@ -25,6 +26,10 @@ jobs:
2526
curl -sSL https://raw.githubusercontent.com/owasp-modsecurity/ModSecurity/v3/master/modsecurity.conf-recommended -o modsecurity.conf-recommended
2627
echo '${{ env.MODSECURITY_RECOMMENDED }}' > sha256sum.txt
2728
sha256sum -c sha256sum.txt
29+
# The environment variable is not accessible in the context of "with" section
30+
- name: Set a repo output
31+
id: metadata
32+
run: echo "repo=${REPO}" >> "$GITHUB_OUTPUT"
2833

2934
build:
3035
runs-on: ubuntu-latest
@@ -60,6 +65,20 @@ jobs:
6065
load: true
6166
push: false
6267

68+
- name: Scan ${{ matrix.target }}
69+
uses: aquasecurity/trivy-action@0.27.0
70+
with:
71+
image-ref: ${{ needs.prepare.outputs.repo }}:${{ matrix.target }}
72+
format: 'table'
73+
exit-code: '1'
74+
ignore-unfixed: true
75+
vuln-type: 'os,library'
76+
severity: 'CRITICAL,HIGH'
77+
scanners: 'vuln,secret'
78+
env:
79+
TRIVY_SKIP_DB_UPDATE: true
80+
# TRIVY_SKIP_JAVA_DB_UPDATE: true
81+
6382
- name: Run ${{ matrix.target }}
6483
run: |
6584
echo "Starting container ${{ matrix.target }}"

0 commit comments

Comments
 (0)