Keycloak and GitLab SSO integration

Keycloak can be the sign-in source for self-managed GitLab through OpenID Connect. This page covers the setup sequence, the HTTPS and RS256 requirements to confirm, group mapping, and which group features need GitLab Premium.

On this page

How Keycloak GitLab SSO works over OpenID Connect

This integration uses OpenID Connect with a confidential client in Keycloak, and GitLab's omniauth OIDC sign-in receives the tokens. Keycloak issues the identity and decides who may sign in, while group claims in the token decide what the user can reach inside GitLab. Keycloak owns the user records, passwords, multi-factor methods, and group membership. GitLab still owns projects, namespaces, roles, runners, and the permissions that apply to each of them, so a Keycloak group does not replace GitLab's own access model.

The two sides only work when their settings match exactly. The redirect URI registered in the Keycloak client must equal the callback path GitLab uses for its OpenID Connect provider, the client ID and client secret must be copied identically, and the issuer URL in GitLab must match the issuer Keycloak publishes in its discovery document for the realm. Confirm each value against the configuration files in your own environment rather than from memory, because a single character mismatch typically produces a sign-in error that looks like a token problem. Also confirm which claim GitLab reads for the username and for group membership, since the Keycloak client must include a mapper that places groups in the token under that name.

Before you build, decide three things with the identity team: whether the client will be confidential with a secret stored in GitLab's configuration, which Keycloak group paths will map to GitLab access levels, and who holds the break-glass local administrator account for GitLab if the realm is unavailable. Check GitLab's current documentation for the OpenID Connect provider settings in the version you run, because option names and defaults change between releases. Plan the HTTPS endpoints for both services first, since the sign-in flow redirects the browser between them and both must present valid certificates.

What you need before configuring GitLab and Keycloak

The GitLab sign-in flow depends on a few things being settled before anyone opens an admin console. Confirm these six items first, because most failed OIDC attempts trace back to a missing HTTPS endpoint, a mismatched URL or an undefined group model.

Keycloak 26.x realm over HTTPS

Keycloak must serve the realm GitLab will trust over TLS with a certificate that browsers and GitLab's server both accept. Keycloak's production guide calls for TLS on all communication, so plan the reverse proxy and hostname before you create the client. The current release is 26.8.1, so confirm which 26.x line your environment runs. Red Hat build of Keycloak users should check their build's version separately, since it can lag the upstream release.

Keycloak production guide

GitLab served over HTTPS

Your self-managed GitLab must answer at its external URL over HTTPS, and that exact URL becomes the base of the redirect URI registered in Keycloak. Confirm that the external URL in your GitLab configuration matches the hostname users type, because a mismatch between http and https or a changed hostname is a common cause of redirect errors. Confirm the HTTPS and certificate requirements in GitLab's own documentation for your installed version.

Keycloak group structure

Decide which Keycloak groups will map to GitLab access before you configure anything. Group names should describe a role or team your access model already recognizes, such as platform engineers or auditors, and each group should have a single owner. Plan for a groups claim in the ID token or userinfo response, and confirm how your GitLab version handles group-based access and which tier it requires for group sync features.

Administrator access to both systems

You need an administrator account in Keycloak that can create clients, mappers and groups, and an administrator account in GitLab that can edit the sign-in configuration and the Admin Area. Separate these roles from day-to-day operator accounts where your access policy requires it. Confirm that both administrators can complete the change without waiting on a second team, because a stalled approval mid-configuration leaves users locked out.

A test user for each access level

Create one test user in Keycloak for each access level you intend to grant, such as a standard developer, a maintainer and a read-only auditor. Assign each user only the groups that level requires. Testing with real accounts before rollout shows whether the groups claim arrives as expected and whether GitLab assigns the right role, which is much cheaper than discovering a privilege gap after users sign in.

Break-glass root login plan

Keep a local GitLab root login working before you enable OIDC, and store its credentials in your privileged account vault with a documented owner. If the Keycloak realm, certificate or client secret fails, this is the only path back into GitLab without a restore. Test that the local login works, and confirm the sign-in method GitLab's documentation allows alongside an OIDC provider so the break-glass path is not disabled by the change.

How a GitLab sign-in travels through Keycloak

The sign-in starts in the user browser, which GitLab redirects to the Keycloak authorization endpoint of the realm. Keycloak checks the user against its user store and runs the configured login steps, such as password, MFA or passkey. The browser then carries only a short-lived authorization code back to the GitLab callback. GitLab exchanges that code for tokens over a direct server-to-server channel, so the tokens never pass through the browser. Check the redirect URI, the claims returned, and how group values map to GitLab access before go-live.

