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:
| Setting | Value |
|---|---|
| Client type | OpenID Connect |
| Client ID | gitlab |
| Client authentication | On |
| Authentication flow | Standard flow only |
| Root URL | https://gitlab.example.com |
| Home URL | https://gitlab.example.com |
| Valid redirect URIs | https://gitlab.example.com/users/auth/openid_connect/callback |
| Valid post logout redirect URIs | https://gitlab.example.com/users/sign_in |
| Web origins | Leave 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:
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| Setting | Meaning |
|---|---|
omniauth_allow_single_sign_on | Creates 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_users | New accounts wait for an administrator's approval. Set it to false if every user of the realm may use GitLab. |
name | Must stay openid_connect; it is part of the callback path. |
issuer and discovery: true | GitLab reads https://auth.example.com/realms/acme/.well-known/openid-configuration for the endpoints and keys. |
client_auth_method | query sends the client ID and secret in the request body, as in GitLab's Keycloak example. |
uid_field | The claim that identifies the user. preferred_username is the Keycloak username; leave it out to use sub, the user's ID. |
pkce | Adds a PKCE challenge to the login. |
client_options | The 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:
-
In GitLab, select Admin in the upper-right corner, then Settings → General in the left sidebar.
-
Expand Sign-in restrictions.
-
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 -
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
- On the
gitlabclient, open the Client scopes tab and choosegitlab-dedicated. - Choose Configure a new mapper and pick Group Membership.
- Fill it in and choose Save:
| Field | Value |
|---|---|
| Name | groups |
| Token Claim Name | groups |
| Full group path | Off |
| Add to ID token | On |
| Add to userinfo | On |
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:
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"]
}
}
}
}
]| Setting | Effect |
|---|---|
groups_attribute | The claim that holds the groups. |
required_groups | Only members may sign in. Leave it out to let every user of the realm in. |
admin_groups | Members are GitLab administrators. A user who leaves the group loses admin access at the next sign-in. |
external_groups | Members are external users: they see public projects and only the internal or private ones they are members of. |
auditor_groups | Members are auditors, with read-only access to the instance. |
GitLab checks these groups at every sign-in and updates the user.
Test it
- Run
sudo gitlab-ctl reconfigureafter each change togitlab.rb. - Open
https://gitlab.example.com/users/sign_inin a private window and select Keycloak. - Sign in as a test user. If
omniauth_block_auto_created_usersistrue, the account waits for approval: select Admin, then Overview → Users, filter by State=Pending approval and approve it. - To see the claims GitLab receives, open the
gitlabclient in Keycloak, go to Client scopes → Evaluate, pick the user and look at Generated ID token. Paste it into the JWT decoder.
Common errors
| Error | Cause | Fix |
|---|---|---|
Invalid parameter: redirect_uri on the Keycloak page | The 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 login | Wrong 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 errors | issuer 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 errors | The realm signs with a symmetric algorithm such as HS256. | Set Default Signature Algorithm back to RS256. |
| New users see that their account is awaiting approval | omniauth_block_auto_created_users is true. | Approve them under Admin → Overview → Users, or set it to false. |
| Group settings have no effect | Free 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
- GitLab, Use OpenID Connect as an authentication provider: https://docs.gitlab.com/administration/auth/oidc/
- GitLab, OmniAuth common settings: https://docs.gitlab.com/integration/omniauth/
- GitLab, Sign-in restrictions (Sign-out page URL): https://docs.gitlab.com/administration/settings/sign_in_restrictions/
- GitLab 19.6 release tags: https://gitlab.com/gitlab-org/gitlab/-/tags
- Keycloak Server Administration Guide, client settings and protocol mappers: https://www.keycloak.org/docs/latest/server_admin/
- Keycloak, OpenID Connect logout: https://www.keycloak.org/securing-apps/oidc-layers
Keycloak SSO for Grafana
Sign in to Grafana with Keycloak through Generic OAuth, map Keycloak groups to Grafana roles with JMESPath, and log out of both at once.
Keycloak SSO for Argo CD
Sign in to Argo CD with Keycloak over OpenID Connect, send Keycloak groups in a groups claim, and map them to Argo CD roles in argocd-rbac-cm.