RealmDeployDocs
GuidesSingle sign-on for apps

Keycloak SSO for GitLab

Sign in to GitLab Self-Managed with Keycloak through the OmniAuth OpenID Connect provider, and use Keycloak groups for admin and external users.

GitLab Self-Managed signs users in with Keycloak through its OmniAuth OpenID Connect provider. The provider is in every tier, Free included. Group-based admin, external and required groups need Premium or Ultimate.

Checked against GitLab 19.6 docs and Keycloak 26.8 on 25 November 2026. The steps are for the Linux package (/etc/gitlab/gitlab.rb); self-compiled installs and the Helm chart take the same provider settings in their own files.

Replace auth.example.com with your RealmDeploy hostname and acme with your realm. The examples use https://gitlab.example.com for GitLab.

In Keycloak

Open Clients, choose Create client, and use these values:

SettingValue
Client typeOpenID Connect
Client IDgitlab
Client authenticationOn
Authentication flowStandard flow only
Root URLhttps://gitlab.example.com
Home URLhttps://gitlab.example.com
Valid redirect URIshttps://gitlab.example.com/users/auth/openid_connect/callback
Valid post logout redirect URIshttps://gitlab.example.com/users/sign_in
Web originsLeave empty

Choose Save, then copy the secret from the Credentials tab.

GitLab's docs ask for tokens signed with a public-key algorithm such as RS256. That is Keycloak's default (Realm settings → Tokens → Default Signature Algorithm), so leave it unless you changed it.

In GitLab

Edit /etc/gitlab/gitlab.rb:

/etc/gitlab/gitlab.rb
gitlab_rails['omniauth_allow_single_sign_on'] = ['openid_connect']
gitlab_rails['omniauth_block_auto_created_users'] = true

gitlab_rails['omniauth_providers'] = [
  {
    name: "openid_connect", # do not change this parameter
    label: "Keycloak",
    args: {
      name: "openid_connect",
      scope: ["openid", "profile", "email"],
      response_type: "code",
      issuer: "https://auth.example.com/realms/acme",
      discovery: true,
      client_auth_method: "query",
      uid_field: "preferred_username",
      pkce: true,
      client_options: {
        identifier: "gitlab",
        secret: "CLIENT_SECRET_FROM_KEYCLOAK",
        redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback"
      }
    }
  }
]

Then apply it:

sudo gitlab-ctl reconfigure
SettingMeaning
omniauth_allow_single_sign_onCreates a GitLab account the first time someone signs in with Keycloak. Without it, users must have an account first and link it in their profile.
omniauth_block_auto_created_usersNew accounts wait for an administrator's approval. Set it to false if every user of the realm may use GitLab.
nameMust stay openid_connect; it is part of the callback path.
issuer and discovery: trueGitLab reads https://auth.example.com/realms/acme/.well-known/openid-configuration for the endpoints and keys.
client_auth_methodquery sends the client ID and secret in the request body, as in GitLab's Keycloak example.
uid_fieldThe claim that identifies the user. preferred_username is the Keycloak username; leave it out to use sub, the user's ID.
pkceAdds a PKCE challenge to the login.
client_optionsThe client ID, the secret from the Credentials tab, and the callback URI you listed in Keycloak.

The sign-in page now shows a Keycloak button below the password form.

Log out of Keycloak too

Signing out of GitLab does not end the Keycloak session. To end both, send users to Keycloak's logout endpoint after they sign out of GitLab:

  1. In GitLab, select Admin in the upper-right corner, then Settings → General in the left sidebar.

  2. Expand Sign-in restrictions.

  3. Set Sign-out page URL to:

    https://auth.example.com/realms/acme/protocol/openid-connect/logout?client_id=gitlab&post_logout_redirect_uri=https%3A%2F%2Fgitlab.example.com%2Fusers%2Fsign_in
  4. Select Save changes.

Because GitLab cannot add id_token_hint to this URL, Keycloak may ask the user to confirm the logout before it sends them back to the sign-in page.

Groups and roles