Browser redirects carry the code, while token exchange runs over the back channel.

Configure the Keycloak client and GitLab OIDC provider in order

This sequence sets up a confidential Keycloak client, shapes the tokens GitLab needs, and wires the matching OpenID Connect provider into self-managed GitLab, ending with a verified sign-in for test users in each group.

  1. Create the confidential OpenID Connect client

    In the realm you chose for GitLab, create an OpenID Connect client for GitLab and set its valid redirect URI to the GitLab callback URL for your instance, using the exact path GitLab documents for its OmniAuth omniauth_openid_connect provider. Your GitLab team or DeployOpen engineer should copy the URL from the GitLab documentation for your version rather than typing it from memory. Check: open the realm's OpenID Configuration Document in a browser and confirm the issuer and endpoints resolve over HTTPS. Keycloak's production guide expects TLS on all communication, so an HTTP-only address is a blocker at this point.

  2. Enable client authentication and store the secret

    Turn on client authentication so Keycloak issues a confidential client with a client secret, and keep the standard authorization code flow enabled. Generate the secret in Keycloak's credentials tab and move it straight into your secrets store, such as a vault or the Kubernetes secret mechanism your team already operates. Do not paste it into a shared document or a repository. Check: the secret is visible in the store, the store entry has an owner and a rotation note, and the Keycloak client shows client authentication as on.

  3. Add a groups mapper to the client

    Add a mapper to the client's dedicated scope that puts group membership into the ID token under a claim name your GitLab configuration will read, such as groups. Choose whether to emit full group paths or short names, and keep that choice consistent with the group names you plan to map to GitLab access. Check: sign in as a test user through the Keycloak account console or a test client, decode the ID token at a JWT inspection tool you trust (inside your own environment if the token is sensitive), and confirm the groups claim lists the expected groups.

  4. Set the realm token signing algorithm to RS256

    In the realm's token settings, confirm the ID token signature algorithm is RS256, which is the algorithm GitLab's OpenID Connect integration expects in the documentation you are working from. Confirm the exact algorithm list and any related settings against GitLab's current documentation before you change anything, because the requirement is tied to the GitLab version you run. Check: the discovery document lists RS256 among the supported ID token signing algorithms, and a freshly issued test ID token carries an RS256 header.

  5. Add the OIDC provider block to GitLab

    On the GitLab server, add the OpenID Connect provider block to the configuration file your installation uses, pointing the issuer at the Keycloak realm URL, and supplying the client ID, the client secret read from your secrets store, and the claims GitLab should expect, including the groups claim from the earlier mapper. Confirm every configuration key name, the callback path and the required options in GitLab's current documentation for your version, since key names change between releases. Check: the configuration file parses without errors on a dry run or syntax check your team uses.

  6. Reconfigure and restart GitLab

    Apply the new configuration with the reconfigure command your installation method documents, then restart GitLab so the authentication settings load. Keep a local administrator account available and tested before you restart, so a failed sign-in does not lock everyone out. Check: GitLab finishes reconfiguration without errors, the services report healthy, and the sign-in page shows a new button for Keycloak alongside the existing local login.

  7. Sign in with a test user from each group

    Sign in through the new Keycloak button with one test account from each Keycloak group you plan to map, and record which GitLab account and access level each one receives. Compare the result against the mapping you intended, and treat any mismatch as a stop point before real users are onboarded. Confirm group-based features against your GitLab edition and plan, because some group capabilities depend on GitLab Premium. Check: each test account lands in the expected GitLab account with the expected access, and the results are recorded for the change file.

Map Keycloak attributes and groups to GitLab access

This table pairs each Keycloak source (claims, attributes and group paths) with the GitLab field it populates and a check to run before users depend on it. Read it as a build checklist: every row that fails to match can block sign-in or leave a user with the wrong access, so confirm each mapping with a test user before rollout.

