Connect Grafana to Keycloak
Map Keycloak identities into Grafana with explicit organization roles, strict claim handling, datasource boundaries and a recoverable administrator path.
Last updated
In short
- Organization administrator and Grafana server administrator are different privileges.
- Strict role mapping can prevent unintended fallback access.
- Dashboard visibility does not replace datasource authorization.
On this page (7)
Integrations · Part of Grafana
Define the privileges before connecting the provider
Grafana can authenticate through Keycloak using its Generic OAuth integration. The useful design question is which organization, role and data access each authenticated person should receive. A successful SSO exchange does not establish that a viewer cannot reach a sensitive datasource or that an organization administrator should administer the whole Grafana server.
This is a documented reference procedure, not a tested configuration. Use the current Keycloak integration guide and Generic OAuth reference for the Grafana release and edition being deployed.
Record the client and role contract
| Configuration item | Design choice | Acceptance evidence |
|---|---|---|
| Public Grafana URL | Correct external root URL behind the proxy | Callback returns to intended HTTPS hostname |
| Keycloak client | Dedicated confidential client | Exact callback and protected credential |
| Identity claim | Stable user identity plus required profile fields | Rename does not create duplicate account |
| Organization role | Viewer, Editor or Admin under explicit rules | Synthetic users receive expected role |
| Server administrator | Separate exceptional mapping | Ordinary organization admin lacks server privileges |
| Missing role | Deny or deliberate limited fallback | Unknown claim does not grant unintended access |
Use a small role vocabulary such as monitoring-viewer and monitoring-editor. Map only the claims required by Grafana. If a claim contains nested arrays or objects, validate the actual expression against a synthetic token rather than assuming it matches the example documentation.
The Generic OAuth reference documents role_attribute_path and role_attribute_strict. Strict mode can deny login when an acceptable role cannot be extracted instead of using the default organization role. It also explains that combined organization and role mappings can result in the higher mapped privilege. Review the complete effective mapping rather than testing each expression in isolation.
Separate edition-dependent features
Basic OAuth authentication, organization role mapping, team synchronization, fine-grained permissions and datasource permissions are distinct capabilities. Check the selected Grafana edition and current feature documentation before promising automated team lifecycle or a particular permission model.
Record the exact Grafana and Keycloak releases, deployment method and any commercial entitlement. Do not infer that a feature visible in a cloud tutorial exists in the same form in an open-source self-hosted installation. The configuration record should identify which mechanism owns each permission: identity claim, Grafana role, team membership, folder permission or datasource access policy.
Configure in a recoverable order
Create the Keycloak client and exact redirect URI first. Configure Grafana’s external root URL and OAuth endpoints or supported discovery values. Store the client secret in the deployment’s secret mechanism. Confirm that Grafana can reach the token and user-information endpoints and that the browser can reach the authorization endpoint.
Enable the provider for a limited pilot without immediately removing the existing administrator login. Verify the effective configuration after restart or provisioning. Then test account linking if users already signed in through a different provider with the same email address; the Keycloak guide explicitly calls out that case.
Automatic login redirection is a usability choice to introduce after recovery access and account mapping are proven. Keep the recovery path controlled, documented and observable rather than leaving a general bypass available to every user.
Test what the user can query
Create a harmless dashboard backed by synthetic metrics and a second restricted datasource or folder. Use separate accounts for viewer, editor, organization administrator and unassigned user.
| Test | Required result |
|---|---|
| Viewer opens approved dashboard | Can view intended data without editing it |
| Viewer explores other query paths | Cannot reach data outside the approved boundary |
| Editor changes a panel | Can edit only the intended scope |
| Organization admin opens server settings | Does not gain server administration accidentally |
| Unassigned user signs in | Rejected or receives only the explicitly approved fallback |
| Role claim is absent or malformed | Safe, documented behavior |
A dashboard hiding a field is not a database security control. Consider Explore, direct datasource queries, exports, alert rules and shared dashboards when defining the boundary. Where a datasource uses a shared database credential, that credential’s permissions are part of every permitted user’s effective access.
Measure role changes and credential revocation
Remove the viewer role while the user has an active session. Test the current tab, a new login and any API credential separately. Observe when Grafana synchronizes roles and whether manually assigned memberships survive. Record the behavior expected by the offboarding process.
Service accounts and alerting integrations may intentionally outlive a human browser session. Assign them named operational owners and scoped permissions. Do not delete or rotate them blindly during an employee departure if that would disable monitoring, but ensure the departing person no longer controls them.
Back up and rerun the acceptance matrix
Preserve Grafana’s database, provisioning files, dashboards, datasource configuration and the secrets required to restore encrypted settings. Keep Keycloak’s client configuration under its own recovery process. Restore into a restricted environment so alerting does not send duplicate incident notifications.
For rollback, retain the previous authentication configuration and verified recovery administrator access. Inspect accounts created during the pilot before removing them. After a Grafana upgrade or a Keycloak claim change, rerun all role and datasource checks. Accept the integration only when the intended users can operate the required dashboards and the negative cases demonstrate that higher privileges remain unavailable.
Sources and further reading
Use the linked documentation to confirm the version, edition and contract that apply to your project.
