-
Notifications
You must be signed in to change notification settings - Fork 9
/
entrypoint.sh
172 lines (160 loc) · 5.21 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
exit_with_err() {
local msg="${1?}"
echo "ERROR: ${msg}"
exit 1
}
function run_orca_container_scan() {
cd "${GITHUB_WORKSPACE}" || exit_with_err "could not find GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
echo "Running Orca Container Image scan:"
echo orca-cli "${GLOBAL_FLAGS[@]}" image scan "${SCAN_FLAGS[@]}"
orca-cli "${GLOBAL_FLAGS[@]}" image scan "${SCAN_FLAGS[@]}"
export ORCA_EXIT_CODE=$?
echo "exit_code=${ORCA_EXIT_CODE}" >>"$GITHUB_OUTPUT"
}
function set_global_flags() {
GLOBAL_FLAGS=()
if [ "${INPUT_EXIT_CODE}" ]; then
GLOBAL_FLAGS+=(--exit-code "${INPUT_EXIT_CODE}")
fi
if [ "${INPUT_NO_COLOR}" == "true" ]; then
GLOBAL_FLAGS+=(--no-color)
fi
if [ "${INPUT_PROJECT_KEY}" ]; then
GLOBAL_FLAGS+=(--project-key "${INPUT_PROJECT_KEY}")
fi
if [ "${INPUT_SILENT}" == "true" ]; then
GLOBAL_FLAGS+=(--silent)
fi
if [ "${INPUT_CONFIG}" ]; then
GLOBAL_FLAGS+=(--config "${INPUT_CONFIG}")
fi
if [ "${INPUT_BASELINE_CONTEXT_KEY}" ]; then
GLOBAL_FLAGS+=(--baseline-context-key "${INPUT_BASELINE_CONTEXT_KEY}")
fi
if [ "${INPUT_DISABLE_BASELINE}" == "true" ]; then
GLOBAL_FLAGS+=(--disable-baseline)
fi
if [ "${INPUT_DISABLE_ERR_REPORT}" == "true" ]; then
GLOBAL_FLAGS+=(--disable-err-report)
fi
if [ "${INPUT_SYNC_BASELINE}" ]; then
GLOBAL_FLAGS+=(--sync-baseline "${INPUT_SYNC_BASELINE}")
fi
if [ "${INPUT_DISPLAY_NAME}" ]; then
GLOBAL_FLAGS+=(--display-name "${INPUT_DISPLAY_NAME}")
fi
if [ "${INPUT_DEBUG}" == "true" ]; then
GLOBAL_FLAGS+=(--debug)
fi
if [ "${INPUT_DISABLE_ACTIVE_VERIFICATION}" == "true" ]; then
GLOBAL_FLAGS+=(--disable-active-verification)
fi
if [ "${INPUT_LOG_PATH}" ]; then
GLOBAL_FLAGS+=(--log-path "${INPUT_LOG_PATH}")
fi
}
# Json format must be reported and be stored in a file for github annotations
function prepare_json_to_file_flags() {
# Output directory must be provided to store the json results
OUTPUT_FOR_JSON="${INPUT_OUTPUT}"
CONSOLE_OUTPUT_FOR_JSON="${INPUT_CONSOLE_OUTPUT}"
if [[ -z "${INPUT_OUTPUT}" ]]; then
# Results should be printed to console in the selected format
CONSOLE_OUTPUT_FOR_JSON="${INPUT_FORMAT:-table}"
# Results should also be stored in a directory
OUTPUT_FOR_JSON="orca_results/"
fi
if [[ -z "${INPUT_FORMAT}" ]]; then
# The default format should be provided together with the one we are adding
FORMATS_FOR_JSON="table,json"
else
if [[ "${INPUT_FORMAT}" == *"json"* ]]; then
FORMATS_FOR_JSON="${INPUT_FORMAT}"
else
FORMATS_FOR_JSON="${INPUT_FORMAT},json"
fi
fi
# Used during the annotation process
export OUTPUT_FOR_JSON CONSOLE_OUTPUT_FOR_JSON FORMATS_FOR_JSON
}
function set_container_scan_flags() {
SCAN_FLAGS=()
if [ "${INPUT_IMAGE}" ]; then
SCAN_FLAGS+=("${INPUT_IMAGE}")
fi
if [ "${INPUT_TAR_ARCHIVE}" ]; then
SCAN_FLAGS+=(--tar-archive "${INPUT_TAR_ARCHIVE}")
fi
if [ "${INPUT_TIMEOUT}" ]; then
SCAN_FLAGS+=(--timeout "${INPUT_TIMEOUT}")
fi
if [ "${INPUT_IGNORE_FAILED_EXEC_CONTROLS}" == "true" ]; then
SCAN_FLAGS+=(--ignore-failed-exec-controls)
fi
if [ "${INPUT_OCI}" == "true" ]; then
SCAN_FLAGS+=(--oci)
fi
if [ "${INPUT_DISABLE_SECRET}" = "true" ]; then
SCAN_FLAGS+=(--disable-secret)
fi
if [ "${INPUT_EXCEPTIONS_FILEPATH}" ]; then
SCAN_FLAGS+=(--exceptions-filepath "${INPUT_EXCEPTIONS_FILEPATH}")
fi
if [ "${INPUT_HIDE_VULNERABILITIES}" = "true" ]; then
SCAN_FLAGS+=(--hide-vulnerabilities)
fi
if [ "${INPUT_NUM_CPU}" ]; then
SCAN_FLAGS+=(--num-cpu "${NUM_CPU}")
fi
if [ "${INPUT_SHOW_FAILED_ISSUES_ONLY}" = "true" ]; then
SCAN_FLAGS+=(--show-failed-issues-only)
fi
if [ "${FORMATS_FOR_JSON}" ]; then
SCAN_FLAGS+=(--format "${FORMATS_FOR_JSON}")
fi
if [ "${OUTPUT_FOR_JSON}" ]; then
SCAN_FLAGS+=(--output "${OUTPUT_FOR_JSON}")
fi
if [ "${CONSOLE_OUTPUT_FOR_JSON}" ]; then
SCAN_FLAGS+=(--console-output="${CONSOLE_OUTPUT_FOR_JSON}")
fi
if [ "${INPUT_SKIP_REMOTE_LOOKUP}" == "true" ]; then
SCAN_FLAGS+=(--skip-remote-lookup)
fi
if [ "${INPUT_CUSTOM_SECRET_CONTROLS}" ]; then
SCAN_FLAGS+=(--custom-secret-controls="${INPUT_CUSTOM_SECRET_CONTROLS}")
fi
if [ "${INPUT_HIDE_SKIPPED_VULNERABILITIES}" == "true" ]; then
SCAN_FLAGS+=(--hide-skipped-vulnerabilities)
fi
if [ "${INPUT_MAX_SECRET}" ]; then
SCAN_FLAGS+=(--max-secret "${INPUT_MAX_SECRET}")
fi
if [ "${INPUT_EXCLUDE_PATHS}" ]; then
SCAN_FLAGS+=(--exclude-paths "${INPUT_EXCLUDE_PATHS}")
fi
if [ "${INPUT_DEPENDENCY_TREE}" == "true" ]; then
SCAN_FLAGS+=(--dependency-tree)
fi
}
function set_env_vars() {
if [ "${INPUT_API_TOKEN}" ]; then
export ORCA_SECURITY_API_TOKEN="${INPUT_API_TOKEN}"
fi
}
function validate_flags() {
[[ -n "${INPUT_API_TOKEN}" ]] || exit_with_err "api_token must be provided"
[[ -n "${INPUT_PROJECT_KEY}" ]] || exit_with_err "project_key must be provided"
[[ -z "${INPUT_OUTPUT}" ]] || [[ "${INPUT_OUTPUT}" == */ ]] || [[ -d "${INPUT_OUTPUT}" ]] || exit_with_err "output must be a folder (end with /)"
}
function main() {
validate_flags
set_env_vars
set_global_flags
prepare_json_to_file_flags
set_container_scan_flags
run_orca_container_scan
exit "${ORCA_EXIT_CODE}"
}
main "${@}"