Skip to content

Commit d3bf5da

Browse files
feat: add cron-job to update Trivy (#256)
**Proposed Changes** Added cron-job to update Trivy's database daily and store it in cache I submit this contribution under the Apache-2.0 license.
1 parent 7ef3b34 commit d3bf5da

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

.github/workflows/security.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232

3333
- name: Set up Docker Buildx
3434
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb #v3.3.0
35-
3635

3736
trivy-scanning:
3837
runs-on: ubuntu-latest
@@ -48,17 +47,20 @@ jobs:
4847
file: ./Dockerfile
4948
platforms: linux/amd64
5049
push: false
51-
tags: |
52-
checkmarx/2ms:scanme
50+
tags: checkmarx/2ms:scanme
51+
52+
- name: Run Trivy Scan
53+
uses: aquasecurity/trivy-action@915b19bbe73b92a6cf82a1bc12b087c9a19a5fe2 # v0.28.0
54+
with:
55+
image-ref: checkmarx/2ms:scanme
56+
vuln-type: os,library
57+
format: table
58+
ignore-unfixed: true
59+
severity: CRITICAL,HIGH,MEDIUM,LOW
60+
trivy-config: trivy.yaml
61+
exit-code: '1'
62+
5363

54-
- name: Install trivy and Run it
55-
run: |
56-
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
57-
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
58-
sudo apt-get update && sudo apt-get install -y trivy
59-
trivy image checkmarx/2ms:scanme --exit-code 1 \
60-
--ignore-unfixed --vuln-type os,library --no-progress --severity CRITICAL,HIGH,MEDIUM,LOW --vex ./ignore.openvex
61-
6264
secret-scanning:
6365
runs-on: ubuntu-latest
6466
steps:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Update Trivy Cache
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Run daily at midnight UTC
6+
workflow_dispatch: # Allow manual triggering
7+
8+
jobs:
9+
update-trivy-db:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Setup oras
13+
uses: oras-project/setup-oras@9c92598691bfef1424de2f8fae81941568f5889c # v1.2.1
14+
15+
- name: Get current date
16+
id: date
17+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
18+
19+
- name: Download and extract the vulnerability DB
20+
run: |
21+
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db
22+
oras pull ghcr.io/aquasecurity/trivy-db:2
23+
tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db
24+
rm db.tar.gz
25+
26+
- name: Download and extract the Java DB
27+
run: |
28+
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db
29+
oras pull ghcr.io/aquasecurity/trivy-java-db:1
30+
tar -xzf javadb.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/java-db
31+
rm javadb.tar.gz
32+
33+
- name: Cache DBs
34+
uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.2.1
35+
with:
36+
path: ${{ github.workspace }}/.cache/trivy
37+
key: cache-trivy-${{ steps.date.outputs.date }}

trivy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vulnerability:
2+
vex:
3+
- ignore.openvex

0 commit comments

Comments
 (0)