@@ -27,11 +27,13 @@ docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/$1-*:$2" > $1-
27
27
images=$( grep --invert-match --no-filename ^REPOSITORY $1 -scanned-container-images.txt | sed ' s/ \+/:/g' | cut -f 1,2 -d:)
28
28
29
29
# Ensure output files exist
30
- touch image-scan-output/clean-images.txt image-scan-output/dirty-images.txt
30
+ touch image-scan-output/clean-images.txt image-scan-output/dirty-images.txt image-scan-output/critical-images.txt
31
31
32
32
# If Trivy detects no vulnerabilities, add the image name to clean-images.txt.
33
33
# If there are vulnerabilities detected, add it to dirty-images.txt and
34
34
# generate a csv summary
35
+ # If the image contains at least one critical vulnerabilities, add it to
36
+ # critical-images.txt
35
37
for image in $images ; do
36
38
filename=$( basename $image | sed ' s/:/\./g' )
37
39
if $( trivy image \
@@ -51,13 +53,13 @@ for image in $images; do
51
53
else
52
54
# Add the image to the dirty list
53
55
echo " ${image} " >> image-scan-output/dirty-images.txt
54
-
56
+
55
57
# Write a header for the summary CSV
56
58
echo ' "PkgName","PkgPath","PkgID","VulnerabilityID","FixedVersion","PrimaryURL","Severity"' > image-scan-output/${filename} .summary.csv
57
59
58
60
# Write the summary CSV data
59
- jq -r ' .Results[]
60
- | select(.Vulnerabilities)
61
+ jq -r ' .Results[]
62
+ | select(.Vulnerabilities)
61
63
| .Vulnerabilities
62
64
# Ignore packages with "kernel" in the PkgName
63
65
| map(select(.PkgName | test("kernel") | not ))
@@ -72,8 +74,13 @@ for image in $images; do
72
74
.[0].PrimaryURL,
73
75
.[0].Severity
74
76
]
75
- )
76
- | .[]
77
+ )
78
+ | .[]
77
79
| @csv' image-scan-output/${filename} .json >> image-scan-output/${filename} .summary.csv
80
+
81
+ if [ $( grep " CRITICAL" image-scan-output/${filename} .summary.csv -c) -gt 0 ]; then
82
+ # If the image contains critical vulnerabilities, add the image to critical list
83
+ echo " ${image} " >> image-scan-output/critical-images.txt
84
+ fi
78
85
fi
79
86
done
0 commit comments