Zum Inhalt springen

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.

ProductVersionModesWhat was verified
Grafana OSS (Docker image grafana/grafana)13.3.0password + MFAGeneric 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
  • 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 role claim 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).
  • Grafana must be served over HTTPS (its own TLS or a reverse proxy). OkYouIn accepts only https redirect URIs (http only 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_url followed by login/generic_oauth, for example https://grafana.example.com/login/generic_oauth, and keep https://grafana.example.com/login in Post-logout redirect URIs. Client type stays Confidential.
  • The Connect tab shows the snippet below with your client ID, secret and URLs filled in.
  1. Add the section to /etc/grafana/grafana.ini (or set the matching GF_AUTH_GENERIC_OAUTH_* variables):

    /etc/grafana/grafana.ini
    [auth.generic_oauth]
    enabled = true
    name = OkYouIn
    client_id = <CLIENT-ID>
    client_secret = <CLIENT-SECRET>
    scopes = openid profile email groups
    auth_url = https://mfa.example.com/oidc/authorize
    token_url = https://mfa.example.com/oidc/token
    api_url = https://mfa.example.com/oidc/userinfo
    use_pkce = true
    login_attribute_path = preferred_username
    name_attribute_path = name
    email_attribute_path = email || preferred_username
    role_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/login

    In role_attribute_path replace Admins with the OkYouIn group whose members become Grafana Admins; everyone else signs in as Viewer.

  2. Restart Grafana. Its login page now shows Sign in with OkYouIn.

  3. Allow the application in the policy. Add a global policy rule that allows Grafana for the right users — see Policy.

  • Roles per group from OkYouIn. On the application’s Rules tab, add the role claim (Viewer, Editor or Admin) to a rule for a group. role_attribute_path reads role first; 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_path makes 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_path falls back to preferred_username (a directory user’s UPN) for users without an e-mail in OkYouIn. Drop the fallback if every user has an e-mail.

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.

  1. 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.
  2. 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.
  3. Logging ▸ SSO sessions lists the browser’s session with Grafana among its applications.
SymptomCause
OkYouIn says the redirect URI is not registeredroot_url + login/generic_oauth differs from Redirect URIs — scheme, host, port and path must match exactly.
”Login failed” for a user without an e-mailThe 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 addresslogin_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 ViewerThe group name in role_attribute_path does not match the OkYouIn group, and no rule sends role.