Skip to content

Commit 0c07da3

Browse files
authored
Merge pull request #1080 from stackhpc/fail-kolla-image-build-when-critical-cve
Fail kolla image build when critical CVEs are detected
2 parents 928f96c + 9c4c16e commit 0c07da3

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ on:
3939
required: false
4040
default: true
4141
push-dirty:
42-
description: Push scanned images that have vulnerabilities?
42+
description: Push scanned images that have critical vulnerabilities?
4343
type: boolean
4444
required: false
45-
# NOTE(Alex-Welsh): This default should be flipped once we resolve existing failures
46-
default: true
45+
default: false
4746

4847
env:
4948
ANSIBLE_FORCE_COLOR: True
@@ -181,7 +180,7 @@ jobs:
181180
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
182181

183182
- name: Create build logs output directory
184-
run: mkdir image-build-logs
183+
run: mkdir image-build-logs
185184

186185
- name: Build kolla overcloud images
187186
id: build_overcloud_images
@@ -240,9 +239,16 @@ jobs:
240239
run: cp image-build-logs/image-scan-output/clean-images.txt image-build-logs/push-attempt-images.txt
241240
if: inputs.push
242241

242+
# NOTE(seunghun1ee): This always appends dirty images with CVEs severity lower than critical.
243+
# This should be reverted when it's decided to filter high level CVEs as well.
243244
- name: Append dirty images to push list
244245
run: |
245246
cat image-build-logs/image-scan-output/dirty-images.txt >> image-build-logs/push-attempt-images.txt
247+
if: ${{ inputs.push }}
248+
249+
- name: Append images with critical vulnerabilities to push list
250+
run: |
251+
cat image-build-logs/image-scan-output/critical-images.txt >> image-build-logs/push-attempt-images.txt
246252
if: ${{ inputs.push && inputs.push-dirty }}
247253

248254
- name: Push images
@@ -254,7 +260,7 @@ jobs:
254260
255261
while read -r image; do
256262
# Retries!
257-
for i in {1..5}; do
263+
for i in {1..5}; do
258264
if docker push $image; then
259265
echo "Pushed $image"
260266
break
@@ -288,8 +294,15 @@ jobs:
288294
run: if [ $(wc -l < image-build-logs/push-failed-images.txt) -gt 0 ]; then cat image-build-logs/push-failed-images.txt && exit 1; fi
289295
if: ${{ !cancelled() }}
290296

291-
- name: Fail when images failed scanning
292-
run: if [ $(wc -l < image-build-logs/dirty-images.txt) -gt 0 ]; then cat image-build-logs/dirty-images.txt && exit 1; fi
297+
# NOTE(seunghun1ee): Currently we want to mark the job fail only when critical CVEs are detected.
298+
# This can be used again instead of "Fail when critical vulnerabilities are found" when it's
299+
# decided to fail the job on detecting high CVEs as well.
300+
# - name: Fail when images failed scanning
301+
# run: if [ $(wc -l < image-build-logs/image-scan-output/dirty-images.txt) -gt 0 ]; then cat image-build-logs/image-scan-output/dirty-images.txt && exit 1; fi
302+
# if: ${{ !inputs.push-dirty && !cancelled() }}
303+
304+
- name: Fail when critical vulnerabilities are found
305+
run: if [ $(wc -l < image-build-logs/image-scan-output/critical-images.txt) -gt 0 ]; then cat image-build-logs/image-scan-output/critical-images.txt && exit 1; fi
293306
if: ${{ !inputs.push-dirty && !cancelled() }}
294307

295308
# NOTE(mgoddard): Trigger another CI workflow in the

tools/scan-images.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/$1-*:$2" > $1-
2727
images=$(grep --invert-match --no-filename ^REPOSITORY $1-scanned-container-images.txt | sed 's/ \+/:/g' | cut -f 1,2 -d:)
2828

2929
# 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
3131

3232
# If Trivy detects no vulnerabilities, add the image name to clean-images.txt.
3333
# If there are vulnerabilities detected, add it to dirty-images.txt and
3434
# generate a csv summary
35+
# If the image contains at least one critical vulnerabilities, add it to
36+
# critical-images.txt
3537
for image in $images; do
3638
filename=$(basename $image | sed 's/:/\./g')
3739
if $(trivy image \
@@ -49,15 +51,13 @@ for image in $images; do
4951
# Add the image to the clean list
5052
echo "${image}" >> image-scan-output/clean-images.txt
5153
else
52-
# Add the image to the dirty list
53-
echo "${image}" >> image-scan-output/dirty-images.txt
54-
54+
5555
# Write a header for the summary CSV
5656
echo '"PkgName","PkgPath","PkgID","VulnerabilityID","FixedVersion","PrimaryURL","Severity"' > image-scan-output/${filename}.summary.csv
5757

5858
# Write the summary CSV data
59-
jq -r '.Results[]
60-
| select(.Vulnerabilities)
59+
jq -r '.Results[]
60+
| select(.Vulnerabilities)
6161
| .Vulnerabilities
6262
# Ignore packages with "kernel" in the PkgName
6363
| map(select(.PkgName | test("kernel") | not ))
@@ -72,8 +72,16 @@ for image in $images; do
7272
.[0].PrimaryURL,
7373
.[0].Severity
7474
]
75-
)
76-
| .[]
75+
)
76+
| .[]
7777
| @csv' image-scan-output/${filename}.json >> image-scan-output/${filename}.summary.csv
78+
79+
if [ $(grep "CRITICAL" image-scan-output/${filename}.summary.csv -c) -gt 0 ]; then
80+
# If the image contains critical vulnerabilities, add the image to critical list
81+
echo "${image}" >> image-scan-output/critical-images.txt
82+
else
83+
# Otherwise, add the image to the dirty list
84+
echo "${image}" >> image-scan-output/dirty-images.txt
85+
fi
7886
fi
7987
done

0 commit comments

Comments
 (0)