From 5596d7c7ac50ee8d3ad24428daed971cd17ccb9d Mon Sep 17 00:00:00 2001 From: Akram Date: Mon, 4 May 2026 15:59:17 +0200 Subject: [PATCH] fix: use plain strings for Keycloak client attributes in update payload mergeDesiredClientIntoMap was wrapping attribute values in []interface{} arrays (e.g. ["false"] instead of "false"), causing Keycloak Admin API to reject the PUT request with 400 "Cannot parse the JSON". Keycloak expects attribute values as plain strings, not arrays. This caused operator-managed client registration to fail for all workloads when the client already existed in Keycloak and needed an update. Signed-off-by: Akram Ben Aissi Assisted-By: Claude (Anthropic AI) Signed-off-by: Akram --- kagenti-operator/internal/keycloak/admin.go | 2 +- kagenti-operator/internal/keycloak/admin_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kagenti-operator/internal/keycloak/admin.go b/kagenti-operator/internal/keycloak/admin.go index 0fe902f3..ade60d1a 100644 --- a/kagenti-operator/internal/keycloak/admin.go +++ b/kagenti-operator/internal/keycloak/admin.go @@ -411,7 +411,7 @@ func mergeDesiredClientIntoMap(m map[string]interface{}, desired *keycloakClient m["attributes"] = attrs } for k, v := range desired.Attributes { - attrs[k] = []interface{}{v} + attrs[k] = v } } diff --git a/kagenti-operator/internal/keycloak/admin_test.go b/kagenti-operator/internal/keycloak/admin_test.go index 66450131..df07172b 100644 --- a/kagenti-operator/internal/keycloak/admin_test.go +++ b/kagenti-operator/internal/keycloak/admin_test.go @@ -105,8 +105,8 @@ func TestAdmin_RegisterOrFetchClient_updatesDrift(t *testing.T) { if attrs == nil { t.Fatal("expected attributes in PUT body") } - ex, _ := attrs["standard.token.exchange.enabled"].([]interface{}) - if len(ex) != 1 || ex[0] != "true" { + ex, _ := attrs["standard.token.exchange.enabled"].(string) + if ex != "true" { t.Fatalf("expected token exchange true in PUT, got %#v", attrs["standard.token.exchange.enabled"]) } w.WriteHeader(http.StatusNoContent)