Grafana
Grafana signs users in through its generic OAuth provider, with OkYouIn as the OpenID Connect provider. Users click Sign in with OkYouIn, enter their password and second factor on OkYouIn’s sign-in page, and land in Grafana with a role. How OkYouIn’s OIDC provider works in general is described in OpenID Connect.
Verified on
Section titled “Verified on”| Product | Version | Modes | What was verified |
|---|---|---|---|
Grafana OSS (Docker image grafana/grafana) | 13.3.0 | password + MFA | Generic OAuth with PKCE; first sign-in with TOTP for local and Active Directory users; role Admin / Viewer from groups; role Editor / Admin from an application rule; single sign-on into GitLab without a prompt; MFA asked again after the session lifetime; policy deny; sign-out through signout_redirect_url; console revoke |
What works
Section titled “What works”- Second factor: TOTP was verified. Push and e-mail MFA were not tested with Grafana; they run on OkYouIn’s own sign-in page, so Grafana is not involved, but the lab record does not cover them.
- Roles: Viewer, Editor or Admin from an OkYouIn group, or from a
roleclaim set by an application rule. - Single sign-on: a user already signed in to another OkYouIn OIDC or SAML application in the same browser goes straight into Grafana, without a prompt, as long as their last MFA is younger than the application’s Session lifetime (hours).
Before you start
Section titled “Before you start”- Grafana must be served over HTTPS (its own TLS or a reverse proxy). OkYouIn accepts only
httpsredirect URIs (httponly for localhost). - OkYouIn’s public URL (Settings ▸ General) must be an
https://address: without it there is no issuer and every/oidc/endpoint answers 503. - Create the application in Access ▸ Applications ▸ Add application ▸ Grafana. Set
Redirect URIs to Grafana’s
root_urlfollowed bylogin/generic_oauth, for examplehttps://grafana.example.com/login/generic_oauth, and keephttps://grafana.example.com/loginin Post-logout redirect URIs. Client type stays Confidential. - The Connect tab shows the snippet below with your client ID, secret and URLs filled in.
Configure
Section titled “Configure”-
Add the section to
/etc/grafana/grafana.ini(or set the matchingGF_AUTH_GENERIC_OAUTH_*variables):/etc/grafana/grafana.ini [auth.generic_oauth]enabled = truename = OkYouInclient_id = <CLIENT-ID>client_secret = <CLIENT-SECRET>scopes = openid profile email groupsauth_url = https://mfa.example.com/oidc/authorizetoken_url = https://mfa.example.com/oidc/tokenapi_url = https://mfa.example.com/oidc/userinfouse_pkce = truelogin_attribute_path = preferred_usernamename_attribute_path = nameemail_attribute_path = email || preferred_usernamerole_attribute_path = role || contains(groups[*], 'Admins') && 'Admin' || 'Viewer'signout_redirect_url = https://mfa.example.com/oidc/end_session?client_id=<CLIENT-ID>&post_logout_redirect_uri=https://grafana.example.com/loginIn
role_attribute_pathreplaceAdminswith the OkYouIn group whose members become Grafana Admins; everyone else signs in as Viewer. -
Restart Grafana. Its login page now shows Sign in with OkYouIn.
-
Allow the application in the policy. Add a global policy rule that allows Grafana for the right users — see Policy.
Roles, login name and e-mail
Section titled “Roles, login name and e-mail”- Roles per group from OkYouIn. On the application’s Rules tab, add the
roleclaim (Viewer, Editor or Admin) to a rule for a group.role_attribute_pathreadsrolefirst; users whose rule sends no role fall back to the Admins / Viewer mapping above. The policy tester shows which rule set the role. - Login name.
login_attribute_pathmakes the Grafana login the OkYouIn username instead of the e-mail address. - E-mail. Grafana refuses a sign-in without an e-mail address.
email_attribute_pathfalls back topreferred_username(a directory user’s UPN) for users without an e-mail in OkYouIn. Drop the fallback if every user has an e-mail.
Sign-out
Section titled “Sign-out”signout_redirect_url sends Grafana’s Sign out to OkYouIn’s end-session URL. Grafana adds
the id_token_hint itself, so the OkYouIn session ends without a confirmation page and the
browser returns to Grafana’s login page. Keep https://grafana.example.com/login in
Post-logout redirect URIs.
Verify
Section titled “Verify”- In a private window, click Sign in with OkYouIn, enter the password and the code. You land in Grafana; the profile shows the OkYouIn username, name and role.
- Logging ▸ SSO sign-in log shows the sign-in (an MFA row, then Allowed) with the application and the policy and application rule that decided it.
- Logging ▸ SSO sessions lists the browser’s session with Grafana among its applications.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause |
|---|---|
| OkYouIn says the redirect URI is not registered | root_url + login/generic_oauth differs from Redirect URIs — scheme, host, port and path must match exactly. |
| ”Login failed” for a user without an e-mail | The email_attribute_path fallback is missing; Grafana then looks for a GitHub-style e-mail endpoint that does not exist. |
| Grafana login is the e-mail address | login_attribute_path = preferred_username is missing. |
| ”Login provider denied login request” | OkYouIn’s policy denied the user. The SSO sign-in log names the rule. |
| Everyone is a Viewer | The group name in role_attribute_path does not match the OkYouIn group, and no rule sends role. |