Skip to content

Commit 6d1856c

Browse files
Support trivy allow lists per image
1 parent fc278ab commit 6d1856c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.github/workflows/stackhpc-container-image-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ jobs:
136136
run: |
137137
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.49.0
138138
139+
- name: Install yq
140+
run: |
141+
curl -sL https://github.com/mikefarah/yq/releases/download/v4.42.1/yq_linux_amd64.tar.gz | tar xz && sudo mv yq_linux_amd64 /usr/bin/yq
142+
139143
- name: Install Kayobe
140144
run: |
141145
mkdir -p venvs &&
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
###############################################################################
3+
# Trivy allowed vulnerabilities list
4+
5+
# Example allowed vulnerabilities file setup
6+
#
7+
# keystone_allowed_vulnerabilities:
8+
# - CVE-2022-2447
9+
#
10+
# barbican-api_allowed_vulnerabilities:
11+
# - CVE-2023-31047
12+
13+
global_allowed_vulnerabilities:
14+
- CVE-2024-36039
15+
16+
###############################################################################
17+
# Dummy variable to allow Ansible to accept this file.
18+
workaround_ansible_issue_8743: yes

tools/scan-images.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,28 @@ touch image-scan-output/clean-images.txt image-scan-output/dirty-images.txt
3434
# generate a csv summary
3535
for image in $images; do
3636
filename=$(basename $image | sed 's/:/\./g')
37+
imagename=$(echo $filename | cut -d "." -f 1)
38+
global_vulnerabilities=$(yq .global_allowed_vulnerabilities[] src/kayobe-config/etc/kayobe/trivy/allowed-vulnerabilities.yml)
39+
image_vulnerabilities=$(yq .$imagename'_allowed_vulnerabilities[]' src/kayobe-config/etc/kayobe/trivy/allowed-vulnerabilities.yml)
40+
rc=$?
41+
touch .trivyignore
42+
for vulnerability in $global_vulnerabilities; do
43+
echo $vulnerability >> .trivyignore
44+
done
45+
for vulnerability in $image_vulnerabilities; do
46+
echo $vulnerability
47+
if [ $rc -eq 0 ]; then
48+
echo $vulnerability >> .trivyignore
49+
fi
50+
done
51+
echo $imagename
52+
cat .trivyignore
3753
if $(trivy image \
38-
--quiet \
54+
--debug \
3955
--exit-code 1 \
4056
--scanners vuln \
4157
--format json \
42-
--severity HIGH,CRITICAL \
58+
--severity CRITICAL \
4359
--output image-scan-output/${filename}.json \
4460
--ignore-unfixed \
4561
$image); then
@@ -76,4 +92,5 @@ for image in $images; do
7692
| .[]
7793
| @csv' image-scan-output/${filename}.json >> image-scan-output/${filename}.summary.csv
7894
fi
95+
rm .trivyignore
7996
done

0 commit comments

Comments
 (0)