Zum Inhalt springen

GitLab (OIDC)

Self-managed GitLab signs users in through its OpenID Connect OmniAuth provider, with OkYouIn as the provider. An OkYouIn button appears on GitLab’s sign-in page; the password and second factor are entered on OkYouIn’s sign-in page. For OkYouIn’s OIDC provider in general, see OpenID Connect. If you prefer SAML for GitLab, see GitLab (SAML).

ProductVersionModesWhat was verified
GitLab CE (Omnibus Docker image)19.5.3-ce.0password + MFAOmniAuth openid_connect with discovery, PKCE and uid_field: sub; first sign-in with TOTP creates the account (local and Active Directory users); single sign-on from Grafana without a prompt; MFA asked again after the session lifetime; policy deny; sign-out through the after-sign-out path; console revoke; email_verified not needed
  • Second factor: TOTP was verified. Push and e-mail MFA were not tested with GitLab.
  • Accounts: created at the first sign-in, active at once with the snippet below.
  • Not tested: GitLab group sync (a GitLab Premium feature).
  • GitLab must be served over HTTPS. OkYouIn accepts only https redirect URIs (http only for localhost).
  • OkYouIn’s public URL (Settings ▸ General) must be an https:// address.
  • Create the application in Access ▸ Applications ▸ Add application ▸ GitLab. The redirect URI is GitLab’s external_url followed by /users/auth/openid_connect/callback, for example https://gitlab.example.com/users/auth/openid_connect/callback. Keep https://gitlab.example.com/users/sign_in in Post-logout redirect URIs.
  • The Connect tab shows the snippets with your client ID, secret and URLs filled in.
  1. Add the OmniAuth provider to /etc/gitlab/gitlab.rb:

    /etc/gitlab/gitlab.rb
    gitlab_rails['omniauth_allow_single_sign_on'] = ['openid_connect']
    gitlab_rails['omniauth_block_auto_created_users'] = false
    gitlab_rails['omniauth_providers'] = [
    {
    name: "openid_connect",
    label: "OkYouIn",
    args: {
    name: "openid_connect",
    scope: ["openid", "profile", "email"],
    response_type: "code",
    issuer: "https://mfa.example.com/oidc",
    discovery: true,
    uid_field: "sub",
    pkce: true,
    client_options: {
    identifier: "<CLIENT-ID>",
    secret: "<CLIENT-SECRET>",
    redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
    }
    }
    }
    ]
  2. Apply it: sudo gitlab-ctl reconfigure. An OkYouIn button appears on the GitLab sign-in page.

  3. Set the after-sign-out path (see Sign-out).

  4. Allow the application in the policy — see Policy.

  • Account creation. The first SSO sign-in creates the GitLab account: the username from preferred_username (a directory user’s UPN loses its @domain), the name and the e-mail. With omniauth_block_auto_created_users set to false it is active at once; GitLab’s default (true) leaves it “pending approval” until an administrator approves it in Admin ▸ Users.
  • Stable link. uid_field: "sub" (the OkYouIn user ID) keeps the link when a user is renamed.
  • E-mail. GitLab takes the e-mail from OkYouIn and marks it confirmed; email_verified is not needed (OkYouIn does not send it). A user without an e-mail in OkYouIn gets a temp-email-for-oauth address and is asked to complete the profile.
  • Linking existing accounts. Linking SSO sign-ins to existing GitLab accounts by e-mail (omniauth_auto_link_user) is off by default. Turn it on only if the e-mail addresses in OkYouIn are trusted.

GitLab does not call OkYouIn’s end-session URL itself, so by default GitLab’s Sign out leaves the OkYouIn session alive. Set Admin ▸ Settings ▸ General ▸ Sign-in restrictions ▸ After sign-out path to:

https://mfa.example.com/oidc/end_session?client_id=<CLIENT-ID>&post_logout_redirect_uri=https://gitlab.example.com/users/sign_in

GitLab’s Sign out then ends the OkYouIn session too. OkYouIn asks “Sign out?” once — GitLab sends no id_token_hint — and returns to GitLab’s sign-in page.

Revoking a session in Logging ▸ SSO sessions ends the OkYouIn session (the next sign-in asks for the password), but does not end a GitLab session that is already open.

  1. In a private window, click OkYouIn on the GitLab sign-in page, enter the password and the code. The account is created (or reused) and you are signed in.
  2. Open Grafana or another OkYouIn application in the same browser: it signs in without a prompt while the MFA is within the session lifetime.
  3. Logging ▸ SSO sign-in log shows the MFA round and the allow, with the deciding rules.
SymptomCause
”Your account is pending approval from your GitLab administrator”omniauth_block_auto_created_users is still true (GitLab’s default). Approve in Admin ▸ Users, or set it to false.
”Could not authenticate you from OpenIDConnect because “Deny""OkYouIn’s policy denied the user; the SSO sign-in log names the rule.
Redirect URI not registeredexternal_url + /users/auth/openid_connect/callback differs from Redirect URIs.
Signing out of GitLab does not sign out of OkYouInThe after-sign-out path is not set.
A user is asked to complete the profileThe user has no e-mail in OkYouIn.