ItemKeycloak sourceGitLab target and check
UsernameA stable claim such as preferred_username, configured in the client's mappersGitLab username. Confirm the claim is unique, stable and not editable by users, and check how GitLab handles usernames that already exist locally.
EmailThe email claim, with email_verified set in the token if your GitLab configuration requires itGitLab primary email. Confirm the claim is always present for every user who signs in, since a missing value can block sign-in.
Full nameThe name claim, or given_name and family_name if you build the name from partsGitLab display name. Confirm that the values appear correctly on a test profile and that they match the directory source of record.
Groups claimA groups claim added by a client mapper, with the choice between full group paths (for example, /parent/child) and short namesGitLab group membership input. Confirm which form GitLab expects in its current OIDC documentation and that a test user's groups arrive in the token exactly as mapped.
Group-to-access mappingSpecific Keycloak groups selected for GitLab access, separated from groups used for other applicationsGitLab group membership or role. Verify role names and which mappings require a Premium or Ultimate tier in GitLab's current docs before you promise a access model.
Group removalA user removed from a Keycloak group in the directory or realmGitLab membership should change on the user's next sign-in or sync, depending on the configuration you choose. Test removal with a disposable account and record the result.
Missing or unmatched claimsAny user whose token lacks the required claim or whose group does not match a mappingSign-in can fail or the user can land without access. Confirm the expected behavior with a test user who has no groups and a user with an unmapped group.

Which group features need GitLab Premium

Signing in to GitLab through Keycloak and keeping group membership in step with Keycloak are two different features, and they do not carry the same tier requirements. Sign-in over OpenID Connect works from the OIDC provider configuration itself. Automatic group membership or role sync, which reads a groups claim from Keycloak and assigns GitLab group access from it, is a separate capability that GitLab ties to a specific tier. Before you promise group sync to stakeholders, open the current GitLab feature matrix and confirm which tier covers the group sync or SAML group features in the version you run. Do not rely on this page for that answer, because GitLab changes its tier placement between releases.

Confirm three things with your GitLab vendor or account contact, using the version you plan to deploy: which tier includes the group-level features you need, whether the Keycloak-side groups claim is supported for the mechanism you choose, and whether any license restriction applies to a self-managed instance. Write the answer into the design record next to the date you checked it. If the answer is that sync needs a higher tier, decide whether that license cost belongs in the business case before the build starts, since it recurs for as long as the instance runs.

If your team stays on the Free tier, group access can still be managed in two ways. The first is manual group membership: administrators add and remove users inside GitLab, and Keycloak controls only sign-in and identity attributes. The second is a scheduled script that calls the GitLab API to align group membership with a list built from Keycloak groups, for example by reading group data through the Keycloak admin API. A script needs a service account with a scoped token, logging of every change, a dry-run mode, and a review of removals so that a bad source list does not strip access from many users at once. Plan for someone to own that script after the first build.

Security settings for Keycloak to GitLab sign-in

Signing GitLab in through Keycloak moves authentication decisions into a second system, so both ends need controls. The cards below cover transport, secret handling, realm authentication, access scope, recovery and monitoring, and each one names a setting to verify before the integration goes live.

Enforce HTTPS on both ends

Serve GitLab and Keycloak only over TLS, and confirm the redirect URI and the issuer URL in the GitLab OpenID Connect settings both use https. Keycloak's production guidance calls for TLS on all communication, including the back-channel calls GitLab makes to the token and userinfo endpoints. Check that no internal hostname or plaintext proxy hop sits between GitLab and Keycloak, and that certificates are trusted by the GitLab host, since a failed trust check often leads teams to disable verification instead.

Keycloak production guide

Keep the client secret out of version control

The confidential client secret that GitLab uses should live in a secrets store or a protected file on the GitLab host, not in gitlab.rb committed to a repository. Rotate it after anyone with access leaves the team, and record who can read the configuration file on the server. Confirm that Keycloak access logs and admin event logs do not capture the secret, and that backups of the GitLab configuration are encrypted and access controlled.

Require MFA or passkeys in the realm

GitLab trusts whatever authentication Keycloak performs, so the strength of sign-in depends on the realm's authentication flow. Bind the GitLab client to a browser flow that requires OTP, WebAuthn or passkeys, and check that conditional MFA rules do not exempt the GitLab client by default. Test a sign-in from a new browser to confirm the second factor is actually prompted before users rely on it.

Restrict who can sign in

Use a Keycloak group or role that is allowed to access GitLab, and only assign it to users who need GitLab. Pair that scope with GitLab's own group access so a valid Keycloak account does not automatically become a GitLab administrator. Review the assigned population on a set schedule, and confirm that disabled or removed Keycloak users lose access to GitLab sessions, not only to new sign-ins.

Set token lifetimes deliberately

Choose access token and session lifetimes in the Keycloak realm that match how long GitLab sessions should stay valid, and document the values. Shorter lifetimes limit the window in which a stolen token is useful, while longer lifetimes reduce sign-in prompts for developers. Confirm how GitLab handles session expiry and whether refresh behavior matches your policy, since these settings interact and are easy to change in one system without updating the other.

