SSO loop on 1.12.x with Keycloak: confidential client 401 on /users/loggedInUser, public client forces implicit flow
Summary
After upgrading from OM 1.5.0 → 1.12.6 (and 1.12.7), Keycloak SSO breaks: the user gets stuck in a /signin redirect loop. The same Keycloak realm + same oidcConfiguration + same principalDomain + same admin user work end-to-end on 1.5.0 but fail on 1.12.x in two distinct ways depending on clientType.
This is on a single-tenant Keycloak 22.0.5 (Bitnami chart) with PKCE-capable openmetadata-client in a separate realm. OM and Keycloak share a self-signed CA via cert-manager; both reachable on https://*.dev.local:8443 from the browser.
Environment
| Component | Version |
|---|---|
| OpenMetadata server | 1.12.6 (also reproduced on 1.12.7) |
| Helm chart | open-metadata/openmetadata 1.12.6 |
| Keycloak | 22.0.5 (Bitnami) |
| Browser | Chrome 147 (also Firefox 122, both default + incognito) |
| Cluster | k3s 1.31 (k3d), 3 nodes |
| DB | Postgres 16 |
Reproduction
Case A — clientType: confidential (recommended path)
values.yaml (relevant slice):
openmetadata:
config:
authentication:
clientType: confidential
provider: custom-oidc
authority: https://keycloak.dev.local:8443/realms/uwv
clientId: openmetadata
callbackUrl: https://openmetadata.dev.local:8443/callback
responseType: code
jwtPrincipalClaims: [preferred_username, email, sub]
enableSelfSignup: true # also tried false
publicKeys:
- http://openmetadata.uwv-meta.svc.cluster.local:8585/api/v1/system/config/jwks
- https://keycloak.dev.local:8443/realms/uwv/protocol/openid-connect/certs
oidcConfiguration:
enabled: true
oidcType: Keycloak
clientId: {secretRef: openmetadata-oidc-client, secretKey: clientId}
clientSecret: {secretRef: openmetadata-oidc-client, secretKey: clientSecret}
discoveryUri: https://keycloak.dev.local:8443/realms/uwv/.well-known/openid-configuration
scope: openid email profile
responseType: code
callbackUrl: https://openmetadata.dev.local:8443/callback
serverUrl: https://openmetadata.dev.local:8443
useNonce: true
clientAuthenticationMethod: client_secret_post
customParams: "{}"
Keycloak client openmetadata:
publicClient: false(confidential)standardFlowEnabled: true,implicitFlowEnabled: false- redirect URI:
https://openmetadata.dev.local:8443/* - attributes:
access.token.lifespan=86400,use.refresh.tokens=true
Steps:
- Fresh incognito →
https://openmetadata.dev.local:8443/ - Click Sign in with SSO
- Keycloak login succeeds; redirect back via
/callback?state=…&code=…(logged: 302 fromAuthenticationCodeFlowHandler, user-entity updated withauthenticationMechanism) - Browser arrives at
/auth/callback?id_token=<jwt>&email=…&name=… - SPA calls
GET /api/v1/users/loggedInUser?fields=… - Response:
401 {"code":401,"message":"Not Authorized! Token not present"} - SPA redirects to
/signin→ loop
Critical observation: replaying step 5 manually with curl -H "Authorization: Bearer <the same id_token>" returns 200 OK with the full platform.admin user record (isAdmin: true). So the JwtFilter accepts the token — the SPA simply does not attach it as Authorization header.
Pod logs at /callback:
INFO ... AuthenticationCodeFlowHandler - ...
INFO ... EntityRepository - storeUpdate: ... fieldsAdded=[authenticationMechanism]
INFO ... EntityRepository - Updated user:…:"platform.admin"
No error, no warning. The server-side flow succeeds; the SPA never picks up the token.
Case B — clientType: public (workaround attempt)
Switch clientType: public and Keycloak client publicClient: true + PKCE S256. Restart OM, fresh DB write of auth config.
Steps:
- Fresh incognito →
https://openmetadata.dev.local:8443/ - Click Sign in with SSO
- SPA constructs Keycloak auth URL with
response_type=id_token(implicit flow) - Keycloak rejects:
Client is not allowed to initiate browser login with given response_type. Implicit flow is disabled for the client.
Enabling implicitFlowEnabled: true on the Keycloak client to unblock:
5. Step 3 succeeds, Keycloak login completes, redirect to /callback#id_token=…
6. SPA error: No matching state found in storage
Hard-refreshing DB to responseType: code and Keycloak with PKCE enforce did not change SPA behaviour: it still emits response_type=id_token. Inspecting the DOM, the auth-button click handler builds the URL from system/config/auth but ignores responseType.
Expected
clientType: confidential should produce a working flow where the SPA either:
- attaches the access token (in addition to the id_token already in the URL) as
Authorization: Beareron every/api/v1/*call, OR - relies on the JSESSIONID cookie + a server-side
JwtFilter.fromCookie()path
Either way, /api/v1/users/loggedInUser should succeed in step 5 after a successful /callback.
Workarounds tried (all failed)
| Variant | Result |
|---|---|
clientType: confidential, responseType: code, enableSelfSignup: false |
401 loop |
clientType: confidential, responseType: code, enableSelfSignup: true |
401 loop |
clientType: public, responseType: code, PKCE S256, publicClient: true |
SPA still emits response_type=id_token |
clientType: public, responseType: id_token, implicit flow ON |
"No matching state found in storage" |
Patching DB row in openmetadata_settings directly |
Server overwrites at startup from env-vars |
Force-secure cookies (FORCE_SECURE_SESSION_COOKIE=true) |
No effect |
useRolesFromProvider: true |
No effect |
Pre-creating platform.admin user in OM with isAdmin: true |
No effect (still 401) |
Why this is severe
- 1.5.0 with the same Keycloak realm worked. We had to pin back to 1.5.0 to keep the demo cluster usable.
- Documentation pages for
custom-oidc+ Keycloak still describe the 1.5-style confidential client flow. - No path through values.yaml gets the SPA to attach a Bearer header on
confidential.
Happy to provide additional logs / HAR exports / a minimal reproducer chart values diff.