Skip to content

Commit cac07db

Browse files
test(kubernetes): port the Phase-1 OIDC render-side suites to Chainsaw
Main added kubernetes-oidc-system.bats and kubernetes-oidc-customconfig.bats after the Chainsaw migration branch was cut; without a port the 260 lines of coverage would vanish with the hack/e2e-apps/ deletion. Both are light cluster e2e (apply CR -> assert rendered objects; no Kamaji bringup, minReplicas: 0), exactly Chainsaw's declarative shape: - System mode: KamajiControlPlane carries --authentication-config + the chart-owned volume/mount; the AuthenticationConfiguration Secret carries the cozy-realm issuer (regex, script step) + per-cluster audience; per-cluster KeycloakClient/KeycloakClientScope land in the cozy realm - CustomConfig: the flag is still wired; the Secret carries the tenant-supplied issuer and NOT the cozy realm (fail-loud negation); no Keycloak objects and no pre-rendered OIDC kubeconfig Secret, expressed as error ops ordered after the positive asserts so an unreconciled HR cannot false-pass them The port also sheds two latent bats bugs: cozytest defines no skip() (the Keycloak guard would have died with exit 127 had it ever fired) and the api-resources group probe exits 0 even when the group is absent — the chart capability-gates Keycloak rendering and CI always ships the operator, so the asserts are unconditional here. Assisted-By: Claude <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 6c76a46 commit cac07db

4 files changed

