1
1
#! /bin/bash
2
+ set -euo pipefail
3
+
2
4
SCRIPTDIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd) "
3
5
4
6
# acs-image-check
5
7
source $SCRIPTDIR /common.sh
6
8
7
9
function rox-image-check() {
8
- echo " Running $TASK_NAME :rox-image-check"
9
- #! /usr/bin/env bash
10
- set +x
11
-
12
10
if [ " $DISABLE_ACS " == " true" ]; then
13
11
echo " DISABLE_ACS is set. No scans will be produced"
14
12
exit_with_success_result
@@ -32,13 +30,9 @@ function rox-image-check() {
32
30
" https://${ROX_CENTRAL_ENDPOINT} /api/cli/download/roxctl-linux" \
33
31
--output ./roxctl \
34
32
> /dev/null
35
- if [ $? -ne 0 ]; then
36
- echo ' Failed to download roxctl'
37
- exit_with_fail_result
38
- fi
39
33
received_filesize=$( stat -c%s ./roxctl)
40
34
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
42
36
cat ./roxctl
43
37
echo ' Failed to download roxctl'
44
38
exit 2
@@ -47,19 +41,39 @@ function rox-image-check() {
47
41
48
42
echo " roxctl image check"
49
43
IMAGE=${PARAM_IMAGE} @${PARAM_IMAGE_DIGEST}
44
+ ROXCTL_CHECK_STATUS=0
50
45
./roxctl image check \
51
46
$( [ " ${INSECURE_SKIP_TLS_VERIFY} " = " true" ] &&
52
47
echo -n " --insecure-skip-tls-verify" ) \
53
48
-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
56
70
}
57
71
58
72
function report() {
59
73
echo " Running $TASK_NAME :report"
60
74
#! /usr/bin/env bash
61
75
echo " ACS_IMAGE_CHECK_EYECATCHER_BEGIN"
62
- cat acs-image-check .json
76
+ cat roxctl_image_check_output .json
63
77
echo " ACS_IMAGE_CHECK_EYECATCHER_END"
64
78
}
65
79
0 commit comments