Plan break-glass access to GitLab

Keep the GitLab root account with a strong, offline-stored password and a hardware-backed second factor, and test that it works before any Keycloak change. Designate a second local administrator who is not tied to the Keycloak directory. If Keycloak or its database is unavailable, these accounts let operators restore access and fix the integration, so review them when administrators change.

Log Keycloak and GitLab, and expose metrics

Turn on Keycloak metrics with --metrics-enabled=true and scrape the Prometheus-format output at /metrics on the management interface, not on the public frontend. Forward sign-in events from both systems to a central log store so a failed or unusual GitLab login can be traced back to its Keycloak authentication event. Confirm retention periods meet your own policy, since the defaults in each product may not.

Keycloak metrics guide

Choosing how much group logic lives in Keycloak

In this model, Keycloak is the system of record for group membership. Administrators assign users to Keycloak groups, and a groups claim in the token carries those memberships into GitLab at each sign-in. Teams that already run Keycloak as the central directory usually prefer this model because joiners, movers and leavers are handled once.

  • Maintainers: identity administrators or the team that owns the HR or directory feed, not GitLab group owners.
  • Leavers: disabling the Keycloak user blocks new sign-ins, but existing sessions and tokens stay valid until they expire, so confirm your token and session lifetimes.
  • Audit trail: Keycloak admin events record group changes, while GitLab records the resulting sign-ins. Confirm that both logs are retained and forwarded to your SIEM.
  • Effort: the claim mapping and group naming are built once, then operations are mostly Keycloak administration.
  • Limit: group-based roles in GitLab depend on the GitLab tier and its documented group sync features, so confirm those against GitLab's current documentation before you design around them.

Before you commit, check how GitLab maps incoming groups to group membership and which tier that behavior requires.

Why GitLab sign-in through Keycloak fails and how to fix it

This table pairs each sign-in failure a team typically meets with its likely cause and the fix to try first. Read it in order when a login breaks, starting with the checks that need no changes to either server. The main takeaway is that most failures trace to a mismatch between what Keycloak sends and what GitLab expects, so decoding the ID token and reading GitLab production logs usually isolates the cause.

SymptomLikely causeFix
Redirect error or invalid redirect URI after loginThe GitLab external URL changed, so the callback path no longer matches the redirect URI registered on the Keycloak clientUpdate the Keycloak client's valid redirect URI to the new GitLab callback URL, then confirm the GitLab external_url setting matches the hostname users type
Token exchange fails with an invalid client secretThe client secret was rotated in Keycloak but the GitLab configuration still holds the old valueCopy the current secret from the Keycloak client credentials tab into the GitLab OmniAuth provider settings, then reconfigure and restart GitLab
Certificate verification error on the callbackGitLab cannot validate the Keycloak HTTPS certificate, often because an internal certificate authority is missing from the GitLab trust storeInstall the internal CA certificate where GitLab trusts it, test the Keycloak discovery URL from the GitLab host, and avoid disabling verification
Sign-in succeeds but the user has no group accessThe token has no groups claim, the mapper is missing from the client, or the group names do not match GitLab configurationAdd a groups mapper to the client scope, decode the ID token to confirm the claim appears, and align group names with the GitLab settings
Signature validation failure on the ID tokenThe realm signing algorithm is not RS256, or GitLab is reading keys from the wrong realmSet the realm token signing algorithm to RS256, confirm the discovery endpoint publishes the expected keys, and check the GitLab production log for the rejected algorithm
Login maps to an existing local account or fails with a duplicate usernameA local GitLab user already holds the same username or email as the Keycloak identityDecide the matching attribute in advance, resolve duplicates before go-live, and check how GitLab links existing accounts for the configured provider
Users locked out after an MFA reset in KeycloakThe user's credentials or required actions changed, or a stale session persists, so the next login loops or is refusedReview the user's required actions and sessions in Keycloak, clear stale sessions, and keep a local GitLab administrator account for recovery
Tokens rejected as not yet valid or expired immediatelyClock skew between the Keycloak host and the GitLab host shifts the issued-at and expiry checksSynchronize both servers with NTP, verify the time on each host, and compare the iat and exp values in the decoded token with the GitLab log timestamps

Questions buyers ask before hiring help with GitLab SSO

What drives the cost of a Keycloak and GitLab SSO integration?

