-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path@orb.yml
546 lines (525 loc) · 23.1 KB
/
@orb.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
version: 2.1
description: |
An orb for running OWASP vulnerability checks through command-line or tasks configured in Gradle and Maven builds.
Reports are persisted as artifacts under the directory 'Report/OWASP'.
Source: https://github.com/entur/owasp-orb
examples:
gradle:
description: |
If you have a standard Gradle project, you can use this orb to run through
a common Gradle worklow.
usage:
version: 2.1
orbs:
owasp: entur/[email protected]
workflows:
owasp:
jobs:
- owasp/gradle_owasp_dependency_check:
executor: java_11
context: global
maven:
description: |
If you have a standard Maven project, you can use this orb to run through
a common Maven worklow.
usage:
version: 2.1
orbs:
owasp: entur/[email protected]
workflows:
owasp:
jobs:
- owasp/maven_owasp_dependency_check:
executor: java_11
context: global
commandline:
description: |
If you need to scan using the command line tool, you can use this orb to invoke it with custom arguments.
usage:
version: 2.1
orbs:
owasp: entur/[email protected]
workflows:
owasp:
jobs:
- owasp/commandline_owasp_dependency_check:
executor: java_11
arguments: "--scan ./ --failOnCVSS 7 --suppression ./dependency-check-suppressions.xml"
context: global
orbs:
gradle: circleci/[email protected]
maven: circleci/[email protected]
executors:
default:
description: |
This default Docker image is highly cached on CircleCI and contains most necessary tools needed for Gradle related projects.
docker:
- image: cimg/openjdk:<<parameters.tag>>
# NB! Add $DOCKERHUB_LOGIN and $DOCKERHUB_PASSWORD credentials in your context to log in to Docker hub
auth:
username: $DOCKERHUB_LOGIN
password: $DOCKERHUB_PASSWORD
environment:
TERM: dumb
parameters:
tag:
default: "11.0.13"
description: |
Pick a specific cimg/openjdk image tag: https://hub.docker.com/r/cimg/openjdk/tags
type: string
aliases:
- &gradle_owasp_dependency_check
description: |
Run OWASP dependency check for a Gradle project
parameters:
executor:
description: The name of custom executor to use.
type: executor
default: default
cve_data_directory:
description: The plugin database directory.
type: string
default: "~/.gradle/dependency-check-data"
task:
description: Task name.
type: string
default: "dependencyCheckAnalyze"
cache_key:
description: Specify a custom cache key.
type: string
default: "v1"
no_output_timeout:
description: Specify period of time has passed with no output.
type: string
default: "15m"
persist_to_workspace:
description: Persist reports to workspace for further processing.
type: boolean
default: false
wrapped_pre_steps:
description: |
Pre-processing steps to run in order to prepare the dependency check.
Not to be confused with the regular 'pre-steps' parameter, this runs after the Gradle cache has been restored and the OWASP database is updated.
type: steps
default: []
executor: <<parameters.executor>>
steps:
- checkout
- wrapped_gradle_steps:
cve_data_directory: <<parameters.cve_data_directory>>
cache_key: <<parameters.cache_key>>
persist_to_workspace: <<parameters.persist_to_workspace>>
wrapped_pre_steps: <<parameters.wrapped_pre_steps>>
wrapped_steps:
- run:
name: Run OWASP Dependency-Check Analyzer
no_output_timeout: << parameters.no_output_timeout >>
command: ./gradlew <<parameters.task>> --info
commands:
restore_owasp_cache:
parameters:
cache_key:
type: string
default: "v1"
steps:
- restore_cache:
name: Restore OWASP Dependency-Check Database from CircleCI cache
keys:
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}-{{ checksum "/tmp/twelveWeeks" }}-{{ checksum "/tmp/fourWeeks" }}-{{ checksum "/tmp/week" }}-{{ checksum "/tmp/day" }}-{{ checksum "/tmp/twelveHoursOfDay" }}-{{ checksum "/tmp/fourHoursOfDay" }}
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}-{{ checksum "/tmp/twelveWeeks" }}-{{ checksum "/tmp/fourWeeks" }}-{{ checksum "/tmp/week" }}-{{ checksum "/tmp/day" }}-{{ checksum "/tmp/twelveHoursOfDay" }}
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}-{{ checksum "/tmp/twelveWeeks" }}-{{ checksum "/tmp/fourWeeks" }}-{{ checksum "/tmp/week" }}-{{ checksum "/tmp/day" }}
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}-{{ checksum "/tmp/twelveWeeks" }}-{{ checksum "/tmp/fourWeeks" }}-{{ checksum "/tmp/week" }}
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}-{{ checksum "/tmp/twelveWeeks" }}-{{ checksum "/tmp/fourWeeks" }}
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}-{{ checksum "/tmp/twelveWeeks" }}
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}
- cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}
store_owasp_cache:
parameters:
cve_data_directory:
type: string
cache_key:
type: string
default: "v1"
steps:
- save_cache:
name: Save OWASP Dependency-Check Database to CircleCI cache
key: cve-cache-<< parameters.cache_key >>-{{ checksum "/tmp/key" }}-{{ checksum "/tmp/year" }}-{{ checksum "/tmp/twelveWeeks" }}-{{ checksum "/tmp/fourWeeks" }}-{{ checksum "/tmp/week" }}-{{ checksum "/tmp/day" }}-{{ checksum "/tmp/twelveHoursOfDay" }}-{{ checksum "/tmp/fourHoursOfDay" }}
paths:
- <<parameters.cve_data_directory>>
generate_cache_keys:
parameters:
cache_key:
description: Unique cache key.
type: string
default: "v1"
steps:
- run:
name: Generate OWASP Dependency-Check Database CircleCI cache keys
command: |
echo <<parameters.cache_key>> >> /tmp/key
echo $(date +"%Y") >> /tmp/year
echo $(( $(date +"%_j") / 84)) >> /tmp/twelveWeeks
echo $(( $(date +"%_j") / 28)) >> /tmp/fourWeeks
echo $(( $(date +"%_j") / 7)) >> /tmp/week
echo $(( $(date +"%_j"))) >> /tmp/day
echo $(( $(date +"%_H") / 12)) >> /tmp/twelveHoursOfDay
echo $(( $(date +"%_H") / 4)) >> /tmp/fourHoursOfDay
collect_reports:
description: Store reports to build artifacts and persist to workspace.
parameters:
persist_to_workspace:
description: Persist reports to workspace.
type: boolean
store_empty_reports_as_artifacts:
description: Keep empty reports. The CSV report type must be generated in order to make this function work as expected.
type: boolean
default: false
store_reports_formats_as_artifacts:
description: Comma-separated list of report formats (extensions) to save as artifacts, or "all" for all formats. These will normally be for human consumption.
type: string
default: html
steps:
- run:
name: Extract OWASP Dependency-Check reports
# Run even if a previous step returned non-zero exit code.
# The command-line tool returns non-zero exit codes if it finds
# vulernabilities above a certian CVSS score is detected.
when: always
command: |
mkdir -p Reports/OWASP
# copy all reports files to the target directory
find . -path ./Reports -prune -o -name "dependency-check*.*" -exec cp --parents \{\} Reports/OWASP/ \;
# copy report files to parent directories for less folders (when using standard report locations)
# gradle - two steps up
find ./Reports -type f -path "*build/reports/dependency-check*.*" -print0 |
while IFS= read -r -d '' file; do
parent=$(dirname "$file")
grandParent=$(dirname "$parent")
grandGrandParent=$(dirname "$grandParent")
mv "$file" "$grandGrandParent"
done
# maven - one step up
find ./Reports -type f -path "*target/dependency-check*.*" -print0 |
while IFS= read -r -d '' file; do
parent=$(dirname "$file")
grandParent=$(dirname "$parent")
mv "$file" "$grandParent"
done
- when:
condition: <<parameters.persist_to_workspace>>
steps:
- persist_to_workspace:
name: Persist OWASP Dependency-Check reports to workspace (in 'Reports/OWASP' directory)
root: .
paths:
- Reports/OWASP
- run:
name: Prepare OWASP Dependency-Check reports artifacts
when: always
command: |
# remove empty reports
if [ "true" == "<< parameters.store_empty_reports_as_artifacts >>" ]; then
echo "Keeping empty reports"
else
echo "Filtering out empty reports. Please note that this function requires that csv reports were generated by the dependency-check plugin."
# search for CSV reports and check number of lines
find ./Reports/OWASP/ -path . -prune -o -name "dependency-check*.csv" -print0 |
while IFS= read -r -d '' file; do
count=$(wc -l < "$file")
if [[ "$count" -eq 1 ]]; then
# CSV file only contains header, delete the corresponding parent directory
parent=$(dirname "$file")
rm -f "${parent}"/dependency-check-*.*
echo "$parent reports were empty."
else
echo "Found $count report lines in $file"
fi
done
fi
# filter on report types
formatsWithoutWhitespace="$(echo -e "<< parameters.store_reports_formats_as_artifacts >>" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')"
IFS=',' read -r -a formats \<<< "$formatsWithoutWhitespace"
if [[ " ${formats[*]} " =~ " all " ]]; then
## keep all
exit 0
fi
find ./Reports/OWASP/ -path . -prune -o -name "dependency-check*.*" -print0 |
while IFS= read -r -d '' file; do
filename=$(basename -- "$file")
extension="${filename##*.}"
extensionLowercase=$(echo "$extension" | tr '[:upper:]' '[:lower:]')
if [[ ! " ${formats[*]} " =~ " ${extensionLowercase} " ]]; then
rm "$file"
fi
done
- store_artifacts:
name: Store OWASP Dependency-Check reports as artifacts
path: Reports/OWASP
destination: .
wrapped_maven_steps:
description: |
Run a set of steps with the OWASP database updated and cached using Maven
parameters:
cve_data_directory:
description: The plugin database directory.
type: string
default: "~/.m2/repository/org/owasp/dependency-check-data"
settings_file:
description: Specify a custom settings file to use (optional).
type: string
default: ""
cache_key:
description: Specify a custom cache key.
type: string
default: "v1"
persist_to_workspace:
description: Persist reports to workspace for further processing.
type: boolean
default: false
wrapped_pre_steps:
description: Pre-processing steps to run in order to prepare the dependency check. Intended for multi-module builds (which require build before dependency check)
type: steps
default: []
wrapped_steps:
type: steps
description: Steps to run in order to perform the dependency check
steps:
- checkout
- maven/with_cache:
settings_file: << parameters.settings_file >>
verify_dependencies: false
steps:
- generate_cache_keys: # for both restore and store
cache_key: maven-<< parameters.cache_key >>-cache-key # flow-specific key
- restore_owasp_cache:
cache_key: << parameters.cache_key >>
- run:
name: Update OWASP Dependency-Check Database
command: mvn org.owasp:dependency-check-maven:update-only
- store_owasp_cache:
cve_data_directory: <<parameters.cve_data_directory>>
cache_key: << parameters.cache_key >>
- steps: << parameters.wrapped_pre_steps >>
- steps: << parameters.wrapped_steps >>
- run:
# note: Also run purge so so that vulernability data is not cached twice.
# Run in seperate step so not run for each submodule.
name: OWASP Dependency-Check cache cleanup
command: mvn org.owasp:dependency-check-maven:purge
- collect_reports:
persist_to_workspace: <<parameters.persist_to_workspace>>
wrapped_gradle_steps:
description: |
Run a set of steps with the OWASP database updated and cached using Gradle
parameters:
cve_data_directory:
description: The plugin database directory.
type: string
default: "~/.gradle/dependency-check-data"
cache_key:
description: Specify a custom cache key.
type: string
default: "v1"
persist_to_workspace:
description: Persist reports to workspace for further processing.
type: boolean
default: false
wrapped_pre_steps:
description: Pre-processing steps to run in order to prepare the dependency check
type: steps
default: []
wrapped_steps:
description: Steps to run in order to perform the dependency check
type: steps
steps:
- checkout
- gradle/with_cache:
cache_key: << parameters.cache_key >>
steps:
- generate_cache_keys: # for both restore and store
cache_key: gradle-<< parameters.cache_key >>-cache-key # flow-specific key
- restore_owasp_cache:
cache_key: << parameters.cache_key >>
- run:
name: Update OWASP Dependency-Check Database
command: ./gradlew :dependencyCheckUpdate --info
- store_owasp_cache:
cve_data_directory: <<parameters.cve_data_directory>>
cache_key: << parameters.cache_key >>
- steps: << parameters.wrapped_pre_steps >>
- steps: << parameters.wrapped_steps >>
- run:
# note: Also run purge so so that vulernability data is not cached twice.
# Run in seperate step so not run for each submodule.
name: OWASP Dependency-Check cache cleanup
command: ./gradlew :dependencyCheckPurge --info
- collect_reports:
persist_to_workspace: <<parameters.persist_to_workspace>>
with_commandline:
description: |
Run a set of steps with the OWASP Dependency-Check command-line tool. Run from ~/.owasp/dependency-check/bin/dependency-check.sh.
parameters:
steps:
type: steps
version:
description: Dependency-check version (if not specified, the latest version will be detected automatically).
type: string
default: ""
cache_key:
description: Specify a custom cache key.
type: string
default: "v1"
steps:
- unless:
condition: <<parameters.version>>
steps:
- run:
name: Check for latest Dependency-Check command-line tool version
command: |
curl --silent "$version_url" > /tmp/owasp_commandline_version
- when:
condition: <<parameters.version>>
steps:
- run:
name: Use fixed Dependency-Check command-line tool version
command: |
echo << parameters.version >> > /tmp/owasp_commandline_version
- run:
name: Create Dependency-Check command-line tool cache key
command: |
echo "$version_url" > /tmp/owasp_commandline_version_url
echo "$executable_url" > /tmp/owasp_commandline_executable_url
- restore_cache:
name: Restore Dependency-Check command-line tool from cache
key: commandline-<< parameters.cache_key >>-{{ checksum "/tmp/owasp_commandline_version" }}-{{ checksum "/tmp/owasp_commandline_version_url" }}-{{ checksum "/tmp/owasp_commandline_executable_url" }}
- run:
name: Download Dependency-Check command-line tool if not already cached
command: |
version=$(cat /tmp/owasp_commandline_version)
executable_url_with_version=${executable_url//VERSION/$version}
if [ -d ~/.owasp/dependency-check ]
then
echo "Dependency-Check command-line tool version $version from $executable_url_with_version already cached."
else
echo "Downloading Dependency-Check executable version $version from $executable_url_with_version .."
wget -q -O owasp.zip "$executable_url_with_version"
unzip -o -q owasp.zip -d ~/.owasp
fi
- save_cache:
name: Save Dependency-Check command-line tool to cache
paths:
- ~/.owasp
key: commandline-<< parameters.cache_key >>-{{ checksum "/tmp/owasp_commandline_version" }}-{{ checksum "/tmp/owasp_commandline_version_url" }}-{{ checksum "/tmp/owasp_commandline_executable_url" }}
- steps: << parameters.steps >>
jobs:
owasp_dependency_check: *gradle_owasp_dependency_check # default to gradle
gradle_owasp_dependency_check: *gradle_owasp_dependency_check
maven_owasp_dependency_check:
description: |
Run OWASP dependency check for a Maven project
parameters:
executor:
description: The name of custom executor to use.
type: executor
default: default
cve_data_directory:
description: The plugin database directory.
type: string
default: "~/.m2/repository/org/owasp/dependency-check-data"
no_output_timeout:
description: Specify period of time has passed with no output.
type: string
default: "15m"
task:
description: Task name.
type: string
default: "check"
settings_file:
description: Specify a custom settings file to use (optional).
type: string
default: ""
cache_key:
description: Specify a custom cache key.
type: string
default: "v1"
persist_to_workspace:
description: Persist reports to workspace for further processing.
type: boolean
default: false
wrapped_pre_steps:
description: |
Pre-processing steps to run in order to prepare the dependency check.
Not to be confused with the regular 'pre-steps' parameter, this runs after the Maven cache has been restored and the OWASP database is updated.
Multi-module projects might consider running the command "mvn clean install -Dmaven.test.skip=true" so that the dependency-check plugin can resolve all artifacts.
type: steps
default: []
executor: <<parameters.executor>>
steps:
- checkout
- wrapped_maven_steps:
cve_data_directory: <<parameters.cve_data_directory>>
settings_file: <<parameters.settings_file>>
cache_key: <<parameters.cache_key>>
persist_to_workspace: <<parameters.persist_to_workspace>>
wrapped_pre_steps: <<parameters.wrapped_pre_steps>>
wrapped_steps:
- run:
name: Run OWASP Dependency-Check Analyzer
no_output_timeout: << parameters.no_output_timeout >>
command: mvn org.owasp:dependency-check-maven:<<parameters.task>>
commandline_owasp_dependency_check:
parameters:
executor:
description: The name of custom executor to use.
type: executor
default: default
cve_data_directory:
description: The data directory for vulernabilities.
type: string
default: "~/.owasp/dependency-check-data"
no_output_timeout:
description: Specify period of time has passed with no output.
type: string
default: "15m"
arguments:
description: Command line arguments. Note that '--format', '--data' and '--noupdate' arguments are already appended by this orb (updating the database is performed in a previous step).
type: string
default: "--scan ./"
cache_key:
description: Specify a custom cache key (optional).
type: string
default: "default"
persist_to_workspace:
description: Persist reports to workspace for further processing.
type: boolean
default: false
version:
description: Dependency-check version (if not specified, the latest version will be detected automatically).
type: string
default: ""
executor: << parameters.executor >>
environment:
version_url: "https://jeremylong.github.io/DependencyCheck/current.txt"
executable_url: "https://github.com/jeremylong/DependencyCheck/releases/download/vVERSION/dependency-check-VERSION-release.zip"
steps:
- checkout
- with_commandline:
version: << parameters.version >>
cache_key: << parameters.cache_key >>
steps:
- generate_cache_keys: # time-based keys for both restore and store
cache_key: commmandline-<< parameters.cache_key >>-cache-key # flow-specific key
- restore_owasp_cache:
cache_key: << parameters.cache_key >>
- run:
name: Update OWASP Dependency-Check Database
command: ~/.owasp/dependency-check/bin/dependency-check.sh --data << parameters.cve_data_directory >> --updateonly
- store_owasp_cache:
cve_data_directory: <<parameters.cve_data_directory>>
cache_key: << parameters.cache_key >>
- run:
name: Run OWASP Dependency-Check Analyzer
no_output_timeout: << parameters.no_output_timeout >>
command: ~/.owasp/dependency-check/bin/dependency-check.sh --data << parameters.cve_data_directory >> --format ALL --noupdate << parameters.arguments >>
- collect_reports:
persist_to_workspace: << parameters.persist_to_workspace >>