Skip to content

Commit de0299f

Browse files
committed
fix(apps/kubernetes): switch AuthenticationConfiguration username claim to email
Real bug caught by an end-to-end OIDC login test on dev3: apiserver accepts the JWT (auth succeeds) but the RBAC check fails with 403 because the CRB `User:` subject was `[email protected]` (from `users[].email`) but the apiserver-visible identity was `alice-oidc` (from `preferred_username`, which in the cozy realm is the Keycloak *username*, not the email). The design proposal example used `claim: preferred_username`, but the operator-facing `users[].email` field explicitly asks for the email address. In the cozy realm — verified — `preferred_username` is the Keycloak username (`kvaps`, `i.okhotnikov`), so the two do NOT coincide. Every user whose Keycloak username differs from their email would silently 403 after a successful OIDC handshake. Switch the AuthenticationConfiguration `claimMappings.username.claim` to `email`, aligning the apiserver-visible identity with the operator-declared `users[].email`. Every conformant OIDC provider emits `email` — cozy realm does (verified), and any BYO `CustomConfig` issuer that follows OIDC does too. The switch is invisible to installers where `preferred_username` already equals the email (a common Keycloak setup); for installers where it doesn't, this fix is required for RBAC to work at all. Signed-off-by: Ivan Okhotnikov <[email protected]>
1 parent af0b7b5 commit de0299f

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎packages/apps/kubernetes/templates/oidc-authn-config.yaml‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,24 @@
2929
{{- if eq .Values.oidc.mode "System" }}
3030
{{- $issuer := include "kubernetes.oidc.systemIssuerURL" . | trim }}
3131
{{- $audience := include "kubernetes.oidc.clientId" . | trim }}
32-
{{- $authnConfig := printf "apiVersion: apiserver.config.k8s.io/v1beta1\nkind: AuthenticationConfiguration\njwt:\n- issuer:\n url: %s\n audiences:\n - %s\n claimMappings:\n username:\n claim: preferred_username\n prefix: \"\"\n groups:\n claim: groups\n prefix: \"\"\n" $issuer $audience }}
32+
{{- /*
33+
User identity claim: `email`, not `preferred_username`.
34+
35+
The design doc example used `claim: preferred_username`, but in the
36+
cozystack `cozy` realm `preferred_username` is the Keycloak *username*
37+
(`kvaps`, `i.okhotnikov`), NOT the email — and the operator-facing
38+
`users[].email` field asks for the email address. Matching the `User:`
39+
subject in the ClusterRoleBinding to `preferred_username` would
40+
silently misidentify every user whose Keycloak username differs from
41+
their email — verified on dev3 where token auth succeeded but the CRB
42+
match failed with 403.
43+
44+
Switching the claim to `email` aligns the apiserver-visible identity
45+
with the operator's declared `users[].email` value. Requires the
46+
issuer to emit `email` — cozy realm (verified) and every conformant
47+
OIDC provider do.
48+
*/ -}}
49+
{{- $authnConfig := printf "apiVersion: apiserver.config.k8s.io/v1beta1\nkind: AuthenticationConfiguration\njwt:\n- issuer:\n url: %s\n audiences:\n - %s\n claimMappings:\n username:\n claim: email\n prefix: \"\"\n groups:\n claim: groups\n prefix: \"\"\n" $issuer $audience }}
3350
---
3451
apiVersion: v1
3552
kind: Secret

‎packages/apps/kubernetes/tests/oidc_test.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ tests:
253253
- matchRegex:
254254
path: stringData["config.yaml"]
255255
pattern: "url: https://keycloak.example.org/realms/cozy"
256+
# Verified end-to-end on dev3: cozy realm's preferred_username is the
257+
# Keycloak *username* (not the email), so a CRB subject sourced from
258+
# users[].email would silently mis-authenticate. Lock the claim name.
259+
- matchRegex:
260+
path: stringData["config.yaml"]
261+
pattern: "claim: email"
256262
- matchRegex:
257263
path: stringData["config.yaml"]
258264
pattern: "- tenant-foo-kubernetes-app"

0 commit comments

Comments
 (0)