Background
Keycloak SSO authentication succeeds, but Grafana then rejects the login with "Login failed / User sync failed." Grafana receives a valid token and fails while creating the local user record.
Root cause: All GTAC LDAP users share one email address. Keycloak allows duplicate emails; Grafana requires them to be unique. The first account claims that email, and every SSO user after that fails to be created.
Also found: login_attribute_path = username doesn't match Keycloak's actual claim (preferred_username), so Grafana falls back to email as the username too.
We have no access to the GTAC LDAP interface, so the fix is limited to Keycloak and Grafana config. No LDAP or Keycloak email addresses change.
Environment: Grafana 10.4.11.13 | Keycloak 10.4.11.12:8444, realm databridge-web-service, client grafana | Generic OAuth
Reproduce: Authenticate to Keycloak → open Grafana → click "Sign in with DataBridge SSO" → "User sync failed."
Grafana Logs
logger=user.sync level=error msg="Failed to create user" error="user not found" auth_module=oauth_generic_oauth auth_id=d2755c01-8d70-4300-bec9-e6742798
logger=authn.service level=error msg="Failed to run post auth hook" client=auth.client.generic_oauth error="[user.sync.internal] unable to create user: user not found""User not found" is misleading — Grafana is trying to create the user, and the create fails on the duplicate email.
Acceptance Criteria
- Two different Keycloak users log in via SSO back to back, and both reach the Grafana home page.
- Each has a separate Grafana account with a unique email, and a username matching their Keycloak
preferred_username. - No
Failed to create userorpost auth hookerrors ingrafana.logduring login. - Each user gets the correct role (Admin/Editor/Viewer), and at least one SSO user is Admin.
- No emails changed in GTAC LDAP or Keycloak; the unique value exists only in Grafana's user table.
- The Keycloak
emailscope change affects thegrafanaclient only. - Rollback verified (restore
grafana.ini+grafana.db, revert the Keycloak scope). - After 1–7 pass, SSO-only login is enabled and both login and sign-out succeed.
Comments
Post a Comment