-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
362 lines (350 loc) · 14.9 KB
/
action.yml
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
---
name: Traceable AST Action
description: "GitHub action for Traceable Active Security Testing"
branding:
icon: 'activity'
color: 'red'
inputs:
step_name:
required: true
description: ''
default: 'NULL'
scan_name:
required: false
description: ''
default: 'NULL'
client_scan_token:
required: true
description: ''
default: 'NULL'
traceable_cli_download_path:
required: false
description: ''
default: 'NULL'
cli_version:
required: false
description: ''
default: 'latest'
traffic_env:
required: true
description: ''
default: 'NULL'
plugins:
required: false
description: ''
default: 'NULL'
policy:
required: false
description: ''
default: 'NULL'
include_url_regex:
required: false
description: ''
default: '.+'
exclude_url_regex:
required: false
description: ''
default: '.*(logout|health).*'
include_endpoint_labels:
required: false
description: ''
default: 'NULL'
exclude_endpoint_labels:
required: false
description: ''
default: 'NULL'
include_endpoint_with_owner_attributes:
required: false
description: 'Comma seperted owner attributes'
default: 'NULL'
include_endpoint_owners:
required: false
description: 'Comma seperated owner values , provided only when include owner attributes are provided'
default: 'NULL'
postman_collection:
required: false
description: ''
default: 'NULL'
postman_environment:
required: false
description: ''
default: 'NULL'
openapi_spec_ids:
required: false
description: 'provide comma separated open api spec ids'
default: 'NULL'
openapi_spec_files:
required: false
description: 'comma separated files of open api spec documents'
default: 'NULL'
target_url:
required: false
description: ''
default: 'NULL'
traceable_server:
required: false
description: ''
default: 'NULL'
idle_timeout:
required: false
description: ''
default: '10'
scan_timeout:
required: false
description: ''
default: 'NULL'
max_retries:
required: false
description: ''
default: 'NULL'
log_level:
required: false
description: ''
default: 'NULL'
traceable_root_ca:
required: false
description: ''
default: 'NULL'
traceable_cli_cert:
required: false
description: ''
default: 'NULL'
traceable_cli_key:
required: false
description: ''
default: 'NULL'
proxy_mode:
required: false
description: 'Run a scan in proxy mode or not'
default: 'false'
ta_service_name:
required: false
description: 'TA service name'
default: 'proxy'
tpa_endpoint:
required: false
description: 'Traceable platform agent (TPA) reporting endpoint'
default: 'localhost'
output_format:
required: false
description: 'Out format for summary report'
default: 'md'
output_file:
required: false
description: 'Output file for summary report'
default: 'NULL'
proxy_logfile:
required: false
description: 'Output stream/file for proxy logs'
default: 'NULL'
agent_logfile:
required: false
description: 'Output stream/file for agent logs'
default: 'NULL'
logfile:
required: false
description: 'Output stream/file for traceable cli logs'
default: 'NULL'
scan_suite:
required: false
description: 'AST suite name as defined on the Traceable.ai platform'
default: 'NULL'
graphql_schema_ids:
required: false
description: 'Comma separated GraphQl schema IDs uploaded on Traceable.ai platform'
default: 'NULL'
graphql_schema_files:
required: false
description: 'Comma separated GraphQl SDL file paths'
default: 'NULL'
graphql_introspection_enabled:
required: false
description: 'Enables extracting the GraphQl Schema by running introspection on target-url'
default: 'NULL'
runs:
using: composite
steps:
- name: Validate required parameters
run: |
[[ "${{ inputs.step_name }}" != "NULL" ]] || { echo "step name input is empty" ; exit 1; }
[[ "${{ inputs.client_scan_token }}" != "NULL" ]] || { echo "client_scan_token input is empty" ; exit 1; }
if [[ "${{ inputs.graphql_introspection_enabled }}" == "true" ]]; then
[[ "${{ inputs.target_url }}" != "NULL" ]] || { echo "target_url is required when graphql_introspection_enabled is true" ; exit 1; }
fi
shell: bash
- name: Download CLI
if: ${{ inputs.step_name == 'init' || inputs.step_name == 'init and run' }}
run: |
if [[ "${{ inputs.traceable_cli_download_path }}" != "NULL" ]]
then
curl -Lo traceableCli.tar.gz ${{ inputs.traceable_cli_download_path }}
tar -xvf traceableCli.tar.gz --directory ${GITHUB_WORKSPACE}
else
if [[ "${{ inputs.cli_version }}" = *"-rc."* ]]
then
curl -Lo traceableCli.tar.gz https://downloads.traceable.ai/cli/rc/${{ inputs.cli_version }}/traceable-cli-${{ inputs.cli_version }}-linux-x86_64.tar.gz
else
curl -Lo traceableCli.tar.gz https://downloads.traceable.ai/cli/release/${{ inputs.cli_version }}/traceable-cli-${{ inputs.cli_version }}-linux-x86_64.tar.gz
fi
tar -xvf traceableCli.tar.gz --directory ${GITHUB_WORKSPACE}
fi
shell: bash
- name: Init and run command on cli
if: ${{ inputs.step_name == 'init and run' }}
run: |
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
if [[ -n "${{ inputs.traceable_root_ca }}" ]] && [[ "${{ inputs.traceable_root_ca }}" != "''" ]] && [[ "${{ inputs.traceable_root_ca }}" != "NULL" ]]
then
echo "${{ inputs.traceable_root_ca }}" > /tmp/ca_file.crt
export TRACEABLE_ROOT_CA_FILE_NAME=/tmp/ca_file.crt
fi
if [[ -n "${{ inputs.traceable_cli_cert }}" ]] && [[ "${{ inputs.traceable_cli_cert }}" != "''" ]] && [[ "${{ inputs.traceable_cli_cert }}" != "NULL" ]]
then
echo "${{ inputs.traceable_cli_cert }}" > /tmp/ca_cert.crt
export TRACEABLE_CLI_CERT_FILE_NAME=/tmp/ca_cert.crt
fi
if [[ -n "${{ inputs.traceable_cli_key }}" ]] && [[ "${{ inputs.traceable_cli_key }}" != "''" ]] && [[ "${{ inputs.traceable_cli_key }}" != "NULL" ]]
then
echo "${{ inputs.traceable_cli_key }}" > /tmp/ca_key.crt
export TRACEABLE_CLI_KEY_FILE_NAME=/tmp/ca_key.crt
fi
traceableCliBinaryLocation=${GITHUB_WORKSPACE}/traceable
scanInitCmd=$traceableCliBinaryLocation' ast scan initAndRun'
optionsArr=('--scan-name' '--traffic-env' '--token' '--plugins' '--include-url-regex' '--exclude-url-regex' '--target-url' '--traceable-server' '--idle-timeout' '--scan-timeout' ' --reference-env' '--max-retries' '--openapi-spec-ids' '--openapi-spec-files' '--policy' '--postman-collection' '--postman-environment' '--include-endpoint-labels' '--exclude-endpoint-labels' '--include-endpoint-with-owner-attributes' '--include-endpoint-owners' '--loglevel' '--logfile' '--agent-logfile' '--proxy-logfile' '--scan-suite' '--graphql-schema-ids' '--graphql-schema-files' '--graphql-introspection-enabled')
#Iterating the options available from options array and filling them with the arguments received in order
iterator=0
for option in '${{ inputs.scan_name }}' '${{ inputs.traffic_env }}' '${{ inputs.client_scan_token }}' '${{ inputs.plugins }}' '${{ inputs.include_url_regex }}' '${{ inputs.exclude_url_regex }}' '${{ inputs.target_url }}' '${{ inputs.traceable_server }}' '${{ inputs.idle_timeout }}' '${{ inputs.scan_timeout }}' '${{ inputs.reference_env }}' '${{ inputs.max_retries }}' '${{ inputs.openapi_spec_ids }}' '${{ inputs.openapi_spec_files }}' '${{ inputs.policy }}' '${{ inputs.postman_collection }}' '${{ inputs.postman_environment }}' '${{ inputs.include_endpoint_labels}}' '${{ inputs.exclude_endpoint_labels }}' '${{ inputs.include_endpoint_with_owner_attributes }}' '${{ inputs.include_endpoint_owners }}' '${{ inputs.log_level }}' '${{ inputs.logfile }}' '${{ inputs.agent_logfile }}' '${{ inputs.proxy_logfile }}' '${{ inputs.scan_suite }}' '${{ inputs.graphql_schema_ids }}' '${{ inputs.graphql_schema_files }}' '${{ inputs.graphql_introspection_enabled }}'
do
if [ -z "$option" ] || [ "$option" = "''" ] || [ "$option" = "NULL" ]
then
echo "${optionsArr[$iterator]}" is Null
else
scanInitCmd=$scanInitCmd" "${optionsArr[$iterator]}" "${option}
fi
iterator=$(($iterator+1))
done
if [[ "${{ inputs.proxy_mode }}" == "true" ]]
then
export TRACEABLE_PROXY_HOST=localhost
export TRACEABLE_PROXY_PORT=18080
export TA_SERVICE_NAME="${{ inputs.ta_service_name }}"
unset http_proxy
scanInitCmd=$scanInitCmd" -tpa "${{ inputs.tpa_endpoint }}" --proxy"
fi
echo "Running cli command $scanInitCmd"
$scanInitCmd
shell: bash
- name: Init command on cli
if: ${{ inputs.step_name == 'init' }}
run: |
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
if [[ -n "${{ inputs.traceable_root_ca }}" ]] && [[ "${{ inputs.traceable_root_ca }}" != "''" ]] && [[ "${{ inputs.traceable_root_ca }}" != "NULL" ]]
then
echo "${{ inputs.traceable_root_ca }}" > /tmp/ca_file.crt
export TRACEABLE_ROOT_CA_FILE_NAME=/tmp/ca_file.crt
fi
if [[ -n "${{ inputs.traceable_cli_cert }}" ]] && [[ "${{ inputs.traceable_cli_cert }}" != "''" ]] && [[ "${{ inputs.traceable_cli_cert }}" != "NULL" ]]
then
echo "${{ inputs.traceable_cli_cert }}" > /tmp/ca_cert.crt
export TRACEABLE_CLI_CERT_FILE_NAME=/tmp/ca_cert.crt
fi
if [[ -n "${{ inputs.traceable_cli_key }}" ]] && [[ "${{ inputs.traceable_cli_key }}" != "''" ]] && [[ "${{ inputs.traceable_cli_key }}" != "NULL" ]]
then
echo "${{ inputs.traceable_cli_key }}" > /tmp/ca_key.crt
export TRACEABLE_CLI_KEY_FILE_NAME=/tmp/ca_key.crt
fi
traceableCliBinaryLocation=${GITHUB_WORKSPACE}/traceable
scanInitCmd=$traceableCliBinaryLocation' ast scan init '
optionsArr=('--scan-name' '--traffic-env' '--token' '--plugins' '--include-url-regex' '--exclude-url-regex' '--target-url' '--traceable-server' '--scan-timeout' ' --reference-env' '--openapi-spec-ids' '--openapi-spec-files' '--policy' '--include-endpoint-labels' '--exclude-endpoint-labels' '--include-endpoint-with-owner-attributes' '--include-endpoint-owners' '--loglevel' '--scan-suite' '--graphql-schema-ids' '--graphql-schema-files' '--graphql-introspection-enabled')
#Iterating the options available from options array and filling them with the arguments received in order
iterator=0
for option in '${{ inputs.scan_name }}' '${{ inputs.traffic_env }}' '${{ inputs.client_scan_token }}' '${{ inputs.plugins }}' '${{ inputs.include_url_regex }}' '${{ inputs.exclude_url_regex }}' '${{ inputs.target_url }}' '${{ inputs.traceable_server }}' '${{ inputs.scan_timeout }}' '${{ inputs.reference_env }}' '${{ inputs.openapi_spec_ids }}' '${{ inputs.openapi_spec_files }}' '${{ inputs.policy }}' '${{ inputs.include_endpoint_labels}}' '${{ inputs.exclude_endpoint_labels }}' '${{ inputs.include_endpoint_with_owner_attributes }}' '${{ inputs.include_endpoint_owners }}' '${{ inputs.log_level }}' '${{ inputs.scan_suite }}' '${{ inputs.graphql_schema_ids }}' '${{ inputs.graphql_schema_files }}' '${{ inputs.graphql_introspection_enabled }}'
do
if [ -z "$option" ] || [ "$option" = "''" ] || [ "$option" = "NULL" ]
then
echo "${optionsArr[$iterator]}" is Null
else
scanInitCmd=$scanInitCmd" "${optionsArr[$iterator]}" "${option}
fi
iterator=$(($iterator+1))
done
echo "Running cli command $scanInitCmd"
$scanInitCmd
shell: bash
- name: Run command on cli
id: run_scan
if: ${{ inputs.step_name == 'run' }}
run: |
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
if [ -f "/tmp/ca_file.crt" ]
then
export TRACEABLE_ROOT_CA_FILE_NAME=/tmp/ca_file.crt
fi
if [ -f "/tmp/ca_cert.crt" ]
then
export TRACEABLE_CLI_CERT_FILE_NAME=/tmp/ca_cert.crt
fi
if [ -f "/tmp/ca_key.crt" ]
then
export TRACEABLE_CLI_KEY_FILE_NAME=/tmp/ca_key.crt
fi
traceableCliBinaryLocation=${GITHUB_WORKSPACE}/traceable
scanRunCmd=$traceableCliBinaryLocation' ast scan run '
optionsArr=('--token' '--idle-timeout' '--max-retries' '--postman-collection' '--postman-environment' '--loglevel' '--logfile' '--agent-logfile' '--proxy-logfile')
#Iterating the options available from options array and filling them with the arguments received in order
iterator=0
for option in '${{ inputs.client_scan_token }}' '${{ inputs.idle_timeout }}' '${{ inputs.max_retries }}' '${{ inputs.postman_collection }}' '${{ inputs.postman_environment }}' '${{ inputs.log_level }}' '${{ inputs.logfile }}' '${{ inputs.agent_logfile }}' '${{ inputs.proxy_logfile }}'
do
if [ -z "$option" ] || [ "$option" = "''" ] || [ "$option" = "NULL" ]
then
echo "${optionsArr[$iterator]}" is Null
else
scanRunCmd=$scanRunCmd" "${optionsArr[$iterator]}" "${option}
fi
iterator=$(($iterator+1))
done
echo "Running cli command $scanRunCmd"
$scanRunCmd
shell: bash
- name: Publish report
if: ${{ inputs.step_name == 'run' || inputs.step_name == 'init and run'}}
run: |
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
if [ -f "/tmp/ca_file.crt" ]
then
export TRACEABLE_ROOT_CA_FILE_NAME=/tmp/ca_file.crt
fi
if [ -f "/tmp/ca_cert.crt" ]
then
export TRACEABLE_CLI_CERT_FILE_NAME=/tmp/ca_cert.crt
fi
if [ -f "/tmp/ca_key.crt" ]
then
export TRACEABLE_CLI_KEY_FILE_NAME=/tmp/ca_key.crt
fi
${GITHUB_WORKSPACE}/traceable ast scan report --exit-code --output-format '${{ inputs.output_format }}' | sed 1,2d >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Stop scan
id: stop_scan
if: ${{ inputs.step_name == 'stop' }}
run: |
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
if [ -f "/tmp/ca_file.crt" ]
then
export TRACEABLE_ROOT_CA_FILE_NAME=/tmp/ca_file.crt
fi
if [ -f "/tmp/ca_cert.crt" ]
then
export TRACEABLE_CLI_CERT_FILE_NAME=/tmp/ca_cert.crt
fi
if [ -f "/tmp/ca_key.crt" ]
then
export TRACEABLE_CLI_KEY_FILE_NAME=/tmp/ca_key.crt
fi
${GITHUB_WORKSPACE}/traceable ast scan stop >/dev/null || true
shell: bash