Lines changed: 322 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Chainsaw port of hack/e2e-apps/kubernetes-oidc-customconfig.bats.
2+
#
3+
# Phase-1 OIDC CustomConfig selector e2e — render-side only. Pairs with the
4+
# kubernetes-oidc-system suite; see its header for why no Kamaji bringup and
5+
# no HR Ready wait (minReplicas: 0, HR asserted to exist only).
6+
#
7+
# What is exercised on a live cluster: spec.oidc.mode: CustomConfig is
8+
# admitted; the HelmRelease renders; the tenant-supplied
9+
# AuthenticationConfiguration is wired onto the KamajiControlPlane; and —
10+
# crucially — NO Keycloak objects are created in the cozy realm when the
11+
# tenant brings their own issuer, and the placeholder OIDC kubeconfig Secret
12+
# is NOT pre-rendered (System mode pre-renders it; CustomConfig distributes
13+
# out-of-band).
14+
#
15+
# The absence checks run AFTER the positive authn-config Secret assert
16+
# establishes the chart has finished rendering — otherwise a not-yet-
17+
# reconciled HR would false-pass them, a hazard the sequential bats never had.
18+
apiVersion: chainsaw.kyverno.io/v1alpha1
19+
kind: Test
20+
metadata:
21+
name: kubernetes-oidc-customconfig
22+
spec:
23+
catch:
24+
- events: {}
25+
- describe:
26+
apiVersion: helm.toolkit.fluxcd.io/v2
27+
kind: HelmRelease
28+
name: kubernetes-oidc-byo
29+
- describe:
30+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha1
31+
kind: KamajiControlPlane
32+
name: kubernetes-oidc-byo
33+
steps:
34+
- name: create-kubernetes-oidc-byo
35+
try:
36+
- apply:
37+
file: kubernetes-oidc-byo.yaml
38+
- assert:
39+
timeout: 1m
40+
resource:
41+
apiVersion: helm.toolkit.fluxcd.io/v2
42+
kind: HelmRelease
43+
metadata:
44+
name: kubernetes-oidc-byo
45+
- assert:
46+
timeout: 3m
47+
resource:
48+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha1
49+
kind: KamajiControlPlane
50+
metadata:
51+
name: kubernetes-oidc-byo
52+
53+
- name: kamajicontrolplane-still-carries-authentication-config
54+
try:
55+
- assert:
56+
resource:
57+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha1
58+
kind: KamajiControlPlane
59+
metadata:
60+
name: kubernetes-oidc-byo
61+
spec:
62+
apiServer:
63+
(contains(extraArgs, '--authentication-config=/etc/kubernetes/authentication-config/config.yaml')): true
64+
65+
- name: authn-config-secret-carries-tenant-issuer
66+
try:
67+
- assert:
68+
timeout: 1m
69+
resource:
70+
apiVersion: v1
71+
kind: Secret
72+
metadata:
73+
name: kubernetes-oidc-byo-oidc-authn-config
74+
- script:
75+
content: |
76+
set -eu
77+
body=$(kubectl -n "$NAMESPACE" get secret kubernetes-oidc-byo-oidc-authn-config \
78+
-o jsonpath='{.data.config\.yaml}' | base64 -d)
79+
echo "$body" | grep -qF "url: https://idp.byo.example.test"
80+
echo "$body" | grep -qF "cozystack-byo-oidc-byo"
81+
# Fail-loud negation (a bare `! ... | grep` is vacuous under set -e):
82+
# the cozy-realm issuer must NOT appear in a BYO config.
83+
if echo "$body" | grep -qE 'url: https://keycloak\.[^/]+/realms/cozy'; then
84+
echo "FAIL: BYO AuthenticationConfiguration must not carry the cozy realm issuer" >&2
85+
exit 1
86+
fi
87+
check:
88+
($error == null): true
89+
90+
# Absence proofs — ordered after the positive asserts above (chart has
91+
# rendered), so `error` op polling to its timeout is a real negative, not a
92+
# not-yet-reconciled false pass.
93+
- name: no-keycloak-objects-and-no-prerendered-kubeconfig
94+
try:
95+
- error:
96+
timeout: 30s
97+
resource:
98+
apiVersion: v1.edp.epam.com/v1
99+
kind: KeycloakClient
100+
metadata:
101+
name: tenant-test-kubernetes-oidc-byo
102+
- error:
103+
timeout: 30s
104+
resource:
105+
apiVersion: v1.edp.epam.com/v1
106+
kind: KeycloakClientScope
107+
metadata:
108+
name: tenant-test-kubernetes-oidc-byo-audience
109+
# System mode pre-renders <release>-oidc-kubeconfig as a placeholder;
110+
# CustomConfig must not.
111+
- error:
112+
timeout: 30s
113+
resource:
114+
apiVersion: v1
115+
kind: Secret
116+
metadata:
117+
name: kubernetes-oidc-byo-oidc-kubeconfig
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: apps.cozystack.io/v1alpha1
2+
kind: Kubernetes
3+
metadata:
4+
name: oidc-byo
5+
spec:
6+
addons:
7+
ingressNginx:
8+
enabled: false
9+
hosts: []
10+
valuesOverride: {}
11+
controlPlane:
12+
apiServer:
13+
resources: {}
14+
resourcesPreset: small
15+
replicas: 1
16+
nodeGroups:
17+
md0:
18+
diskSize: 20Gi
19+
gpus: []
20+
instanceType: u1.micro
21+
maxReplicas: 1
22+
minReplicas: 0
23+
resources: {}
24+
roles:
25+
- worker
26+
storageClass: replicated
27+
version: v1.35
28+
oidc:
29+
mode: CustomConfig
30+
customConfig:
31+
config: |
32+
apiVersion: apiserver.config.k8s.io/v1beta1
33+
kind: AuthenticationConfiguration
34+
jwt:
35+
- issuer:
36+
url: https://idp.byo.example.test
37+
audiences:
38+
- cozystack-byo-oidc-byo
39+
claimMappings:
40+
username:
41+
claim: preferred_username
42+
prefix: ""
43+
groups:
44+
claim: groups
45+
prefix: ""
46+
users:
47+
48+
role: admin
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: apps.cozystack.io/v1alpha1
2+
kind: Kubernetes
3+
metadata:
4+
name: oidc-system
5+
spec:
6+
addons:
7+
ingressNginx:
8+
enabled: false
9+
hosts: []
10+
valuesOverride: {}
11+
controlPlane:
12+
apiServer:
13+
resources: {}
14+
resourcesPreset: small
15+
replicas: 1
16+
nodeGroups:
17+
md0:
18+
diskSize: 20Gi
19+
gpus: []
20+
instanceType: u1.micro
21+
maxReplicas: 1
22+
minReplicas: 0
23+
resources: {}
24+
roles:
25+
- worker
26+
storageClass: replicated
27+
version: v1.35
28+
oidc:
29+
mode: System
30+
users:
31+
32+
role: admin
33+
34+
role: view

0 commit comments

Comments
 (0)