The cost follows the amount of decision-making and testing involved, more than the number of clicks. The main drivers are the number of Keycloak groups that must map to GitLab access, the number of GitLab instances or groups it covers, how much identity governance already exists in Keycloak, the testing scope across browsers, Git clients and CI jobs, and whether MFA rules must be designed for GitLab sign-in. Cost is largely one-time for configuration and testing, with recurring work for upgrades and secret rotation. Ask any partner to itemize these drivers in a written, fixed-scope quote so you can see what each one adds.

How long does a Keycloak to GitLab SSO project take?

No duration is fixed for this work, so treat any timeline as a function of its drivers. Duration grows with the number of groups that need review and sign-off, the number of GitLab instances, whether Keycloak realms and clients already exist, how many environments must be tested before production, and how quickly your group owners approve role mappings. Change windows for your GitLab and Keycloak servers also set the pace, as do any HTTPS or certificate work needed first. Ask a partner to tie each phase of the timeline to a named dependency in the written scope.

What do we need to provide for the integration?

You need administrator access to both Keycloak and GitLab, plus a non-production test environment for each. Keycloak access covers creating a client, configuring the groups claim and the mappers that feed GitLab. GitLab access covers the OmniAuth settings in the self-managed instance and the ability to verify sign-in. Before work starts, name a test plan that covers sign-in, first-time user creation, group-to-role mapping and sign-out. Group owners must confirm which Keycloak groups map to which GitLab access levels, because those decisions are business decisions, not technical ones.

Can our own team set up Keycloak and GitLab SSO without a partner?

Yes, a capable team can build this in-house, provided it works from the official documentation and a separate Keycloak test realm. Start in a non-production GitLab instance, confirm HTTPS and the RS256 signing requirements GitLab documents, and test group mapping with a small set of accounts before touching production. Keep a rollback plan: keep a local or break-glass GitLab administrator account available, and know how to revert the OmniAuth settings and Keycloak client changes. A partner adds value mainly when the scope is wide, the timeline is tight, or your team lacks the time to test thoroughly.

Which parts are one-time work and which recur?

The initial configuration is one-time work: creating the Keycloak client, setting redirect URIs, adding the groups claim, configuring GitLab OmniAuth, and mapping groups to access. Recurring work includes upgrades to both Keycloak and GitLab, which each need regression testing of SSO, and rotation of the client secret on a schedule your security policy sets. Group membership changes happen continuously in Keycloak, so someone must own the mapping review process. Ask a partner which of these tasks are included in the fixed-scope engagement and which fall under a separate retainer.

What should we ask for in a fixed-scope quote for GitLab SSO?

Ask for a written scope that lists each Keycloak realm, client and mapper to be configured, each GitLab instance covered, and the number of groups in scope. Request a test plan that names the sign-in, provisioning, group mapping, sign-out and rollback checks, and who signs off on each. Confirm which GitLab features are in scope and whether any group features require a GitLab Premium subscription on your side, since that licensing decision is yours and must be confirmed with GitLab. Also ask about handover documentation, post-launch support, and how upgrades and client secret rotation are handled after go-live.

How DeployOpen scopes and delivers Keycloak to GitLab SSO

DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside your own infrastructure, including Keycloak deployments and their integrations. For Keycloak and GitLab SSO integration, we agree the written scope first, build the OpenID Connect client and group mapping in your environment, and hand over the configuration and evidence your team needs to run it.

How we scope

  • Confirm your self-managed GitLab edition and whether your group mapping needs Premium features before design starts.
  • Record the Keycloak realm, client, groups claim and redirect URLs your GitLab instance will use in the written scope.
  • Agree which GitLab groups map to which access levels, and who approves changes to that mapping.

How we build

  • Configure the Keycloak client and GitLab OpenID Connect settings over HTTPS with RS256-signed tokens, as GitLab documents.
  • Test sign-in with a test user, a group member, a non-member and an account that should be blocked.
  • Keep a local administrator path in GitLab so sign-in problems cannot lock out every administrator.

How we hand over

  • Deliver the configuration record, including client settings, claim mappings, group-to-role tables and secret locations.
  • Provide a test script and a checklist your team can rerun after Keycloak or GitLab upgrades.
  • Walk your identity and platform engineers through the runbook for adding groups and rotating the client secret.

How we support

  • Offer ongoing support, upgrades and continuous testing for the integration as a retainer.
  • Retest sign-in and group mapping after each planned Keycloak or GitLab upgrade, using the written scope.
  • Review the integration when your access model or GitLab edition changes, and update the documentation to match.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.