Skip to content

Commit 0b25e96

Browse files
committed
Fail acs-image-check task when image check fails
Failure during roxctl-image-check currently does not cause the acs-image-check script to fail, resulting in a false negative. Signed-off-by: Tomáš Nevrlka <[email protected]> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
1 parent bdcfee6 commit 0b25e96

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

rhtap/acs-image-check.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#!/bin/bash
2+
set -euo pipefail
3+
24
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
35

46
# acs-image-check
57
source $SCRIPTDIR/common.sh
68

79
function rox-image-check() {
8-
echo "Running $TASK_NAME:rox-image-check"
9-
#!/usr/bin/env bash
10-
set +x
11-
1210
if [ "$DISABLE_ACS" == "true" ]; then
1311
echo "DISABLE_ACS is set. No scans will be produced"
1412
exit_with_success_result
@@ -32,13 +30,9 @@ function rox-image-check() {
3230
"https://${ROX_CENTRAL_ENDPOINT}/api/cli/download/roxctl-linux" \
3331
--output ./roxctl \
3432
> /dev/null
35-
if [ $? -ne 0 ]; then
36-
echo 'Failed to download roxctl'
37-
exit_with_fail_result
38-
fi
3933
received_filesize=$(stat -c%s ./roxctl)
4034
if (($received_filesize < 10000)); then
41-
# Responce from ACS server is not a binary but error message
35+
# Response from ACS server is not a binary but error message
4236
cat ./roxctl
4337
echo 'Failed to download roxctl'
4438
exit 2
@@ -47,19 +41,39 @@ function rox-image-check() {
4741

4842
echo "roxctl image check"
4943
IMAGE=${PARAM_IMAGE}@${PARAM_IMAGE_DIGEST}
44+
ROXCTL_CHECK_STATUS=0
5045
./roxctl image check \
5146
$([ "${INSECURE_SKIP_TLS_VERIFY}" = "true" ] &&
5247
echo -n "--insecure-skip-tls-verify") \
5348
-e "${ROX_CENTRAL_ENDPOINT}" --image "$IMAGE" --output json --force \
54-
> roxctl_image_check_output.json
55-
cp roxctl_image_check_output.json acs-image-check.json
49+
> roxctl_image_check_output.json ||
50+
ROXCTL_CHECK_STATUS=$?
51+
52+
if [ "$ROXCTL_CHECK_STATUS" -eq 0 ]; then
53+
exit
54+
fi
55+
56+
# Number of policy violations with Critical and High severity parsed from the report
57+
severe_violations=$(
58+
jq '.summary |
59+
with_entries(
60+
select(.key | IN("CRITICAL", "HIGH"))
61+
) |
62+
add' \
63+
roxctl_image_check_output.json
64+
)
65+
66+
# If roxctl image check exited with non-zero code and it is not because of policy violations, report error
67+
if [ "$severe_violations" -eq 0 ]; then
68+
exit "$ROXCTL_CHECK_STATUS"
69+
fi
5670
}
5771

5872
function report() {
5973
echo "Running $TASK_NAME:report"
6074
#!/usr/bin/env bash
6175
echo "ACS_IMAGE_CHECK_EYECATCHER_BEGIN"
62-
cat acs-image-check.json
76+
cat roxctl_image_check_output.json
6377
echo "ACS_IMAGE_CHECK_EYECATCHER_END"
6478
}
6579

0 commit comments

Comments
 (0)