-
Notifications
You must be signed in to change notification settings - Fork 11
515 lines (450 loc) · 15.4 KB
/
test-suite.yaml
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
name: Test Suite
on:
push:
branches: [ "*" ]
paths-ignore:
- 'docs/**'
- 'README.md'
pull_request:
branches: [ "*" ]
paths-ignore:
- 'docs/**'
- 'README.md'
jobs:
build-host-scanner-image:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set image version
id: image-version
run: echo '::set-output name=IMAGE_VERSION::test'
- name: Set image name
id: image-name
run: echo '::set-output name=IMAGE_NAME::quay.io/${{ github.repository_owner }}/host-scanner'
- name: Login to Quay.io
env:
QUAY_PASSWORD: ${{ secrets.QUAYIO_REGISTRY_PASSWORD }}
QUAY_USERNAME: ${{ secrets.QUAYIO_REGISTRY_USERNAME }}
run: docker login -u="${QUAY_USERNAME}" -p="${QUAY_PASSWORD}" quay.io
- name: Build the Docker image
run: |
docker buildx \
build . \
--file build/Dockerfile \
--tag ${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.image-version.outputs.IMAGE_VERSION }} \
--tag ${{ steps.image-name.outputs.IMAGE_NAME }}:test \
--build-arg BUILD_VERSION=${{ steps.image-version.outputs.IMAGE_VERSION }} \
--push
env:
CGO_ENABLED: 0
integration-test:
needs: [build-host-scanner-image]
runs-on: ubuntu-latest
steps:
- name: Checkout host-scanner repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
- name: Checkout systests repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3
with:
repository: armosec/system-tests
path: system-tests
- uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # ratchet:actions/setup-python@v4
with:
python-version: '3.8.13'
cache: 'pip'
- name: create env
run: ./create_env.sh
working-directory: system-tests/
- name: Create k8s Kind Cluster
id: kind-cluster-install
uses: helm/kind-action@d08cf6ff1575077dee99962540d77ce91c62387d # ratchet:helm/kind-action@v1.3.0
with:
cluster_name: integration
- name: run integration test
env:
CUSTOMER: ${{ secrets.CUSTOMER }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
CLIENT_ID: ${{ secrets.CLIENT_ID_PROD }}
SECRET_KEY: ${{ secrets.SECRET_KEY_PROD }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
source systests_python_env/bin/activate
python3 systest-cli.py \
-t host_scanner_with_hostsensorrule \
-b production \
-c CyberArmorTests \
--duration 3 \
--logger DEBUG \
--kwargs ks_branch=release \
host_scan_yaml=../deployment/host-scanner.yaml
deactivate
working-directory: system-tests/
e2e-test-multi-version-support:
strategy:
fail-fast: false
matrix:
k8s: [
{
name: 'kind',
version: 'v1.25.0',
port: '7825'
},
{
name: 'kind',
version: 'v1.26.0',
port: '7826'
},
{
name: 'kind',
version: 'v1.27.0',
port: '7827'
}
]
needs: [build-host-scanner-image]
runs-on: ubuntu-latest
steps:
- name: Clone host-scanner repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Kubectl
uses: azure/setup-kubectl@v3
id: install
- name: Install Kind
uses: engineerd/setup-kind@v0.5.0
with:
skipClusterCreation: true
version: v0.18.0
- name: Setup test clusters
run: |
kind create cluster \
--kubeconfig test-${{ matrix.k8s.version }} \
--name test-${{ matrix.k8s.version }} \
--image kindest/node:${{ matrix.k8s.version }}
- name: Install host-scanner
run: |
kubectl apply \
--kubeconfig test-${{ matrix.k8s.version }} \
-f deployment/host-scanner.yaml
- name: Get Namespace
id: namespace
run: |
namespace=$(cat deployment/host-scanner.yaml | grep -oP "(?<=namespace: )(.*)")
echo "NAMESPACE=$namespace" >> $GITHUB_OUTPUT
- name: Wait for host-scanner ready
run: |
sleep 15
kubectl wait \
--for=condition=ready \
pod \
-l name=host-scanner \
--namespace ${{ steps.namespace.outputs.NAMESPACE }} \
--timeout=300s \
--kubeconfig test-${{ matrix.k8s.version }}
- name: Setup Kubernetes port-forward daemon
run: |
kubectl port-forward \
'daemonset/host-scanner' \
${{ matrix.k8s.port }}:7888 \
--namespace=${{ steps.namespace.outputs.NAMESPACE }} \
--kubeconfig=test-${{ matrix.k8s.version }} &
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.22'
- name: Run e2e tests
working-directory: ./e2e
run: |
go test \
-tags ${{ matrix.k8s.name }} \
-v -ginkgo.v \
-args -port ${{ matrix.k8s.port }}
env:
KUBECONFIG: ../test-${{ matrix.k8s.version }}
# setup AKS cluster to run host-scanner on it
e2e-test-setup-aks:
strategy:
fail-fast: false
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
needs: [build-host-scanner-image]
runs-on: ubuntu-latest
steps:
- name: Download terraform scripts
uses: actions/checkout@v3
with:
ref: 'fix/add-conditional-output-to-aks'
repository: armosec/terraform-test-clusters
token: ${{ secrets.GH_TOKEN_TERRAFORM_TEST_CLUSTER }}
- uses: azure/login@v1
with:
creds: '{"clientId":"${{ secrets.AZURE_AD_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_AD_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_AD_TENANT_ID }}"}'
- name: Setup terraform
uses: hashicorp/setup-terraform@v2
- name: terraform Init
run: |
terraform init
working-directory: ./AKS/module_based/
- name: terraform apply
run: |
terraform apply \
-auto-approve \
-var cluster_owner=hs-e2e \
-var resource_group_name=automation-sonar-rg \
-var create_resource_group=0
working-directory: ./AKS/module_based/
- name: Get cluster name
id: cluster_name
run: |
cluster_name=$(terraform-bin output -raw kubernetes_cluster_name)
echo "CLUSTER_NAME=$cluster_name" >> $GITHUB_OUTPUT
working-directory: ./AKS/module_based/
- name: Retrieve aks kubconfig
uses: azure/CLI@v1
with:
inlineScript: |
az aks get-credentials \
--resource-group automation-sonar-rg \
--name ${{ steps.cluster_name.outputs.CLUSTER_NAME }} \
--admin \
--file ./AKS/module_based/test-aks
- name: Set right ownerships
run: |
sudo chown runner:docker test-aks
sudo chown runner:docker terraform.tfstate
working-directory: ./AKS/module_based/
- name: Encrypt kubeconfig files
run: |
gpg \
--batch \
-c \
--symmetric \
--cipher-algo AES256 \
--passphrase "${{ secrets.GPG_PASSPHRASE }}" \
./test-aks
working-directory: ./AKS/module_based/
- uses: actions/upload-artifact@v3
with:
name: kubeconfig-aks
path: |
./AKS/module_based/test-aks.gpg
retention-days: 1
- name: Encrypt tfstate file
run: |
gpg \
--batch \
-c \
--symmetric \
--cipher-algo AES256 \
--passphrase "${{ secrets.GPG_PASSPHRASE }}" \
./terraform.tfstate
working-directory: ./AKS/module_based/
- uses: actions/upload-artifact@v3
with:
name: tfstate-aks
path: |
./AKS/module_based/terraform.tfstate.gpg
retention-days: 1
# setup-eks:
# strategy:
# fail-fast: false
# runs-on: ubuntu-latest
# needs: [build-host-scanner-image]
# setup-gke:
# strategy:
# fail-fast: false
# runs-on: ubuntu-latest
# needs: [build-host-scanner-image]
e2e-test-install-host-scanner:
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
strategy:
fail-fast: false
matrix:
k8s: [
{
name: 'aks',
version: 'aks',
port: '7801'
}
]
runs-on: ubuntu-latest
needs: [e2e-test-setup-aks]
steps:
- name: Clone host-scanner repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Kubectl
uses: azure/setup-kubectl@v3
id: install
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: kubeconfig-${{ matrix.k8s.version }}
path: ./test-${{ matrix.k8s.version }}
- name: Decrypt files
run: |
gpg \
--quiet \
--batch \
--yes \
--decrypt \
--passphrase "${{ secrets.GPG_PASSPHRASE }}" \
--output test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }} \
test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }}.gpg
- uses: azure/use-kubelogin@v1
with:
kubelogin-version: 'v0.0.29'
- uses: azure/login@v1
with:
creds: '{"clientId":"${{ secrets.AZURE_AD_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_AD_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_AD_TENANT_ID }}"}'
- name: Convert kubeconfig
run: |
kubelogin convert-kubeconfig -l azurecli
- name: Install host-scanner
run: |
kubectl apply \
--kubeconfig test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }} \
-f deployment/host-scanner.yaml
- name: Get Namespace
id: namespace
run: |
namespace=$(cat deployment/host-scanner.yaml | grep -oP "(?<=namespace: )(.*)")
echo "NAMESPACE=$namespace" >> $GITHUB_OUTPUT
- name: Wait for host-scanner ready
run: |
sleep 15
kubectl wait \
--for=condition=ready \
pod \
-l name=host-scanner \
--namespace ${{ steps.namespace.outputs.NAMESPACE }} \
--timeout=300s \
--kubeconfig test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }}
e2e-test-run-test-suite:
if: always()
strategy:
max-parallel: 8
fail-fast: false
matrix:
k8s: [
{
name: 'aks',
version: 'aks',
port: '7801'
}
]
runs-on: ubuntu-latest
needs: [e2e-test-install-host-scanner]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.22'
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: kubeconfig-${{ matrix.k8s.version }}
path: ./test-${{ matrix.k8s.version }}
- name: Decrypt kubeconfig files
run: |
gpg \
--quiet \
--batch \
--yes \
--decrypt \
--passphrase "${{ secrets.GPG_PASSPHRASE }}" \
--output test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }} \
test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }}.gpg
- name: Get Namespace
id: namespace
run: |
namespace=$(cat deployment/host-scanner.yaml | grep -oP "(?<=namespace: )(.*)")
echo "NAMESPACE=$namespace" >> $GITHUB_OUTPUT
- name: Setup Kubernetes port-forward daemon
run: |
kubectl port-forward \
'daemonset/host-scanner' \
${{ matrix.k8s.port }}:7888 \
--namespace=${{ steps.namespace.outputs.NAMESPACE }} \
--kubeconfig=test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }} &
- name: Run e2e tests
working-directory: ./e2e
run: |
go test \
-tags ${{ matrix.k8s.name }} \
-v -ginkgo.v \
-args -port ${{ matrix.k8s.port }}
env:
KUBECONFIG: ../test-${{ matrix.k8s.version }}/test-${{ matrix.k8s.version }}
e2e-test-destroy-aks:
if: always()
strategy:
fail-fast: false
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
needs: [e2e-test-run-test-suite]
runs-on: ubuntu-latest
steps:
- name: Download terraform scripts
uses: actions/checkout@v3
with:
ref: 'fix/add-conditional-output-to-aks'
repository: armosec/terraform-test-clusters
token: ${{ secrets.GH_TOKEN_TERRAFORM_TEST_CLUSTER }}
- uses: azure/login@v1
with:
creds: '{"clientId":"${{ secrets.AZURE_AD_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_AD_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_AD_TENANT_ID }}"}'
- name: Setup terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
- name: Download tfstate artifact
uses: actions/download-artifact@v3
with:
name: tfstate-aks
path: ./AKS/module_based/
- name: Decrypt files
run: |
gpg \
--quiet \
--batch \
--yes \
--decrypt \
--passphrase "${{ secrets.GPG_PASSPHRASE }}" \
--output terraform.tfstate \
terraform.tfstate.gpg
working-directory: ./AKS/module_based/
- name: terraform Init
run: |
terraform init
working-directory: ./AKS/module_based/
- name: terraform destroy
run: |
terraform destroy \
-auto-approve \
-var cluster_owner=hs-e2e \
-var resource_group_name=automation-sonar-rg \
-var create_resource_group=0
working-directory: ./AKS/module_based/