forked from orcasecurity/shiftleft-container-image-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.bat
166 lines (154 loc) · 5.52 KB
/
entrypoint.bat
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
@echo off
:exit_with_err
echo ERROR: %~1
exit /b 1
:run_orca_container_scan
cd "%GITHUB_WORKSPACE%" || call :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%
set ORCA_EXIT_CODE=%errorlevel%
echo exit_code=%ORCA_EXIT_CODE% >>"%GITHUB_OUTPUT%"
:set_global_flags
set "GLOBAL_FLAGS="
if "%INPUT_EXIT_CODE%" NEQ "" (
set "GLOBAL_FLAGS=--exit-code %INPUT_EXIT_CODE%"
)
if "%INPUT_NO_COLOR%"=="true" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --no-color"
)
if "%INPUT_PROJECT_KEY%" NEQ "" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --project-key %INPUT_PROJECT_KEY%"
)
if "%INPUT_SILENT%"=="true" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --silent"
)
if "%INPUT_CONFIG%" NEQ "" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --config %INPUT_CONFIG%"
)
if "%INPUT_BASELINE_CONTEXT_KEY%" NEQ "" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --baseline-context-key %INPUT_BASELINE_CONTEXT_KEY%"
)
if "%INPUT_DISABLE_BASELINE%"=="true" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --disable-baseline"
)
if "%INPUT_DISABLE_ERR_REPORT%"=="true" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --disable-err-report"
)
if "%INPUT_SYNC_BASELINE%" NEQ "" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --sync-baseline %INPUT_SYNC_BASELINE%"
)
if "%INPUT_DISPLAY_NAME%" NEQ "" (
set "GLOBAL_FLAGS=%GLOBAL_FLAGS% --display-name %INPUT_DISPLAY_NAME%"
)
REM Json format must be reported and be stored in a file for github annotations
:prepare_json_to_file_flags
REM Output directory must be provided to store the json results
set "OUTPUT_FOR_JSON=%INPUT_OUTPUT%"
set "CONSOLE_OUTPUT_FOR_JSON=%INPUT_CONSOLE_OUTPUT%"
if "%INPUT_OUTPUT%"=="" (
REM Results should be printed to console in the selected format
set "CONSOLE_OUTPUT_FOR_JSON=%INPUT_FORMAT:table=%"
REM Results should also be stored in a directory
set "OUTPUT_FOR_JSON=orca_results/"
)
if "%INPUT_FORMAT%"=="" (
REM The default format should be provided together with the one we are adding
set "FORMATS_FOR_JSON=table,json"
) else (
if "%INPUT_FORMAT:json=%"=="%INPUT_FORMAT%" (
set "FORMATS_FOR_JSON=%INPUT_FORMAT%,json"
) else (
set "FORMATS_FOR_JSON=%INPUT_FORMAT%"
)
)
REM Used during the annotation process
set "OUTPUT_FOR_JSON=%OUTPUT_FOR_JSON%"
set "CONSOLE_OUTPUT_FOR_JSON=%CONSOLE_OUTPUT_FOR_JSON%"
set "FORMATS_FOR_JSON=%FORMATS_FOR_JSON%"
:set_container_scan_flags
set "SCAN_FLAGS="
if "%INPUT_IMAGE%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% %INPUT_IMAGE%"
)
if "%INPUT_TAR_ARCHIVE%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --tar-archive %INPUT_TAR_ARCHIVE%"
)
if "%INPUT_TIMEOUT%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --timeout %INPUT_TIMEOUT%"
)
if "%INPUT_IGNORE_FAILED_EXEC_CONTROLS%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --ignore-failed-exec-controls"
)
if "%INPUT_OCI%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --oci"
)
if "%INPUT_DISABLE_SECRET%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --disable-secret"
)
if "%INPUT_EXCEPTIONS_FILEPATH%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --exceptions-filepath %INPUT_EXCEPTIONS_FILEPATH%"
)
if "%INPUT_HIDE_VULNERABILITIES%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --hide-vulnerabilities"
)
if "%INPUT_NUM_CPU%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --num-cpu %INPUT_NUM_CPU%"
)
if "%INPUT_SHOW_FAILED_ISSUES_ONLY%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --show-failed-issues-only"
)
if "%FORMATS_FOR_JSON%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --format %FORMATS_FOR_JSON%"
)
if "%OUTPUT_FOR_JSON%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --output %OUTPUT_FOR_JSON%"
)
if "%CONSOLE_OUTPUT_FOR_JSON%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --console-output=%CONSOLE_OUTPUT_FOR_JSON%"
)
if "%INPUT_SKIP_REMOTE_LOOKUP%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --skip-remote-lookup"
)
if "%INPUT_CUSTOM_SECRET_CONTROLS%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --custom-secret-controls=%INPUT_CUSTOM_SECRET_CONTROLS%"
)
if "%INPUT_HIDE_SKIPPED_VULNERABILITIES%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --hide-skipped-vulnerabilities"
)
if "%INPUT_MAX_SECRET%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --max-secret %INPUT_MAX_SECRET%"
)
if "%INPUT_EXCLUDE_PATHS%" NEQ "" (
set "SCAN_FLAGS=%SCAN_FLAGS% --exclude-paths %INPUT_EXCLUDE_PATHS%"
)
if "%INPUT_DEPENDENCY_TREE%"=="true" (
set "SCAN_FLAGS=%SCAN_FLAGS% --dependency-tree"
)
:set_env_vars
if "%INPUT_API_TOKEN%" NEQ "" (
set "ORCA_SECURITY_API_TOKEN=%INPUT_API_TOKEN%"
)
:validate_flags
if "%INPUT_API_TOKEN%"=="" (
exit_with_err "api_token must be provided"
)
if "%INPUT_PROJECT_KEY%"=="" (
exit_with_err "project_key must be provided"
)
if "%INPUT_OUTPUT%" NEQ "" (
if not "%INPUT_OUTPUT:~-1%"=="\" (
if not exist "%INPUT_OUTPUT%\" (
exit_with_err "output must be a folder (end with \)"
)
)
)
:main
call validate_flags
call set_env_vars
call set_global_flags
call prepare_json_to_file_flags
call set_container_scan_flags
call run_orca_container_scan
exit %ORCA_EXIT_CODE%
call main "%*"