Skip to content

Commit 07f9a7b

Browse files
committed
test(e2e): assert the tenant OIDC UID header on the control plane
The render matrix proves the chart emits --requestheader-uid-headers, but nothing checked that the flag survives the path a real tenant takes: aggregated API admission of spec.oidc, the HelmRelease, and the rendered KamajiControlPlane. Assert it in both OIDC helpers, next to the existing --authentication-config check on the same resource. Read the arg list once into a variable and grep the capture twice. The existing check consumed a pipeline, which is single-use, and a second kubectl call would double the management-cluster reads these helpers already make. Only the header flag is asserted. The chart also renders --feature-gates=RemoteRequestHeaderUID=true, but only on v1.32 where the gate is still alpha, while this lane takes the highest version in the map, which is above that. The header flag is the part that holds wherever the flag exists at all. The bats case for the missing flag runs the helper as a standalone subshell under set -e rather than as an if condition. Shells suppress errexit for a command whose status is being tested, and that reaches inside the subshell, so the if spelling reports success and pins nothing. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent a68418d commit 07f9a7b

2 files changed

Lines changed: 101 additions & 9 deletions

File tree

‎hack/e2e-chainsaw/_lib/run-kubernetes.sh‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ cozy_oidc_bindings() {
145145
sort
146146
}
147147

148+
cozy_assert_oidc_apiserver_flags() {
149+
local release="$1"
150+
local extra_args
151+
152+
# Captured because a pipeline is single-use: a second grep on it reads nothing.
153+
extra_args=$(kubectl -n tenant-test get kamajicontrolplane "${release}" \
154+
-o jsonpath='{.spec.apiServer.extraArgs}')
155+
printf '%s\n' "${extra_args}" |
156+
grep -qF -- '--authentication-config=/etc/kubernetes/authentication-config/config.yaml'
157+
# --feature-gates=RemoteRequestHeaderUID=true is deliberately not asserted:
158+
# the chart renders it only on v1.32, while this lane takes the highest
159+
# version in the map, which is above that.
160+
printf '%s\n' "${extra_args}" |
161+
grep -qF -- '--requestheader-uid-headers=X-Remote-Uid'
162+
}
163+
148164
cozy_assert_oidc_system() {
149165
local test_name="$1"
150166
local release="kubernetes-${test_name}"
@@ -154,9 +170,7 @@ cozy_assert_oidc_system() {
154170
kubectl -n tenant-test wait job "${release}-oidc-bootstrap" \
155171
--for=condition=complete --timeout=1m
156172

157-
kubectl -n tenant-test get kamajicontrolplane "${release}" \
158-
-o jsonpath='{.spec.apiServer.extraArgs}' |
159-
grep -qF -- '--authentication-config=/etc/kubernetes/authentication-config/config.yaml'
173+
cozy_assert_oidc_apiserver_flags "${release}"
160174

161175
authn_config=$(kubectl -n tenant-test get secret "${release}-oidc-authn-config" \
162176
-o jsonpath='{.data.config\.yaml}' | base64 -d)
@@ -206,9 +220,7 @@ cozy_switch_and_assert_oidc_custom_config() {
206220
kubectl -n tenant-test wait job "${release}-oidc-bootstrap" \
207221
--for=condition=complete --timeout=1m
208222

209-
kubectl -n tenant-test get kamajicontrolplane "${release}" \
210-
-o jsonpath='{.spec.apiServer.extraArgs}' |
211-
grep -qF -- '--authentication-config=/etc/kubernetes/authentication-config/config.yaml'
223+
cozy_assert_oidc_apiserver_flags "${release}"
212224

213225
authn_config=$(kubectl -n tenant-test get secret "${release}-oidc-authn-config" \
214226
-o jsonpath='{.data.config\.yaml}' | base64 -d)

‎hack/run-kubernetes-oidc_test.bats‎

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
case "$*" in
5757
*" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;;
5858
*" get kamajicontrolplane kubernetes-demo "*)
59-
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]'
59+
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]'
6060
;;
6161
*" get secret kubernetes-demo-oidc-authn-config "*)
6262
printf 'url: https://keycloak.example.test/realms/cozy\naudiences:\n- tenant-test-kubernetes-demo\n' | base64 | tr -d '\n'
@@ -76,6 +76,51 @@
7676
cozy_assert_oidc_system demo
7777
}
7878

