-
Notifications
You must be signed in to change notification settings - Fork 6
3070 lines (2709 loc) · 148 KB
/
Copy pathci.yml
File metadata and controls
3070 lines (2709 loc) · 148 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
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-FileCopyrightText: 2025 Deutsche Telekom AG
#
# SPDX-License-Identifier: Apache-2.0
name: CI
on:
push:
branches: [ main, deployment-testing ]
pull_request:
branches: [ main, deployment-testing ]
workflow_dispatch: {}
permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
KIND_VERSION: 'v0.31.0'
KIND_NODE_IMAGE: 'kindest/node:v1.34.3@sha256:08497ee19eace7b4b5348db5c6a1591d7752b164530a36f855cb0f2bdcbadd48'
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Verify release provenance workflow
run: make verify-release-provenance
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Verify formatting
run: go fmt ./... | tee /dev/stderr | wc -l | grep -q '^0$' || { echo 'Please run make fmt'; exit 1; }
- name: Install tools (controller-gen, kustomize, golangci-lint)
run: make controller-gen kustomize golangci-lint
- name: Lint
run: make lint
unit-tests-controller:
name: Controller Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Controller unit tests (excluding bgctl and e2e)
run: make test-controller
- name: Upload coverage
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: cover-controller.out
flags: controller
fail_ci_if_error: false
unit-tests-cli:
name: CLI Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: bgctl unit tests
run: make test-cli
- name: bgctl e2e tests (mocked)
run: make test-cli-e2e
- name: Upload coverage
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: cover-cli.out
flags: cli
fail_ci_if_error: false
crd-validation:
name: CRD Schema & API Server Validation
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Validate CRDs (offline schema + envtest API server)
run: make validate-crds
- name: Validate e2e fixtures against Go validation rules
run: make validate-fixtures
npm-audit:
name: Frontend Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '24.11.0'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Frontend security audit (npm)
run: |
cd frontend
npm ci
npm audit --audit-level=high --json > ../npm-audit.json
- name: Upload npm audit results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: npm-audit
path: npm-audit.json
manifest-validation:
name: Manifest Validation & Comparison
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0 # Full history for tag access
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Install tools
run: make controller-gen kustomize
- name: Generate manifests
run: make manifests
- name: Build all kustomize targets
run: |
mkdir -p manifests-current
# Note: 'dev' target is excluded because it requires generated TLS certificates
# that are created by e2e/kind-setup-single.sh and not checked into git
for target in base debug; do
echo "Building config/$target..."
./bin/kustomize build config/$target > manifests-current/$target.yaml
echo "✅ config/$target built successfully"
done
# Also build CRDs only
./bin/kustomize build config/crd > manifests-current/crds.yaml
echo "✅ config/crd built successfully"
- name: Get latest release tag
id: get_release
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LATEST_TAG" ]; then
echo "No previous release found, skipping comparison"
echo "has_previous_release=false" >> $GITHUB_OUTPUT
else
echo "Latest release: $LATEST_TAG"
echo "has_previous_release=true" >> $GITHUB_OUTPUT
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
fi
- name: Build manifests from previous release
if: steps.get_release.outputs.has_previous_release == 'true'
run: |
LATEST_TAG=${{ steps.get_release.outputs.tag }}
mkdir -p manifests-previous
# Checkout previous release in a temporary directory
git worktree add /tmp/prev-release $LATEST_TAG
cd /tmp/prev-release
# Install tools for previous release
make controller-gen kustomize 2>/dev/null || true
make manifests 2>/dev/null || true
# Build targets that exist in previous release
# Note: 'dev' target excluded (requires generated TLS certs not in git)
for target in base debug default with-webhooks; do
if [ -d "config/$target" ]; then
echo "Building previous config/$target..."
./bin/kustomize build config/$target > $GITHUB_WORKSPACE/manifests-previous/$target.yaml 2>/dev/null || echo "# Build failed for $target" > $GITHUB_WORKSPACE/manifests-previous/$target.yaml
fi
done
# Build CRDs
./bin/kustomize build config/crd > $GITHUB_WORKSPACE/manifests-previous/crds.yaml 2>/dev/null || echo "# Build failed" > $GITHUB_WORKSPACE/manifests-previous/crds.yaml
cd $GITHUB_WORKSPACE
git worktree remove /tmp/prev-release --force
- name: Compare manifests
id: compare
if: steps.get_release.outputs.has_previous_release == 'true'
run: |
echo "## Manifest Changes vs ${{ steps.get_release.outputs.tag }}" > manifest-diff.md
echo "" >> manifest-diff.md
CHANGES_FOUND=false
# Note: 'dev' target is excluded (requires generated TLS certs not in git)
for target in base debug crds; do
CURRENT="manifests-current/$target.yaml"
PREVIOUS="manifests-previous/$target.yaml"
if [ ! -f "$CURRENT" ]; then
echo "### $target: New target (not in previous release)" >> manifest-diff.md
continue
fi
if [ ! -f "$PREVIOUS" ]; then
# Check if old naming exists
if [ "$target" = "base" ] && [ -f "manifests-previous/default.yaml" ]; then
PREVIOUS="manifests-previous/default.yaml"
echo "### $target (comparing to default)" >> manifest-diff.md
else
echo "### $target: New target (not in previous release)" >> manifest-diff.md
continue
fi
else
echo "### $target" >> manifest-diff.md
fi
# Compare and capture diff
if diff -u "$PREVIOUS" "$CURRENT" > /tmp/diff-$target.txt 2>&1; then
echo "✅ No changes" >> manifest-diff.md
else
CHANGES_FOUND=true
LINES=$(wc -l < /tmp/diff-$target.txt)
echo "⚠️ Changes detected ($LINES diff lines)" >> manifest-diff.md
echo "" >> manifest-diff.md
echo "<details><summary>Show diff</summary>" >> manifest-diff.md
echo "" >> manifest-diff.md
echo '```diff' >> manifest-diff.md
head -500 /tmp/diff-$target.txt >> manifest-diff.md
if [ "$LINES" -gt 500 ]; then
echo "... (truncated, $LINES total lines)" >> manifest-diff.md
fi
echo '```' >> manifest-diff.md
echo "</details>" >> manifest-diff.md
fi
echo "" >> manifest-diff.md
done
if [ "$CHANGES_FOUND" = "true" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
# Log to CI output
echo "=== Manifest Comparison Summary ==="
cat manifest-diff.md
- name: Comment on PR with manifest changes
if: github.event_name == 'pull_request' && steps.get_release.outputs.has_previous_release == 'true' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs');
const diffContent = fs.readFileSync('manifest-diff.md', 'utf8');
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const botComment = comments.find(c =>
c.user.type === 'Bot' &&
c.body.includes('## Manifest Changes vs')
);
const body = `<!-- manifest-comparison-comment -->\n${diffContent}`;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}
- name: Upload manifest artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: manifests
path: |
manifests-current/
manifest-diff.md
retention-days: 30
frontend-tests:
name: Frontend Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '24.11.0'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Type check
run: npm run typecheck
- name: Lint
# Note: warnings are tolerated; only errors fail the build
run: npx eslint .
- name: Unit tests
run: npm run test:coverage
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Accessibility tests (axe-core WCAG 2.1 AA + AAA)
run: npm run test:a11y
- name: Upload a11y Playwright report
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: playwright-a11y-report
path: frontend/playwright-report-a11y/
retention-days: 7
- name: Upload a11y test results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: failure()
with:
name: playwright-a11y-results
path: frontend/test-results-a11y/
retention-days: 7
- name: Upload frontend coverage
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: frontend
files: coverage/coverage-final.json
flags: frontend
fail_ci_if_error: false
handle_no_reports_found: true
helm-lint:
name: Helm Chart Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Helm
uses: azure/setup-helm@dda3372f752e03dde6b3237bc9431cdc2f7a02a2 # v5.0.0
with:
version: v4.0.4
- name: Lint Helm charts
run: |
helm lint charts/escalation-config
- name: Template validation
run: |
helm template test-release charts/escalation-config --debug
build-image:
name: Build Image
runs-on: ubuntu-latest
# No direct 'needs' on quality-gate jobs — this build runs in parallel with lint/tests.
# Quality gates are enforced by the E2E jobs, whose 'needs' include
# lint, unit-tests-controller, unit-tests-cli, crd-validation, frontend-tests, and helm-lint.
# Registry push, SBOM, and attestation are in a separate 'publish-image' job
# so E2E tests can start as soon as the image artifact is ready.
permissions:
contents: read
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up QEMU
uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4.1.0
- name: Set up Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
with:
driver-opts: image=moby/buildkit:rootless
- name: Cache Docker layers
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: /tmp/.buildx-cache
key: buildx-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
buildx-${{ github.ref_name }}-
buildx-
- name: Docker meta
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=pr-${{ github.event.number }},enable=${{ github.event_name == 'pull_request' }}
type=sha
labels: |
org.opencontainers.image.title=Kubernetes Breakglass
org.opencontainers.image.description=Secure, auditable privilege escalation system for Kubernetes clusters with real-time webhook integration and time-bounded access
org.opencontainers.image.url=https://github.com/telekom/k8s-breakglass
org.opencontainers.image.documentation=https://github.com/telekom/k8s-breakglass/tree/main/docs
org.opencontainers.image.source=https://github.com/telekom/k8s-breakglass
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.vendor=Deutsche Telekom
org.opencontainers.image.version=${{ github.sha }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
com.github.repo.branch=${{ github.ref_name }}
com.github.repo.owner=${{ github.repository_owner }}
com.buildkit.build.ref=${{ github.ref }}
- name: Build image locally
id: build
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
push: false
load: true
# CI builds amd64 only for speed; arm64 is validated in the release
# workflow via native runners (no QEMU emulation overhead).
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.ref_name }}
GIT_COMMIT=${{ github.sha }}
BUILD_DATE=${{ github.event.head_commit.timestamp }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Tag image for E2E artifact
run: |
# Get the first tag from the built images and tag it as breakglass:e2e for local use
FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
echo "Tagging $FIRST_TAG as breakglass:e2e for E2E tests"
docker tag "$FIRST_TAG" breakglass:e2e
docker images | grep breakglass
- name: Build tmux-debug image for E2E tests
run: |
# Build the tmux debug image used by terminal sharing/debug session tests
docker build -t breakglass-tmux-debug:latest -f e2e/images/tmux-debug/Dockerfile e2e/images/tmux-debug/
docker images | grep tmux-debug
- name: Save Docker images for E2E tests
run: |
mkdir -p /tmp/image-artifacts
docker save breakglass:e2e -o /tmp/image-artifacts/breakglass-e2e.tar
docker save breakglass-tmux-debug:latest -o /tmp/image-artifacts/breakglass-tmux-debug.tar
ls -lh /tmp/image-artifacts/
- name: Upload Docker image artifact for E2E
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: breakglass-e2e-image
path: /tmp/image-artifacts/
retention-days: 1
compression-level: 0
- name: Move cache
if: always()
run: |
rm -rf /tmp/.buildx-cache-old
mv /tmp/.buildx-cache /tmp/.buildx-cache-old || true
mv /tmp/.buildx-cache-new /tmp/.buildx-cache || true
# ============================================================================
# Publish Image — SBOM, registry push, attestation, Artifactory push
# Runs in parallel with E2E tests (does not block them).
# ============================================================================
publish-image:
name: Publish Image
runs-on: ubuntu-latest
needs: [build-image]
permissions:
contents: read
packages: write
id-token: write # Required for actions/attest-build-provenance
attestations: write # Required to persist attestations
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
with:
driver-opts: image=moby/buildkit:rootless
- name: Download Docker image artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: breakglass-e2e-image
path: /tmp/image-artifacts
- name: Load Docker image
run: |
docker load -i /tmp/image-artifacts/breakglass-e2e.tar
docker images | grep breakglass
- name: Login to GHCR
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine if PR is from fork
id: fork_check
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
PR_REPO_OWNER="${{ github.event.pull_request.head.repo.owner.login }}"
MAIN_REPO_OWNER="${{ github.repository_owner }}"
if [ "$PR_REPO_OWNER" == "$MAIN_REPO_OWNER" ]; then
echo "push_to_registry=true" >> $GITHUB_OUTPUT
echo "PR from internal repo, will push to registry"
else
echo "push_to_registry=false" >> $GITHUB_OUTPUT
echo "PR from fork, skipping registry push"
fi
else
echo "push_to_registry=true" >> $GITHUB_OUTPUT
echo "Not a PR, will push to registry"
fi
- name: Determine registry push eligibility
id: push_check
run: |
# Dependabot PRs receive a read-only GITHUB_TOKEN even though they
# originate from the same repo (not a fork). Pushing images and
# attestations would fail with 404/403 errors.
if [ "${{ github.actor }}" == "dependabot[bot]" ]; then
echo "can_push=false" >> $GITHUB_OUTPUT
echo "Dependabot PR — GITHUB_TOKEN is read-only, skipping registry push"
elif [ "${{ github.event_name }}" != "pull_request" ] || [ "${{ steps.fork_check.outputs.push_to_registry }}" == "true" ]; then
echo "can_push=true" >> $GITHUB_OUTPUT
else
echo "can_push=false" >> $GITHUB_OUTPUT
fi
- name: Docker meta
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=pr-${{ github.event.number }},enable=${{ github.event_name == 'pull_request' && steps.fork_check.outputs.push_to_registry == 'true' }}
type=sha
- name: Tag image with metadata tags
env:
TAGS: ${{ steps.meta.outputs.tags }}
run: |
# The loaded image is tagged as breakglass:e2e — re-tag with metadata tags for registry push
while IFS= read -r tag; do
[ -z "$tag" ] && continue
echo "Tagging breakglass:e2e -> $tag"
docker tag breakglass:e2e "$tag"
done <<< "$TAGS"
docker images | grep breakglass | head -10
- name: Generate SBOM (Syft)
uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
id: sbom
if: ${{ steps.push_check.outputs.can_push == 'true' }}
with:
image: breakglass:e2e
format: spdx-json
output-file: sbom.json
- name: Push image to GHCR
id: registry_push
if: ${{ steps.push_check.outputs.can_push == 'true' }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
run: |
set -e
PUSH_DIGEST=""
while IFS= read -r tag; do
[ -z "$tag" ] && continue
echo "Pushing ${tag}..."
OUTPUT=$(docker push "$tag" 2>&1)
echo "$OUTPUT"
LINE_DIGEST=$(echo "$OUTPUT" | grep -oP 'digest: \Ksha256:\S+' | tail -1 || true)
if [ -n "$LINE_DIGEST" ] && [ -z "$PUSH_DIGEST" ]; then
PUSH_DIGEST="$LINE_DIGEST"
fi
done <<< "$TAGS"
if [ -z "$PUSH_DIGEST" ]; then
echo "::warning::Could not extract digest from docker push output"
FIRST_TAG=$(echo "$TAGS" | head -n1)
if [ -n "$FIRST_TAG" ]; then
echo "Polling manifest for fallback registry digest of ${FIRST_TAG}..."
for i in $(seq 1 30); do
INSPECT_OUTPUT=$(docker buildx imagetools inspect "$FIRST_TAG" 2>/dev/null) || true
INSPECT_DIGEST=$(printf '%s\n' "$INSPECT_OUTPUT" | awk '/^Digest:[[:space:]]+sha256:[0-9a-f]{64}$/ {print $2; exit}')
if [ -n "$INSPECT_DIGEST" ]; then
PUSH_DIGEST="$INSPECT_DIGEST"
echo "Registry digest resolved after ${i} attempt(s)"
break
fi
echo "Attempt ${i}/30: registry digest not yet available, retrying in 10s..."
sleep 10
done
fi
fi
if [ -z "$PUSH_DIGEST" ]; then
echo "::error::Could not determine registry digest after a successful push; provenance attestation would be skipped."
exit 1
fi
echo "Registry digest: ${PUSH_DIGEST}"
echo "digest=${PUSH_DIGEST}" >> $GITHUB_OUTPUT
- name: Wait for manifest availability
if: ${{ steps.push_check.outputs.can_push == 'true' && steps.registry_push.outputs.digest != '' }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
run: |
set -e
FIRST_TAG=$(echo "$TAGS" | head -n1)
echo "Polling for manifest availability of ${FIRST_TAG}..."
for i in $(seq 1 30); do
if docker buildx imagetools inspect "$FIRST_TAG" --raw > /dev/null 2>&1; then
echo "Manifest available after ${i} attempt(s)"
exit 0
fi
echo "Attempt ${i}/30: manifest not yet available, retrying in 10s..."
sleep 10
done
echo "::warning::Manifest still not available after 30 attempts (300s). Attestation may fail."
- name: Attest provenance
if: ${{ steps.push_check.outputs.can_push == 'true' && steps.registry_push.outputs.digest != '' }}
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.registry_push.outputs.digest }}
push-to-registry: true
- name: Upload SBOM artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: ${{ steps.push_check.outputs.can_push == 'true' }}
with:
name: sbom
path: sbom.json
- name: Push image to Artifactory (OCI)
# Skip for Dependabot PRs (no access to secrets) and fork PRs
if: ${{ github.actor != 'dependabot[bot]' && steps.push_check.outputs.can_push == 'true' && steps.registry_push.outputs.digest != '' }}
env:
ARTIFACTORY_URL: artifactory.devops.telekom.de
ARTIFACTORY_REPO: cit-t-caas-oci/images/t-caas
REGISTRY: ${{ env.REGISTRY }}
IMAGE: ${{ env.IMAGE_NAME }}
run: |
set -e
echo "Preparing to push image to Artifactory"
echo "${{ secrets.AF_TOKEN }}" | docker login --username ${{ secrets.AF_USER }} --password-stdin https://${ARTIFACTORY_URL}
REPO_KEY=$(echo "${ARTIFACTORY_REPO}" | cut -d'/' -f1)
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u "${{ secrets.AF_USER }}:${{ secrets.AF_TOKEN }}" "https://${ARTIFACTORY_URL}/artifactory/api/storage/${REPO_KEY}" ) || true
echo "Artifactory storage API HTTP status: ${HTTP_STATUS}"
if [ "${HTTP_STATUS}" != "200" ]; then
echo "Warning: Artifactory repo ${REPO_KEY} not accessible (HTTP ${HTTP_STATUS}). The push may fail due to permissions."
fi
echo "Using local image breakglass:e2e for Artifactory push"
ART_TAG=${GITHUB_SHA}
ART_IMG=${ARTIFACTORY_URL}/${ARTIFACTORY_REPO}/${IMAGE}:${ART_TAG}
echo "Tagging breakglass:e2e -> ${ART_IMG}"
docker tag breakglass:e2e "${ART_IMG}"
set -x
docker push "${ART_IMG}"
set +x
sleep 3
CHECK_PATH=$(echo "${ARTIFACTORY_REPO}/${IMAGE}" | sed 's@//*@/@g')
HTTP_STATUS_AFTER=$(curl -s -o /dev/null -w "%{http_code}" -u "${{ secrets.AF_USER }}:${{ secrets.AF_TOKEN }}" "https://${ARTIFACTORY_URL}/artifactory/api/storage/${CHECK_PATH}?list" ) || true
echo "Artifactory storage API HTTP status for pushed path: ${HTTP_STATUS_AFTER}"
if [ "${HTTP_STATUS_AFTER}" = "200" ]; then
echo "Artifact path appears present in Artifactory."
else
echo "Artifact path not found or not accessible (HTTP ${HTTP_STATUS_AFTER}). It might be a permission issue or Artifactory indexing delay."
fi
# ============================================================================
# E2E Tests - Use the Docker image artifact from build-image job
# ============================================================================
single-cluster-e2e:
name: Single-Cluster E2E Tests
runs-on: ubuntu-latest
timeout-minutes: 120
needs: [build-image, lint, unit-tests-controller, unit-tests-cli, crd-validation, frontend-tests, helm-lint]
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Free runner disk space
run: |
echo "Disk before cleanup:"
df -h /
sudo rm -rf \
/usr/share/dotnet \
/usr/local/lib/android \
/usr/local/share/boost \
/opt/ghc \
/opt/hostedtoolcache/CodeQL
docker system prune -af || true
echo "Disk after cleanup:"
df -h /
- name: Download Docker image artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: breakglass-e2e-image
path: /tmp/image-artifacts
- name: Load Docker image
run: |
docker load -i /tmp/image-artifacts/breakglass-e2e.tar
docker load -i /tmp/image-artifacts/breakglass-tmux-debug.tar
docker images | grep -E 'breakglass|tmux'
rm -rf /tmp/image-artifacts
docker image prune -f
df -h /
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Install Kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/${{ env.KIND_VERSION }}/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind version
- name: Setup E2E environment
id: setup
continue-on-error: true
run: |
chmod +x e2e/kind-setup-single.sh
KIND_RETAIN_ON_FAILURE=true SKIP_BUILD=true SKIP_PROXY=true IMAGE=breakglass:e2e UI_FLAVOUR=telekom KIND_NODE_IMAGE=${{ env.KIND_NODE_IMAGE }} ./e2e/kind-setup-single.sh
env:
SKIP_BUILD: "true"
SKIP_PROXY: "true"
IMAGE: breakglass:e2e
PRESERVE_ON_FAILURE: "true"
KIND_RETAIN_ON_FAILURE: "true"
- name: Collect setup failure diagnostics
if: steps.setup.outcome == 'failure'
run: |
DIAG_DIR="setup-failure-diagnostics"
mkdir -p "$DIAG_DIR"/{docker,kubernetes,logs}
echo "=== Setup failed, collecting diagnostics ==="
# Docker state
docker ps -a > "$DIAG_DIR/docker/containers.txt" 2>&1 || true
docker images > "$DIAG_DIR/docker/images.txt" 2>&1 || true
docker logs e2e-keycloak > "$DIAG_DIR/docker/keycloak-container.log" 2>&1 || true
# Kind clusters
kind get clusters > "$DIAG_DIR/docker/kind-clusters.txt" 2>&1 || true
# If cluster exists, get diagnostics
if kind get clusters 2>&1 | grep -q breakglass-hub; then
export KUBECONFIG="$(kind get kubeconfig-path --name breakglass-hub 2>/dev/null || echo ~/.kube/config)"
kubectl get pods -A > "$DIAG_DIR/kubernetes/all-pods.txt" 2>&1 || true
kubectl get events -A --sort-by='.lastTimestamp' > "$DIAG_DIR/kubernetes/events.txt" 2>&1 || true
kubectl describe pods -A > "$DIAG_DIR/kubernetes/pods-describe.txt" 2>&1 || true
# Get logs from any existing pods
for ns in breakglass-system kube-system cert-manager; do
for pod in $(kubectl get pods -n "$ns" -o name 2>/dev/null); do
podname=$(echo "$pod" | sed 's#pod/##')
kubectl logs -n "$ns" "$podname" --all-containers > "$DIAG_DIR/logs/${ns}-${podname}.log" 2>&1 || true
done
done
fi
# Setup script logs
cp e2e/kind-setup-single-tls/*.log "$DIAG_DIR/logs/" 2>/dev/null || true
cp e2e/kind-setup-single-tdir/*.log "$DIAG_DIR/logs/" 2>/dev/null || true
- name: Upload setup failure diagnostics
if: steps.setup.outcome == 'failure'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: single-cluster-setup-failure-logs
path: setup-failure-diagnostics/
retention-days: 14
- name: Fail if setup failed
if: steps.setup.outcome == 'failure'
run: |
echo "Setup failed. Check the setup-failure-logs artifact for details."
exit 1
- name: Wait for services to be ready
run: |
echo "Waiting for pods to be ready..."
kubectl wait --for=condition=Ready pods --all -n breakglass-system --timeout=300s || {
echo "Pods not ready, collecting diagnostics..."
kubectl get pods -A
kubectl describe pods -n breakglass-system
exit 1
}
- name: Source E2E environment
run: |
# Source the environment variables from setup script
if [ -f e2e/kind-setup-single-tdir/e2e-env.sh ]; then
echo "Sourcing E2E environment from setup script..."
source e2e/kind-setup-single-tdir/e2e-env.sh
if [ -n "${KEYCLOAK_GROUP_SYNC_CLIENT_SECRET:-}" ]; then
echo "::add-mask::${KEYCLOAK_GROUP_SYNC_CLIENT_SECRET}"
fi
# Export to GITHUB_ENV for subsequent steps
echo "E2E_TEST=true" >> "$GITHUB_ENV"
echo "E2E_NAMESPACE=${E2E_NAMESPACE}" >> "$GITHUB_ENV"
echo "E2E_CLUSTER_NAME=${E2E_CLUSTER_NAME}" >> "$GITHUB_ENV"
echo "BREAKGLASS_API_URL=${BREAKGLASS_API_URL}" >> "$GITHUB_ENV"
echo "BREAKGLASS_WEBHOOK_URL=${BREAKGLASS_WEBHOOK_URL}" >> "$GITHUB_ENV"
echo "BREAKGLASS_METRICS_URL=${BREAKGLASS_METRICS_URL}" >> "$GITHUB_ENV"
echo "KEYCLOAK_HOST=${KEYCLOAK_HOST}" >> "$GITHUB_ENV"
echo "KEYCLOAK_PORT=${KEYCLOAK_PORT}" >> "$GITHUB_ENV"
echo "KEYCLOAK_URL=${KEYCLOAK_URL:-}" >> "$GITHUB_ENV"
echo "KEYCLOAK_REALM=${KEYCLOAK_REALM}" >> "$GITHUB_ENV"
echo "KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID}" >> "$GITHUB_ENV"
echo "KEYCLOAK_ISSUER_HOST=${KEYCLOAK_ISSUER_HOST}" >> "$GITHUB_ENV"
echo "KEYCLOAK_INTERNAL_URL=${KEYCLOAK_INTERNAL_URL:-}" >> "$GITHUB_ENV"
echo "KEYCLOAK_CA_FILE=${KEYCLOAK_CA_FILE:-}" >> "$GITHUB_ENV"
echo "TLS_DIR=${TLS_DIR:-}" >> "$GITHUB_ENV"
echo "KUBERNETES_API_SERVER=${KUBERNETES_API_SERVER:-}" >> "$GITHUB_ENV"
echo "KUBECONFIG=${KUBECONFIG}" >> "$GITHUB_ENV"
echo "Environment variables set:"
env | grep -E "E2E_|BREAKGLASS_|KEYCLOAK_" | grep -v "KEYCLOAK_GROUP_SYNC_CLIENT_SECRET=" || true
else
echo "ERROR: E2E environment file not found!"
exit 1
fi
- name: Setup port-forwards for E2E tests
run: |
echo "=== Setting up port-forwards for E2E tests ==="
# Kill keepalive wrapper processes started by kind-setup-single.sh
# The setup script records wrapper PIDs in e2e/port-forward-pids
PF_FILE="e2e/port-forward-pids"
if [ -f "$PF_FILE" ]; then
echo "Terminating existing port-forward wrappers from PID file..."
while IFS= read -r pf_pid; do
if [ -n "$pf_pid" ]; then
kill "$pf_pid" 2>/dev/null || true
fi
done < "$PF_FILE"
rm -f "$PF_FILE"
fi
# Also kill any orphaned port-forward processes not tracked by the PID file
pkill -f "port-forward.*breakglass" 2>/dev/null || true
sleep 1
# Start resilient port-forwards that auto-restart on failure.
# kubectl port-forward can die due to idle timeouts, pod restarts, or
# network issues. The while-true loop ensures it restarts automatically.
# Keycloak port-forward (critical for OIDC authentication in all tests)
echo "Starting Keycloak keepalive port-forward..."
(
set +e
PF_PID=""
trap 'kill $PF_PID 2>/dev/null; exit 0' EXIT TERM INT
while true; do
kubectl -n breakglass-system port-forward svc/breakglass-keycloak 8443:8443 2>/dev/null &
PF_PID=$!
wait $PF_PID
echo "[keepalive] Keycloak port-forward exited, restarting in 2s..."
sleep 2
done
) &
echo "Keycloak keepalive PID: $!"
# API / controller port-forward
echo "Starting API keepalive port-forward..."
(
set +e
PF_PID=""
trap 'kill $PF_PID 2>/dev/null; exit 0' EXIT TERM INT
while true; do
kubectl -n breakglass-system port-forward svc/breakglass-breakglass 8080:8080 2>/dev/null &
PF_PID=$!
wait $PF_PID
echo "[keepalive] API port-forward exited, restarting in 2s..."
sleep 2
done
) &
echo "API keepalive PID: $!"
# Metrics port-forward
echo "Starting Metrics keepalive port-forward..."
(
set +e
PF_PID=""
trap 'kill $PF_PID 2>/dev/null; exit 0' EXIT TERM INT
while true; do
kubectl -n breakglass-system port-forward svc/breakglass-breakglass 8181:8081 2>/dev/null &
PF_PID=$!
wait $PF_PID
echo "[keepalive] Metrics port-forward exited, restarting in 2s..."
sleep 2
done
) &
echo "Metrics keepalive PID: $!"
# Kafka port-forward (port 9094) - needed for audit tests
echo "Starting Kafka keepalive port-forward..."
(
set +e
PF_PID=""
trap 'kill $PF_PID 2>/dev/null; exit 0' EXIT TERM INT
while true; do
kubectl -n breakglass-system port-forward svc/breakglass-kafka 9094:9094 2>/dev/null &
PF_PID=$!
wait $PF_PID
echo "[keepalive] Kafka port-forward exited, restarting in 2s..."
sleep 2
done
) &
echo "Kafka keepalive PID: $!"
# Wait for Kafka to be accessible
for i in {1..30}; do
if nc -z localhost 9094 2>/dev/null; then
echo "✓ Kafka port-forward ready"
break
fi
sleep 1
done
if ! nc -z localhost 9094 2>/dev/null; then
echo "Warning: Kafka not accessible on port 9094 (audit tests may fail)"
fi
# Audit webhook receiver port-forward (port 8090)
echo "Starting audit webhook receiver keepalive port-forward..."
(
set +e
PF_PID=""
trap 'kill $PF_PID 2>/dev/null; exit 0' EXIT TERM INT
while true; do
kubectl -n breakglass-system port-forward svc/breakglass-audit-webhook-receiver 8090:80 2>/dev/null &
PF_PID=$!
wait $PF_PID
echo "[keepalive] Audit webhook receiver port-forward exited, restarting in 2s..."
sleep 2
done
) &
echo "Audit webhook receiver keepalive PID: $!"
# Wait for audit webhook receiver to be accessible
for i in {1..30}; do
if curl -sf "http://localhost:8090/health" > /dev/null 2>&1; then
echo "✓ Audit webhook receiver port-forward ready"
break
fi
sleep 1
done
if ! curl -sf "http://localhost:8090/health" > /dev/null 2>&1; then
echo "Warning: Audit webhook receiver not accessible (tests may fail)"
fi
# MailHog port-forward (port 8025) - needed for notification e2e tests
echo "Starting MailHog keepalive port-forward..."
(
set +e
PF_PID=""
trap 'kill $PF_PID 2>/dev/null; exit 0' EXIT TERM INT
while true; do
kubectl -n breakglass-system port-forward svc/breakglass-mailhog 8025:8025 2>/dev/null &
PF_PID=$!
wait $PF_PID
echo "[keepalive] MailHog port-forward exited, restarting in 2s..."
sleep 2
done
) &
echo "MailHog keepalive PID: $!"
# Wait for MailHog to be accessible
for i in {1..30}; do
if curl -sf "http://localhost:8025/api/v2/messages" > /dev/null 2>&1; then
echo "✓ MailHog port-forward ready"
break
fi
sleep 1