Skip to content

Commit 9a596e6

Browse files
Support allow lists in Trivy
1 parent fc278ab commit 9a596e6

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ on:
3737
description: Push scanned images that have vulnerabilities?
3838
type: boolean
3939
required: false
40-
# NOTE(Alex-Welsh): This default should be flipped once we resolve existing failures
41-
default: true
40+
default: false
4241

4342
env:
4443
ANSIBLE_FORCE_COLOR: True
@@ -136,6 +135,10 @@ jobs:
136135
run: |
137136
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin v0.49.0
138137
138+
- name: Install yq
139+
run: |
140+
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
141+
139142
- name: Install Kayobe
140143
run: |
141144
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,25 @@ 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+
if [ $rc -eq 0 ]; then
47+
echo $vulnerability >> .trivyignore
48+
fi
49+
done
3750
if $(trivy image \
3851
--quiet \
3952
--exit-code 1 \
4053
--scanners vuln \
4154
--format json \
42-
--severity HIGH,CRITICAL \
55+
--severity CRITICAL \
4356
--output image-scan-output/${filename}.json \
4457
--ignore-unfixed \
4558
$image); then
@@ -76,4 +89,5 @@ for image in $images; do
7689
| .[]
7790
| @csv' image-scan-output/${filename}.json >> image-scan-output/${filename}.summary.csv
7891
fi
92+
rm .trivyignore
7993
done

0 commit comments

Comments
 (0)