Skip to content

Commit 53d702f

Browse files
authored
Scan images using Trivy (#685)
* Scan images using Trivy * use python 3.12 base image python 3.12.4 did not work, which is why the version was pinned to 3.12.3. However, the most recent python 3.12 version should work again. * continue to build and scan images after one build / scan fails e.g. when python 3.10 is vulnerable and fails, we still want to scan 3.11 and 3.12. * add trivy config and ignore file
1 parent d00ca61 commit 53d702f

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

.github/workflows/ci.yml

+36-6
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ jobs:
9595

9696
containerbuild:
9797
strategy:
98+
fail-fast: false
9899
matrix:
99-
python-version: ["3.10", "3.11", "3.12.3"]
100+
python-version: ["3.10", "3.11", "3.12"]
100101

101102
runs-on: ubuntu-latest
102103
steps:
@@ -111,7 +112,7 @@ jobs:
111112
username: ${{ github.actor }}
112113
password: ${{ secrets.GITHUB_TOKEN }}
113114

114-
- name: Build and export to Docker
115+
- name: Build image and export to Docker
115116
uses: docker/build-push-action@v6
116117
with:
117118
context: .
@@ -122,17 +123,46 @@ jobs:
122123
tags: |
123124
ghcr.io/fkie-cad/logprep:py${{ matrix.python-version }}-${{ github.head_ref }}
124125
125-
- name: Test
126+
- name: Ensure logprep is available in image
126127
run: |
127128
docker run --rm ghcr.io/fkie-cad/logprep:py${{ matrix.python-version }}-${{ github.head_ref }} --version
128-
129-
- name: Build images
129+
130+
# This step will build the image again, but every layer will already be cached, so it is nearly instantaneous.
131+
- name: Push image
130132
uses: docker/build-push-action@v5
131133
with:
132134
context: .
133-
push: true # Will only build if this is not here
135+
push: true
134136
build-args: |
135137
LOGPREP_VERSION=dev
136138
PYTHON_VERSION=${{ matrix.python-version }}
137139
tags: |
138140
ghcr.io/fkie-cad/logprep:py${{ matrix.python-version }}-${{ github.head_ref }}
141+
142+
# To avoid the trivy-db becoming outdated, we save the cache for one day
143+
- name: Get date
144+
id: date
145+
run: echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT
146+
147+
- name: Restore trivy cache
148+
uses: actions/cache@v4
149+
with:
150+
path: cache/db
151+
key: trivy-cache-${{ steps.date.outputs.date }}
152+
restore-keys:
153+
trivy-cache-
154+
155+
- name: Scan image using Trivy
156+
uses: aquasecurity/[email protected]
157+
env:
158+
TRIVY_CACHE_DIR: ./cache
159+
with:
160+
scan-type: image
161+
image-ref: ghcr.io/fkie-cad/logprep:py${{ matrix.python-version }}-${{ github.head_ref }}
162+
trivy-config: trivy.yaml
163+
164+
# Trivy-db uses `0600` permissions.
165+
# But `action/cache` use `runner` user by default
166+
# So we need to change the permissions before caching the database.
167+
- name: Change permissions for trivy.db
168+
run: sudo chmod 0644 ./cache/db/trivy.db

.github/workflows/publish-latest-dev-release-to-pypi.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
containerbuild:
5050
strategy:
5151
matrix:
52-
python-version: ["3.10", "3.11", "3.12.3"]
52+
python-version: ["3.10", "3.11", "3.12"]
5353

5454
runs-on: ubuntu-latest
5555
steps:

.github/workflows/publish-release-to-pypi.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
containerbuild:
6363
strategy:
6464
matrix:
65-
python-version: ["3.10", "3.11", "3.12.3"]
65+
python-version: ["3.10", "3.11", "3.12"]
6666

6767
runs-on: ubuntu-latest
6868
needs: publish-latest-release-to-pypi

.github/workflows/testing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-22.04
1515
strategy:
1616
matrix:
17-
python-version: ["3.10", "3.11", "3.12.3"]
17+
python-version: ["3.10", "3.11", "3.12"]
1818
test-type: ["unit", "acceptance"]
1919
steps:
2020
- uses: actions/checkout@v4

.trivyignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore Python 3.10 CVE that is only fixed in Python 3.11 as long as we still support Python 3.10.
2+
CVE-2023-36632

trivy.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# https://aquasecurity.github.io/trivy/v0.56/docs/references/configuration/config-file/
2+
format: table
3+
report: all
4+
ignorefile: .trivyignore
5+
exit-code: 1
6+
severity:
7+
- HIGH
8+
- CRITICAL
9+
timeout: 10m
10+
scan:
11+
scanners:
12+
- vuln
13+
- secret
14+
vulnerability:
15+
ignore-unfixed: true

0 commit comments

Comments
 (0)