79+
@test "System OIDC assertion fails when the aggregation-layer UID header is missing" {
80+
# Same mock as the passing case, minus --requestheader-uid-headers, so that
81+
# flag is the only thing left to fail on. Drop the grep for it from the helper
82+
# and this case goes red, which is what stops it passing for the wrong reason.
83+
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
84+
kubectl() {
85+
case "$*" in
86+
*" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;;
87+
*" get kamajicontrolplane kubernetes-demo "*)
88+
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]'
89+
;;
90+
*" get secret kubernetes-demo-oidc-authn-config "*)
91+
printf 'url: https://keycloak.example.test/realms/cozy\naudiences:\n- tenant-test-kubernetes-demo\n' | base64 | tr -d '\n'
92+
;;
93+
*" get keycloakclient.v1.edp.epam.com tenant-test-kubernetes-demo "*) printf 'true' ;;
94+
*" get keycloakclientscope.v1.edp.epam.com tenant-test-kubernetes-demo-audience "*) printf 'oidc-audience-mapper' ;;
95+
*" get secret kubernetes-demo-oidc-kubeconfig "*)
96+
printf 'args:\n- oidc-login\n- --oidc-client-id=tenant-test-kubernetes-demo\n' | base64 | tr -d '\n'
97+
;;
98+
*) echo "unexpected kubectl call: $*" >&2; return 1 ;;
99+
esac
100+
}
101+
cozy_oidc_bindings() {
102+
printf '[email protected]\tcluster-admin\[email protected]\tview\n'
103+
}
104+
105+
# The subshell restores `set -e`, which the chainsaw step runs the helper
106+
# under: without it a failing `grep -q` mid-function does not end the
107+
# function, and the exit status comes from the last assertion instead.
108+
#
109+
# It has to stand as its own command, not as an `if` condition. Shells
110+
# suppress errexit for a command whose status is being tested, and that
111+
# suppression reaches inside the subshell too, which is why the plain
112+
# `if ( set -e; ... )` spelling reports success here.
113+
local rc=0
114+
set +e
115+
( set -e; cozy_assert_oidc_system demo )
116+
rc=$?
117+
set -e
118+
if [ "${rc}" -eq 0 ]; then
119+
echo "the System assertion passed without --requestheader-uid-headers" >&2
120+
return 1
121+
fi
122+
}
123+
79124
@test "CustomConfig transition fails when it cannot ask whether System leftovers are gone" {
80125
# The teardown probes used `if kubectl get ... >/dev/null 2>&1`, which reads
81126
# every non-zero exit as "the object is gone" -- including an RBAC denial, a
@@ -101,7 +146,7 @@
101146
*" patch kuberneteses.apps.cozystack.io demo "*) : ;;
102147
*" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;;
103148
*" get kamajicontrolplane kubernetes-demo "*)
104-
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]'
149+
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]'
105150
;;
106151
*" get secret kubernetes-demo-oidc-authn-config "*)
107152
printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n'
@@ -123,6 +168,41 @@
123168
done
124169
}
125170

171+
@test "CustomConfig transition fails when the aggregation-layer UID header is missing" {
172+
# The System helper's twin. Same mock as the passing transition below, minus
173+
# --requestheader-uid-headers, so that flag is the only thing left to fail on.
174+
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
175+
kubectl() {
176+
case "$*" in
177+
*" get helmrelease kubernetes-demo "*) printf '7' ;;
178+
*" patch kuberneteses.apps.cozystack.io demo "*) : ;;
179+
*" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;;
180+
*" get kamajicontrolplane kubernetes-demo "*)
181+
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]'
182+
;;
183+
*" get secret kubernetes-demo-oidc-authn-config "*)
184+
printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n'
185+
;;
186+
*--ignore-not-found*) : ;;
187+
*) echo "unexpected kubectl call: $*" >&2; return 1 ;;
188+
esac
189+
}
190+
cozy_wait_helmrelease_upgrade() { :; }
191+
cozy_oidc_bindings() { printf '[email protected]\tcluster-admin\n'; }
192+
193+
# Standalone subshell, not an `if` condition: errexit is suppressed for a
194+
# command whose status is tested, and that reaches inside the subshell.
195+
local rc=0
196+
set +e
197+
( set -e; cozy_switch_and_assert_oidc_custom_config demo )
198+
rc=$?
199+
set -e
200+
if [ "${rc}" -eq 0 ]; then
201+
echo "the transition passed without --requestheader-uid-headers" >&2
202+
return 1
203+
fi
204+
}
205+
126206
@test "CustomConfig transition patches the live cluster waits for the new generation and rejects System leftovers" {
127207
. hack/e2e-chainsaw/_lib/run-kubernetes.sh
128208
calls=$(mktemp)
@@ -144,7 +224,7 @@
144224
;;
145225
*" wait job kubernetes-demo-oidc-bootstrap "*) return 0 ;;
146226
*" get kamajicontrolplane kubernetes-demo "*)
147-
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml]'
227+
printf '[--authentication-config=/etc/kubernetes/authentication-config/config.yaml --requestheader-uid-headers=X-Remote-Uid]'
148228
;;
149229
*" get secret kubernetes-demo-oidc-authn-config "*)
150230
printf 'url: https://idp.byo.example.test\naudiences:\n- cozystack-byo-demo\n' | base64 | tr -d '\n'

0 commit comments

Comments
 (0)