GitLab can read a groups claim and use it to require a group to sign in, or to make users administrators, auditors or external users. This is a Premium and Ultimate feature. On the Free tier, GitLab ignores these settings and you manage roles in GitLab. It also does not add users to GitLab groups or projects.

In Keycloak

  1. On the gitlab client, open the Client scopes tab and choose gitlab-dedicated.
  2. Choose Configure a new mapper and pick Group Membership.
  3. Fill it in and choose Save:
FieldValue
Namegroups
Token Claim Namegroups
Full group pathOff
Add to ID tokenOn
Add to userinfoOn

Create the groups under Groups, for example gitlab-users, gitlab-admins and gitlab-external, and add users to them.

In GitLab

Add a gitlab block inside client_options. The values must match the group names exactly as they appear in the claim:

/etc/gitlab/gitlab.rb
gitlab_rails['omniauth_providers'] = [
  {
    name: "openid_connect",
    label: "Keycloak",
    args: {
      name: "openid_connect",
      scope: ["openid", "profile", "email"],
      response_type: "code",
      issuer: "https://auth.example.com/realms/acme",
      discovery: true,
      client_auth_method: "query",
      uid_field: "preferred_username",
      pkce: true,
      client_options: {
        identifier: "gitlab",
        secret: "CLIENT_SECRET_FROM_KEYCLOAK",
        redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback",
        gitlab: {
          groups_attribute: "groups",
          required_groups: ["gitlab-users"],
          admin_groups: ["gitlab-admins"],
          external_groups: ["gitlab-external"]
        }
      }
    }
  }
]
SettingEffect
groups_attributeThe claim that holds the groups.
required_groupsOnly members may sign in. Leave it out to let every user of the realm in.
admin_groupsMembers are GitLab administrators. A user who leaves the group loses admin access at the next sign-in.
external_groupsMembers are external users: they see public projects and only the internal or private ones they are members of.
auditor_groupsMembers are auditors, with read-only access to the instance.

GitLab checks these groups at every sign-in and updates the user.

Test it

  1. Run sudo gitlab-ctl reconfigure after each change to gitlab.rb.
  2. Open https://gitlab.example.com/users/sign_in in a private window and select Keycloak.
  3. Sign in as a test user. If omniauth_block_auto_created_users is true, the account waits for approval: select Admin, then Overview → Users, filter by State=Pending approval and approve it.
  4. To see the claims GitLab receives, open the gitlab client in Keycloak, go to Client scopes → Evaluate, pick the user and look at Generated ID token. Paste it into the JWT decoder.

Common errors

ErrorCauseFix
Invalid parameter: redirect_uri on the Keycloak pageThe redirect_uri in gitlab.rb and Valid redirect URIs differ, often in the scheme or host.Make both exactly https://gitlab.example.com/users/auth/openid_connect/callback. Check with the redirect URI matcher.
invalid_client or unauthorized_client after the Keycloak loginWrong secret, or Client authentication is off.Copy the secret again from the Credentials tab. Look up other codes in the OAuth error lookup.
Discovery or issuer errorsissuer has a trailing slash, an old /auth path or the wrong realm.Use https://auth.example.com/realms/acme exactly. Open the discovery document in the OIDC discovery viewer and compare its issuer.
Signature errorsThe realm signs with a symmetric algorithm such as HS256.Set Default Signature Algorithm back to RS256.
New users see that their account is awaiting approvalomniauth_block_auto_created_users is true.Approve them under Admin → Overview → Users, or set it to false.
Group settings have no effectFree tier, or the groups have a leading slash because Full group path is on.Group settings need Premium or Ultimate. Turn off Full group path.

FAQ

Can existing GitLab users keep their accounts?

Yes. A signed-in user can link Keycloak in their profile. GitLab can also link accounts automatically by matching email with gitlab_rails['omniauth_auto_link_user'] = ['openid_connect']; only use it if Keycloak verifies email addresses.

Can I send everyone straight to Keycloak?

Yes, with gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'openid_connect'. GitLab's docs warn that users must also sign out of Keycloak to avoid a sign-in loop, which the Sign-out page URL above does.

Does this work on GitLab.com?

No. The OmniAuth OpenID Connect provider is for GitLab Self-Managed.

Sources

On this page