Skip to content

Commit 2e4b610

Browse files
committed
fix(kubernetes): name the configured realm in the OIDC denial message
The claimValidationRules message in the System-mode AuthenticationConfiguration hardcoded "in the cozy realm", so on a renamed realm it told a rejected user to look in a realm that no longer exists. Build it from the same realm the issuer uses (toString-guarded, as the derived issuer URL already is). Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent f43bd53 commit 2e4b610

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
{{- $issuer := include "kubernetes.oidc.systemIssuerURL" . | trim }}
3232
{{- $audience := include "kubernetes.oidc.clientId" . | trim }}
3333
{{- $groupsExpr := include "kubernetes.oidc.groupsClaimValidationExpr" . | trim }}
34+
{{- $realm := dig "oidc-realm-name" "cozy" (.Values._cluster | default dict) | toString }}
3435
{{- /*
3536
User identity claim: `email`, not `preferred_username`.
3637

@@ -59,7 +60,7 @@ chart) to be present in the token's `groups` claim. Symmetric with the
5960
Grafana-side `allowed_groups` gate in the Monitoring chart — see
6061
docs/oidc-tenant.md and docs/oidc-grafana.md.
6162
*/ -}}
62-
{{- $authnConfig := printf "apiVersion: apiserver.config.k8s.io/v1beta1\nkind: AuthenticationConfiguration\njwt:\n- issuer:\n url: %s\n audiences:\n - %s\n claimValidationRules:\n - expression: '%s'\n message: \"user is not a member of any %s-{view,use,admin,super-admin} group in the cozy realm — this tenant's apiserver only trusts identities the tenant chart has admitted\"\n claimMappings:\n username:\n claim: email\n prefix: \"\"\n groups:\n claim: groups\n prefix: \"\"\n" $issuer $audience $groupsExpr .Release.Namespace }}
63+
{{- $authnConfig := printf "apiVersion: apiserver.config.k8s.io/v1beta1\nkind: AuthenticationConfiguration\njwt:\n- issuer:\n url: %s\n audiences:\n - %s\n claimValidationRules:\n - expression: '%s'\n message: \"user is not a member of any %s-{view,use,admin,super-admin} group in the %s realm — this tenant's apiserver only trusts identities the tenant chart has admitted\"\n claimMappings:\n username:\n claim: email\n prefix: \"\"\n groups:\n claim: groups\n prefix: \"\"\n" $issuer $audience $groupsExpr .Release.Namespace $realm }}
6364
---
6465
apiVersion: v1
6566
kind: Secret

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,11 @@ tests:
592592
- notMatchRegex:
593593
path: stringData["config.yaml"]
594594
pattern: "/realms/cozy"
595+
# The claimValidationRules denial message names the realm; on a renamed
596+
# realm it must not keep telling the user to look in "cozy".
597+
- matchRegex:
598+
path: stringData["config.yaml"]
599+
pattern: "group in the acme realm"
600+
- notMatchRegex:
601+
path: stringData["config.yaml"]
602+
pattern: "group in the cozy realm"

0 commit comments

Comments
 (0)