|
| 1 | +# Chainsaw port of hack/e2e-apps/kubernetes-oidc-system.bats. |
| 2 | +# |
| 3 | +# Phase-1 OIDC System-mode e2e — render-side only. Pairs with the |
| 4 | +# kubernetes-oidc-customconfig suite (BYO issuer path). |
| 5 | +# |
| 6 | +# Does NOT spin up a full Kamaji control plane: that path is covered by the |
| 7 | +# kubernetes-latest/previous suites and would add another ~25 min bringup for |
| 8 | +# a feature whose end-to-end OIDC browser flow is explicitly out of scope |
| 9 | +# (see docs/oidc-tenant.md -> Phase 1). minReplicas: 0 means no worker VMs; |
| 10 | +# the suite runs in minutes. Accordingly the HR is only asserted to EXIST |
| 11 | +# (cozystack-api materialised it), never Ready. |
| 12 | +# |
| 13 | +# What is exercised on a live cluster: the new spec.oidc.* fields are |
| 14 | +# admitted by the aggregated API; the HelmRelease renders the OIDC templates; |
| 15 | +# and the resulting KamajiControlPlane / AuthenticationConfiguration Secret / |
| 16 | +# KeycloakClient / KeycloakClientScope carry the expected per-cluster shape. |
| 17 | +# The Keycloak asserts are unconditional: the chart capability-gates their |
| 18 | +# rendering on v1.edp.epam.com/v1 (oidc-keycloak.yaml), and the CI platform |
| 19 | +# always ships the operator — the bats' api-resources guard was dead code |
| 20 | +# there (and its `skip` did not exist under cozytest anyway). |
| 21 | +# |
| 22 | +# The Kubernetes CR is applied declaratively, so Chainsaw auto-cleanup |
| 23 | +# deletes it at test end — the bats' hand-rolled cleanup_kr/cozy_cleanup |
| 24 | +# hooks have no equivalent here by construction. |
| 25 | +apiVersion: chainsaw.kyverno.io/v1alpha1 |
| 26 | +kind: Test |
| 27 | +metadata: |
| 28 | + name: kubernetes-oidc-system |
| 29 | +spec: |
| 30 | + catch: |
| 31 | + - events: {} |
| 32 | + - describe: |
| 33 | + apiVersion: helm.toolkit.fluxcd.io/v2 |
| 34 | + kind: HelmRelease |
| 35 | + name: kubernetes-oidc-system |
| 36 | + - describe: |
| 37 | + apiVersion: controlplane.cluster.x-k8s.io/v1alpha1 |
| 38 | + kind: KamajiControlPlane |
| 39 | + name: kubernetes-oidc-system |
| 40 | + steps: |
| 41 | + - name: create-kubernetes-oidc-system |
| 42 | + try: |
| 43 | + - apply: |
| 44 | + file: kubernetes-oidc-system.yaml |
| 45 | + # cozystack-api materialises the HelmRelease… |
| 46 | + - assert: |
| 47 | + timeout: 1m |
| 48 | + resource: |
| 49 | + apiVersion: helm.toolkit.fluxcd.io/v2 |
| 50 | + kind: HelmRelease |
| 51 | + metadata: |
| 52 | + name: kubernetes-oidc-system |
| 53 | + # …and the chart renders the KamajiControlPlane (no Ready wait — that |
| 54 | + # would require the Kamaji bringup this suite deliberately avoids). |
| 55 | + - assert: |
| 56 | + timeout: 3m |
| 57 | + resource: |
| 58 | + apiVersion: controlplane.cluster.x-k8s.io/v1alpha1 |
| 59 | + kind: KamajiControlPlane |
| 60 | + metadata: |
| 61 | + name: kubernetes-oidc-system |
| 62 | + |
| 63 | + - name: kamajicontrolplane-oidc-wiring |
| 64 | + try: |
| 65 | + - assert: |
| 66 | + resource: |
| 67 | + apiVersion: controlplane.cluster.x-k8s.io/v1alpha1 |
| 68 | + kind: KamajiControlPlane |
| 69 | + metadata: |
| 70 | + name: kubernetes-oidc-system |
| 71 | + spec: |
| 72 | + apiServer: |
| 73 | + # --authentication-config is appended to extraArgs; the |
| 74 | + # chart-owned mount lands on extraVolumeMounts. |
| 75 | + (contains(extraArgs, '--authentication-config=/etc/kubernetes/authentication-config/config.yaml')): true |
| 76 | + (extraVolumeMounts[?name == 'authentication-config']): |
| 77 | + - name: authentication-config |
| 78 | + deployment: |
| 79 | + # The chart-owned volume lands on extraVolumes. |
| 80 | + (extraVolumes[?name == 'authentication-config']): |
| 81 | + - name: authentication-config |
| 82 | + |
| 83 | + - name: authn-config-secret |
| 84 | + try: |
| 85 | + - assert: |
| 86 | + timeout: 1m |
| 87 | + resource: |
| 88 | + apiVersion: v1 |
| 89 | + kind: Secret |
| 90 | + metadata: |
| 91 | + name: kubernetes-oidc-system-oidc-authn-config |
| 92 | + # The issuer check is a regex (any keycloak.<host>), so it stays a script; |
| 93 | + # the per-cluster audience literal rides along. |
| 94 | + - script: |
| 95 | + content: | |
| 96 | + set -eu |
| 97 | + body=$(kubectl -n "$NAMESPACE" get secret kubernetes-oidc-system-oidc-authn-config \ |
| 98 | + -o jsonpath='{.data.config\.yaml}' | base64 -d) |
| 99 | + echo "$body" | grep -qE 'url: https://keycloak\.[^/]+/realms/cozy' |
| 100 | + echo "$body" | grep -qF -- "- tenant-test-kubernetes-oidc-system" |
| 101 | + check: |
| 102 | + ($error == null): true |
| 103 | + |
| 104 | + - name: keycloak-objects-in-cozy-realm |
| 105 | + try: |
| 106 | + - assert: |
| 107 | + timeout: 1m |
| 108 | + resource: |
| 109 | + apiVersion: v1.edp.epam.com/v1 |
| 110 | + kind: KeycloakClient |
| 111 | + metadata: |
| 112 | + name: tenant-test-kubernetes-oidc-system |
| 113 | + spec: |
| 114 | + public: true |
| 115 | + - assert: |
| 116 | + timeout: 1m |
| 117 | + resource: |
| 118 | + apiVersion: v1.edp.epam.com/v1 |
| 119 | + kind: KeycloakClientScope |
| 120 | + metadata: |
| 121 | + name: tenant-test-kubernetes-oidc-system-audience |
| 122 | + spec: |
| 123 | + (protocolMappers[0].protocolMapper): oidc-audience-mapper |
0 commit comments