-
Notifications
You must be signed in to change notification settings - Fork 179
945 lines (820 loc) · 34.6 KB
/
ci.yaml
File metadata and controls
945 lines (820 loc) · 34.6 KB
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# SPDX-FileCopyrightText: 2020 iteratec GmbH
#
# SPDX-License-Identifier: Apache-2.0
name: "CI"
on: push
env:
# ---- Language Versions ----
GO_VERSION: "1.15"
PYTHON_VERSION: "3.9"
# ---- Docker Namespace ----
# DOCKER_USER and DOCKER_TOKEN are stored as GitHub secrets as well
DOCKER_NAMESPACE: ${{ secrets.DOCKER_NAMESPACE }}
jobs:
# ---- Unit-Test ----
# ---- Unit-Test | Java ----
unit-java:
name: "Unit-Test | Java"
runs-on: ubuntu-latest
strategy:
matrix:
unit: ["persistence-defectdojo"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "11" # The JDK version to make available on the path.
java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
architecture: x64 # (x64 or x86) - defaults to x64
- run: |
cd hooks/${{ matrix.unit }}/
./gradlew test
# ---- Unit-Test | Python ----
unit-python:
name: "Unit-Test | Python"
runs-on: ubuntu-latest
strategy:
matrix:
unit: ["git-repo-scanner", "zap-advanced"]
steps:
- name: Checkout
uses: actions/checkout/@v2
- name: "Setup Python"
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: "Install dependencies"
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r scanners/${{ matrix.unit }}/scanner/requirements.txt
- name: "Execute Tests"
working-directory: scanners/${{ matrix.unit }}/scanner/
run: |
pip install pytest
pytest --ignore-glob='*_local.py' --ignore=tests/docker
# ---- Unit-Test | JavaScript ----
unit-javascript:
name: "Unit-Test | JavaScript"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: "list files and folders"
run: ls
- name: "Install npm dependencies in all parser sub projects"
run: |
for dir in scanners/*/parser/
do
cd $dir
if [ -f package.json ] && [ -f package-lock.json ]; then
echo "Installing dependencies for $dir"
npm ci
fi
# cd back
cd -
done
- name: "Install npm dependencies in all hook sub projects"
run: |
for dir in hooks/*/
do
cd $dir
if [ -f package.json ] && [ -f package-lock.json ]; then
echo "Installing dependencies for $dir"
npm ci
fi
# cd back
cd -
done
- name: "Install npm test dependencies"
run: |
npm ci
cd scanners/
npm ci
cd -
cd hooks/
npm ci
- name: "Compile Typescript"
run: |
cd hooks/declarative-subsequent-scans
npm run build
- name: "Run tests & publish code coverage"
uses: paambaati/codeclimate-action@v2.6.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageCommand: npm test -- --ci --colors --coverage
# ---- Build Stage ----
# ---- Build Stage | Operator & Lurcher ----
operator:
name: "Build | Operator"
needs:
- unit-python
- unit-javascript
runs-on: ubuntu-latest
strategy:
matrix:
component: ["operator", "lurcher"]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Go Setup
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Lint Go Code
run: |
cd ${{ matrix.component }}/
go fmt ./...
go vet ./...
- name: Docker Meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKER_NAMESPACE }}/${{ matrix.component }}
tag-sha: true
tag-semver: |
{{ version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.component }}
file: ./${{ matrix.component }}/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# ---- Build Stage | SDK Matrix ----
sdk:
name: "Build | SDKs"
needs:
- unit-python
- unit-javascript
runs-on: ubuntu-latest
strategy:
matrix:
sdk:
- parser-sdk
- hook-sdk
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Docker Meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKER_NAMESPACE }}/${{ matrix.sdk }}-nodejs
tag-sha: true
tag-semver: |
{{ version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.sdk }}/nodejs
file: ./${{ matrix.sdk }}/nodejs/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# ---- Build Stage | Matrix Hooks ----
hooks:
name: "Build | Hooks"
needs: sdk
runs-on: ubuntu-latest
strategy:
matrix:
hook:
- declarative-subsequent-scans
- finding-post-processing
- generic-webhook
- notification-hook
- persistence-elastic
- persistence-defectdojo
- update-field
- teams-webhook
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Docker Meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKER_NAMESPACE }}/${{ matrix.hook }}
tag-sha: true
tag-semver: |
{{ version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set baseImageTag to commit hash
run: |
echo "baseImageTag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./hooks/${{ matrix.hook }}
file: ./hooks/${{ matrix.hook }}/Dockerfile
build-args: |
namespace=${{ env.DOCKER_NAMESPACE }}
baseImageTag=${{ env.baseImageTag }}
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# ---- Build Stage | Matrix Parsers ----
parsers:
name: "Build | Parsers"
needs: sdk
runs-on: ubuntu-latest
strategy:
matrix:
parser:
- amass
- angularjs-csti-scanner
- git-repo-scanner
- gitleaks
- kube-hunter
- kubeaudit
- ncrack
- nikto
- nmap
- screenshooter
- ssh-scan
- sslyze
- test-scan
- trivy
- wpscan
- zap
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Docker Meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKER_NAMESPACE }}/parser-${{ matrix.parser }}
tag-sha: true
tag-semver: |
{{ version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set baseImageTag to commit hash
run: |
echo "baseImageTag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./scanners/${{ matrix.parser }}/parser
file: ./scanners/${{ matrix.parser }}/parser/Dockerfile
build-args: |
namespace=${{ env.DOCKER_NAMESPACE }}
baseImageTag=${{ env.baseImageTag }}
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# ---- Build | Scanners ----
# Note we only build images for scanner that don't provider official public container images
# ---- Build | Scanners | Third Party Scanner ----
# This Matrix should contain Third Party Scanners
# The Tag for the Image should be the current version of the Scanner
scanners-third-party:
name: "Build | Third Party Scanner"
needs:
- unit-python
- unit-javascript
runs-on: ubuntu-latest
strategy:
matrix:
scanner:
- angularjs-csti-scanner
- gitleaks
- kube-hunter
- kubeaudit
- ncrack
- nmap
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set ENV Var with Scanner Version
uses: mikefarah/yq@v4.4.1
# Notice: The current version of the scanner is provided via the Chart.yaml to ensure
# there is only one place to edit the version of a scanner
with:
cmd: echo scannerVersion=$(yq e .appVersion scanners/${{ matrix.scanner }}/Chart.yaml) >> $GITHUB_ENV
- name: Docker Meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKER_NAMESPACE }}/scanner-${{ matrix.scanner }}
tag-sha: true
tag-custom-only: true
tag-custom: ${{ env.scannerVersion }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./scanners/${{ matrix.scanner }}/scanner
file: ./scanners/${{ matrix.scanner }}/scanner/Dockerfile
build-args: |
scannerVersion=${{ env.scannerVersion }}
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# ---- Build | Scanners | Custom Scanner ----
# This Section contains Scanners that are developed by the secureCodeBox project
# The tag for these images will be the Semver of the release
scanners-custom:
name: "Build | Custom Scanner"
needs:
- unit-python
- unit-javascript
runs-on: ubuntu-latest
strategy:
matrix:
scanner:
- git-repo-scanner
- screenshooter
- test-scan
- zap-advanced
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Docker Meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKER_NAMESPACE }}/scanner-${{ matrix.scanner }}
tag-sha: true
tag-semver: |
{{ version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set baseImageTag to commit hash
run: |
echo "baseImageTag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./scanners/${{ matrix.scanner }}/scanner
file: ./scanners/${{ matrix.scanner }}/scanner/Dockerfile
build-args: |
baseImageTag=${{ env.baseImageTag }}
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
scanner-nikto:
# This Scanner has to be build seperately because the official image is only on GitHub but not on DockerHub
name: "Build | Scanner | Nikto"
needs:
- unit-python
- unit-javascript
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout secureCodeBox
uses: actions/checkout/@v2
with:
path: scb
- name: "Checkout Nikto"
uses: actions/checkout/@v2
with:
repository: "sullo/nikto"
path: nikto
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
- name: Build and Push Nikto to Local Registry
uses: docker/build-push-action@v2
with:
context: ./nikto/
file: ./nikto/Dockerfile
push: true
tags: localhost:5000/sullo/nikto:latest
- name: Docker Meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKER_NAMESPACE }}/scanner-nikto
tag-sha: true
tag-custom: 2.1.6
tag-semver: |
{{ version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set baseImageTag to commit hash
run: |
echo "baseImageTag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./scb/scanners/nikto/scanner
file: ./scb/scanners/nikto/scanner/Dockerfile
build-args: |
baseImageTag=${{ env.baseImageTag }}
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
# ---- Integration Tests ----
Integration-tests:
name: Integration Tests | k8s ${{ matrix.k8sVersion }}
needs:
- operator
- hooks
- parsers
- scanners-third-party
- scanners-custom
- scanner-nikto
runs-on: ubuntu-latest
strategy:
matrix:
k8sVersion:
- v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
- v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9
- v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729
- v1.18.19@sha256:7af1492e19b3192a79f606e43c35fb741e520d195f96399284515f077b3b622c
steps:
- uses: actions/checkout@master
- name: "Start kind cluster"
run: |
kind version
kind create cluster --image kindest/node:${{ matrix.k8sVersion }} --wait 3m
- name: "Inspect kind cluster"
run: |
kubectl config current-context
kubectl get node
# ---- Install Operator & Create Namespaces ----
- name: "Install Operator"
run: |
# Namespace in which the scans for the tests will be executed
kubectl create namespace integration-tests
# Operator Namespace
kubectl create namespace securecodebox-system
# Install Operator using the images of the current commit
helm -n securecodebox-system install securecodebox-operator ./operator/ --wait \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/operator" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="lurcher.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/lurcher" \
--set="lurcher.image.tag=sha-$(git rev-parse --short HEAD)" \
# ---- Operator Health Check ----
- name: "Inspect Operator"
run: |
echo "Deployment in namespace 'securecodebox-system'"
kubectl -n securecodebox-system get deployments
echo "Pods in namespace 'securecodebox-system'"
kubectl -n securecodebox-system get pods
echo "Operator Startup Logs"
kubectl -n securecodebox-system logs deployment/securecodebox-controller-manager
- name: "Create 'demo-apps' namespace"
run: "kubectl create namespace demo-apps"
# ---- Install Test Dependencies ----
- name: "Install Test Dependencies"
run: |
cd tests/integration/
npm ci
# ---- General Testing ----
# This steps should include Integration tests which are not related to a Specific Scanner
# ---- General Testing | ReadAndWrite Hook ----
- name: "Throws NoScanDefinition Error Integration Tests"
run: |
cd tests/integration/
npx jest --ci --color generic/no-scan-definition-error.test.js
- name: "Hooks (ReadAndWrite) Integration Tests"
run: |
helm -n integration-tests install update-category ./hooks/update-field/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/update-field" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="attribute.name=category" \
--set="attribute.value=fancy-category"
helm -n integration-tests install update-severity ./hooks/update-field/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/update-field" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="attribute.name=severity" \
--set="attribute.value=high"
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color generic/read-write-hook.test.js
helm -n integration-tests uninstall test-scan update-category update-severity
# ---- Gerneral Testing | ReadOnly Hook ----
- name: "Hooks (ReadOnly) Integration Tests"
run: |
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
helm -n integration-tests install http-webhook ./demo-apps/http-webhook
helm -n integration-tests install ro-hook ./hooks/generic-webhook/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/generic-webhook" \
--set="webhookUrl=http://http-webhook/hallo-welt" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color generic/read-only-hook.test.js
helm -n integration-tests uninstall test-scan http-webhook ro-hook
# ---- Install Demo Apps for Specific Tests ----
- name: "Install Demo Apps"
run: |
# Install dummy-ssh app
helm -n demo-apps install dummy-ssh ./demo-apps/dummy-ssh/ --set="fullnameOverride=dummy-ssh" --wait
# Install unsafe-https app
helm -n demo-apps install unsafe-https ./demo-apps/unsafe-https/ --set="fullnameOverride=unsafe-https" --wait
# Install bodgeit app
helm -n demo-apps install bodgeit ./demo-apps/bodgeit/ --set="fullnameOverride=bodgeit" --wait
# Install bodgeit app
helm -n demo-apps install petstore ./demo-apps/swagger-petstore/ --set="fullnameOverride=petstore" --wait
# Install old-wordpress app
helm -n demo-apps install old-wordpress ./demo-apps/old-wordpress/ --set="fullnameOverride=old-wordpress" --wait
# Install juiceshop app
helm -n demo-apps install juiceshop ./demo-apps/juice-shop/ --set="fullnameOverride=juiceshop" --wait
# Install plain nginx server
kubectl create deployment --image nginx:alpine nginx --namespace demo-apps
kubectl expose deployment nginx --port 80 --namespace demo-apps
# ---- OWASP Amass Integration Tests ----
- name: "amass Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install amass ./scanners/amass/ \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-amass" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color scanner/amass.test.js
# ---- gitleaks Integration Tests ----
- name: "gitleaks Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install gitleaks ./scanners/gitleaks/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-gitleaks" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-gitleaks" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color scanner/gitleaks.test.js
# ---- Kubehunter Integration Tests ----
- name: "kube-hunter Integration Tests"
run: |
helm -n integration-tests install kube-hunter ./scanners/kube-hunter/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-kube-hunter" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-kube-hunter" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color scanner/kube-hunter.test.js
# ---- Kubeaudit Integration Tests ----
- name: "kubeaudit Integration Tests"
run: |
kubectl create namespace kubeaudit-tests
helm -n kubeaudit-tests install juice-shop ./demo-apps/juice-shop/ --wait
helm -n integration-tests install kubeaudit ./scanners/kubeaudit/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-kubeaudit" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-kubeaudit" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="kubeauditScope=cluster"
cd tests/integration/
npx jest --ci --color scanner/kubeaudit.test.js
kubectl delete namespace kubeaudit-tests
# ---- Ncrack Integration Tests ----
- name: "ncrack Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install ncrack ./scanners/ncrack/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-ncrack" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-ncrack" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color scanner/ncrack.test.js
# ---- Nikto Integration Tests ----
- name: "nikto Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install nikto ./scanners/nikto/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-nikto" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-nikto" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color scanner/nikto.test.js
# ---- Nmap Integration Tests ----
- name: "nmap Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install nmap ./scanners/nmap/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-nmap" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-nmap" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color scanner/nmap.test.js
# ---- Notification Hook Tests ----
- name: "Notification Hook Tests"
run: |
helm -n integration-tests install test-scan ./scanners/test-scan/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-test-scan" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-test-scan" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
helm -n integration-tests install http-webhook ./demo-apps/http-webhook --wait
helm -n integration-tests install notification-hook ./hooks/notification-hook --values tests/integration/hooks/__testFiles__/notification-hook-values.yaml \
--set="image.repository=docker.io/${{env.DOCKER_NAMESPACE }}/notification-hook" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color ./hooks/notification-hook.test.js
helm -n integration-tests uninstall test-scan http-webhook notification-hook
# ---- SSH_SCAN Integration Tests ----
- name: "ssh-scan Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install ssh-scan ./scanners/ssh-scan/ \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-ssh-scan"
cd tests/integration/
npx jest --ci --color scanner/ssh-scan.test.js
# ---- SSLyze Integration Tests ----
- name: "sslyze Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install sslyze ./scanners/sslyze/ \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-sslyze"
cd tests/integration/
npx jest --ci --color scanner/sslyze.test.js
# ---- WPScan Integration Tests ----
- name: "WPScan Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install wpscan ./scanners/wpscan/ \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-wpscan" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
cd tests/integration/
npx jest --ci --color scanner/wpscan.test.js
# ---- Zap Integration Tests ----
- name: "ZAP Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install zap ./scanners/zap/ \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-zap"
cd tests/integration/
npx jest --ci --color scanner/zap.test.js
# ---- Zap Extended Integration Tests ----
- name: "ZAP Extended Integration Tests"
# disable zap extended test temporarily as they slow down the pipeline too much
if: ${{ false }}
run: |
kubectl -n integration-tests delete scans --all
helm -n integration-tests install zap-advanced ./scanners/zap-advanced/ \
--set="parseJob.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-zap" \
--set="parseJob.image.tag=sha-$(git rev-parse --short HEAD)" \
--set="scannerJob.image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-zap-advanced" \
--set="scannerJob.image.tag=sha-$(git rev-parse --short HEAD)"
kubectl apply -f ./scanners/zap-advanced/examples/integration-tests/scantype-configMap.yaml -n integration-tests
cd tests/integration/
npx jest --ci --color scanner/zap-advanced.test.js
# ---- Cascading Scans ncrack Integration Test ----
- name: "cascading Scans ncrack Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
# We'll run these in a separate namespace so that only the cascadingRules we want to test will be used
kubectl create namespace cascading-tests
# Install declarative-subsequent-scans hook
helm upgrade --install dssh ./hooks/declarative-subsequent-scans/ -n cascading-tests \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/declarative-subsequent-scans" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
# Install nmap
helm -n cascading-tests install nmap ./scanners/nmap/ \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-nmap" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-nmap" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
# Install ncrack
printf "root\nadmin\n" > users.txt
printf "THEPASSWORDYOUCREATED\n123456\npassword\n" > passwords.txt
kubectl create secret generic --from-file users.txt --from-file passwords.txt ncrack-lists -n cascading-tests
cat <<EOF | helm -n cascading-tests install ncrack ./scanners/ncrack \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-ncrack" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-ncrack" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)" \
--values -
scannerJob:
extraVolumes:
- name: ncrack-lists
secret:
secretName: ncrack-lists
extraVolumeMounts:
- name: ncrack-lists
mountPath: "/ncrack/"
EOF
# Actually run the tests
cd tests/integration/
npx jest --ci --color scanner/cascade-nmap-ncrack.test.js
# Clean up:
kubectl -n cascading-tests delete scans --all
kubectl delete namespace cascading-tests
# ---- Cascading Scans SSLyze Integration Tests ----
- name: "cascading Scans sslyze Integration Tests"
run: |
kubectl -n integration-tests delete scans --all
# We'll run these in a separate namespace so that only the cascadingRules we want to test will be used
kubectl create namespace cascading-tests
# Install declarative-subsequent-scans hook
helm upgrade --install dssh ./hooks/declarative-subsequent-scans/ -n cascading-tests --wait \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/declarative-subsequent-scans" \
--set="image.tag=sha-$(git rev-parse --short HEAD)"
# Install unsafe-https
helm upgrade --install unsafe-https ./demo-apps/unsafe-https/ -n cascading-tests --wait
# Install nmap
helm -n cascading-tests install nmap ./scanners/nmap/ --wait \
--set="image.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/scanner-nmap" \
--set="image.tag=sha-$(git rev-parse --short HEAD)" \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-nmap" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
# Install sslyze
helm -n cascading-tests install sslyze ./scanners/sslyze/ --wait \
--set="parserImage.repository=docker.io/${{ env.DOCKER_NAMESPACE }}/parser-sslyze" \
--set="parserImage.tag=sha-$(git rev-parse --short HEAD)"
# Actually run the tests
cd tests/integration/
npx jest --ci --color scanner/cascade-nmap-sslyze.test.js
# Clean up:
kubectl -n cascading-tests delete scans --all
kubectl delete namespace cascading-tests
# ---- Debuging Cluster on Failure ----
- name: Inspect Post Failure
if: failure()
run: |
echo "List all 'HelmCharts' in all namespaces"
helm list --all-namespaces
echo "List all 'Scans' in all namespaces"
kubectl -n integration-tests get scan -o wide --all-namespaces
echo "List all 'Jobs' in all namespaces"
kubectl -n integration-tests get jobs -o wide --all-namespaces
echo "List all 'Pods' in all namespaces"
kubectl -n integration-tests get pods -o wide --all-namespaces
echo "List all 'Services' in all namespaces"
kubectl -n integration-tests get services -o wide --all-namespaces
- name: "Inspect Operator"
if: failure()
run: |
echo "Deployment in namespace 'securecodebox-system'"
kubectl -n securecodebox-system get deployments
echo "Deployment in namespace 'securecodebox-system'"
kubectl -n securecodebox-system get pods
echo "Operator Startup Logs"
kubectl -n securecodebox-system logs deployment/securecodebox-controller-manager
# ---- Clean UP ----
- name: "Delete kind cluster"
run: |
kind delete cluster