Keycloak and SonarQube SAML single sign-on

Sign in to SonarQube Server through Keycloak over SAML with a clear client, redirect URI and group mapping plan. Learn the build order, the checks at each step and the failure points to test first.

On this page

How Keycloak SAML sign-in to SonarQube Server works

SonarSource documents Keycloak as a SAML identity provider for SonarQube Server, so a security or platform team that wants developers to sign in with the company identity provider can build this from a single SAML client. The client's valid redirect URI must be <SonarQubeBaseURL>/oauth2/callback/saml, where the base URL matches exactly how users reach SonarQube, including scheme and host. A mismatch here is the most common reason the handshake fails, so confirm the public URL before creating the client. The SAML flow is started from SonarQube, the browser is redirected to Keycloak, and Keycloak returns a signed assertion to the SonarQube callback. The SonarQube Keycloak SAML guide lists the exact client settings for your SonarQube version.

Two attribute mappers are required: a login mapper and a name mapper. SonarQube uses the login value to match an existing or new account, so decide now which Keycloak attribute will serve as the login, usually the username or a corporate email, and keep it stable because changing it later can create duplicate accounts. The name mapper supplies the display name shown in SonarQube. An email mapper is worth adding for notifications and for matching accounts, and it should map a value that users cannot change themselves.

The groups mapper is what enables just-in-time group sync. SonarQube expects a groups attribute, which Keycloak can produce with a Group list or Role list mapper with the single role attribute option enabled. Groups are then assigned to SonarQube permissions on each sign-in, so the team must decide which Keycloak groups map to which SonarQube groups and who owns that list. Assertion encryption and request signing are optional. If you use them, generate the key pair in the client's Keys tab, convert the private key to PKCS#8, and test both directions in a non-production instance, because a key mismatch will look like a generic sign-in failure. Confirm the SonarQube version and its SAML settings before you commit to either option.

What you need before configuring SAML in Keycloak

The SAML setup touches three things you control: a Keycloak realm, a SonarQube Server instance reachable over HTTPS, and a group model that decides who gets which access. Settle these before you create the client, because the redirect URI and mapper names must match exactly what SonarQube expects.

Keycloak release and realm

Confirm which Keycloak release you run before you start. The current release is 26.8.1, but many teams run an earlier 26.x build, so check your version against the upgrade notes before you copy any screen-based steps. Pick the realm that will hold SonarQube users, ideally a dedicated realm or one that already holds your workforce accounts, so the SAML client and its mappers sit next to the users they serve.

Keycloak docs

Reachable SonarQube base URL

SonarQube builds the SAML redirect URI from its base URL, so the value you configure in Keycloak must match that base URL exactly, including scheme, host and any context path. Serve SonarQube over HTTPS and confirm the hostname resolves for every user browser. A mismatch between http and https, or between a bare hostname and a fully qualified one, is one of the most common causes of failed sign-in redirects.

Admin access to both systems

You need administrative rights in the Keycloak realm to create clients, mappers and keys, and administrator rights in SonarQube to enter the SAML settings and test sign-in. Agree on who holds each role before the change window. Keep at least one local SonarQube administrator account that does not depend on SAML, so a misconfigured identity provider cannot lock every administrator out.

Group mapping decision

Decide which Keycloak groups map to which SonarQube groups before you configure the groups mapper. SonarQube reads a groups attribute from the assertion, so the names in Keycloak become the names SonarQube sees at sign-in. Choose a naming convention, limit the list to groups that need Sonar access, and record who approves each membership. This decision drives the just-in-time group sync behavior you will test later.

Optional signing and encryption keys

Decide early whether you will sign requests or encrypt assertions. Encryption needs a key pair generated in the client's Keys tab, and the private key must be converted to PKCS#8 before SonarQube can use it. Assign an owner for that key, record where it is stored, and plan its rotation. Treating this as an afterthought often delays the change window because the conversion and upload steps need a second review.

SonarQube version confirmation

Confirm the SonarQube Server version you run against the SonarSource documentation before you follow any steps. Setup screens, setting names and supported SAML options can differ between releases, so the guide you use must match your running version. Note the version in your change record, and recheck it if you plan an upgrade during the same quarter.

SonarQube Keycloak guide

Configure the Keycloak SAML client and SonarQube SAML settings

This sequence builds a SAML client in Keycloak that SonarQube Server can trust, sends the attributes SonarQube needs for login and group sync, and then points SonarQube at that identity provider. The result is a working SAML sign-in that a non-admin test user can complete.

  1. Create the SAML client in Keycloak

    In the realm that will serve SonarQube, create a new client with the SAML protocol and set the client ID to the entity ID that SonarQube will present, as shown in the SonarQube Keycloak SAML documentation. Confirm the entity ID with your SonarQube administrator before saving, because a mismatch stops sign-in at the assertion check. Done means the client appears in the client list with the SAML protocol selected.

  2. Set the valid redirect URI for SonarQube

    On the client settings, set the valid redirect URI to your SonarQube base URL followed by /oauth2/callback/saml. Use the exact public address users type into the browser, including the scheme, and avoid a trailing slash mismatch. Done means the URI is saved and matches the value your SonarQube instance will use when it sends the user back after authentication.

  3. Add the login and name attribute mappers

    Add the attribute mappers that SonarQube requires for login and name, mapping the Keycloak user properties to the SAML attribute names listed in the SonarQube documentation. Keep the attribute names exactly as documented, since SonarQube reads them by name. Verification: sign in with a non-admin test user and confirm SonarQube creates or matches the account and shows the expected display name.

  4. Add the groups mapper with single role attribute

    Add a Group list or Role list mapper that emits a groups attribute. If you use a Role list mapper, enable the single role attribute option so that the values arrive as one attribute that SonarQube can read. Assign at least one Keycloak group to the test user. Verification: open the SAML response from a test login, using a browser tool or the client's SAML debug view, and confirm the groups attribute lists the expected group names.

  5. Enter the identity provider settings in SonarQube

    In SonarQube Server, open the SAML authentication configuration and enter the identity provider details from the Keycloak realm, including the SAML descriptor or metadata values the documentation describes, the login URL, and the certificate. Set the attribute names to match the mappers you created. Save the configuration but leave the group sync setting for the next check. Done means SonarQube shows the SAML option on its login page.

  6. Test sign-in with a non-admin user and confirm group sync

    Sign in to SonarQube with the non-admin test user through the Keycloak SAML option. Confirm the account is created just in time, the email and name are correct, and the user receives the permissions tied to the synced group. Check the SonarQube group membership page for the user. Done means the login completes, the user is in the expected group, and an administrator account still works through the local login path.

Which Keycloak attributes map to SonarQube login, name, email and groups

This table compares each SonarQube SAML field with the Keycloak user property, mapper type or group setting that supplies it. Read the Required column first, since SonarSource's login and name mappers must be present for sign-in to work. The main takeaway is that group sync depends on a groups attribute that Keycloak must emit, so confirm that mapper before testing with real users.

FieldRequiredKeycloak sourceWhat to confirm
Login identifierYes (login mapper)Username or a stable user attribute mapped from the user profileThe exact SonarQube attribute name for login in your version's SAML docs, and whether usernames are unique and stable
Display nameYes (name mapper)First name and last name, or a full name attribute from the user profileThe attribute name SonarQube expects for the name field, and how it renders names with missing last names
EmailOptionalEmail property of the Keycloak userWhether your SonarQube version requires or uses the email attribute for account matching or notifications
GroupsOptional (needed for group sync)Group list or Role list mapper with single role attribute enabled, applied to the clientThe attribute name SonarQube reads for groups, and that group names in Keycloak match the SonarQube group names you plan to use
Assertion encryptionOptionalClient Keys tab key pair, with the private key converted to PKCS#8Whether your SonarQube version accepts encrypted assertions and the key format it expects
Request signingOptionalPrivate key in PKCS#8 format supplied on the SonarQube sideThe signing key format and where Keycloak's client signature settings must match SonarQube's configuration

When to enable assertion encryption and request signing

Standard SAML sign-in is the baseline for SonarQube Server with Keycloak. The SAML client needs a valid redirect URI of <SonarQubeBaseURL>/oauth2/callback/saml and the login and name attribute mappers SonarQube requires. Traffic between the browser, Keycloak and SonarQube runs over HTTPS, and the SAML exchange depends on that transport protection rather than on extra keys in the client.

  • Fewer moving parts: No additional key pair is generated in the client's Keys tab, so there is no PKCS#8 conversion step and no encryption certificate to publish.
  • Lower rotation load: Without an encryption key, there is no second certificate that SonarQube must trust and that your team must renew on a schedule.
  • Required mappers still apply: The login and name mappers are needed in this model too, and the groups mapper is needed if you want just-in-time group sync.
  • Suitable starting point: Many teams begin here, confirm sign-in and group behavior, and add encryption later if their review requires it.

Before you settle on this model, confirm with your security team whether their policy requires encrypted assertions, and check the SonarQube Keycloak SAML guide for the exact requirements of your SonarQube version.

How a SonarQube login flows through Keycloak over SAML

The flow starts when a user opens SonarQube in the browser and is redirected to Keycloak, where the SAML client for SonarQube handles authentication. Keycloak returns a SAML response through the user's browser to SonarQube's SAML callback endpoint, and SonarQube reads the login, name, email and groups attributes to create or update the user and apply group membership just in time. Check that the redirect URI matches your SonarQube base URL, that the groups attribute comes from a Group list or Role list mapper with single role attribute enabled, and that the trust boundary between the user network and the identity provider is covered by TLS.

SAML login flow from browser to Keycloak and back to the SonarQube callback endpoint.

Security settings for SonarQube SAML through Keycloak

The SonarQube SAML client sits between your users, your Keycloak realm and your SonarQube Server, so each setting below controls who can sign in and what identity data leaves the realm. Review them together before go-live and again after any change to hostnames, certificates or group structure.

HTTPS on both endpoints

Serve SonarQube and Keycloak over TLS only, and confirm that the SonarQube base URL in the SAML configuration matches the public HTTPS address users reach. SAML responses carry identity assertions, so a plain HTTP leg between the browser and either service exposes sign-in data. Keycloak's production guidance also calls for TLS on all communication, so check the proxy path end to end, not only the public hostname.

Keycloak production guide

Exact redirect URI only

Set the SAML client's valid redirect URI to the single callback path SonarQube documents, <SonarQubeBaseURL>/oauth2/callback/saml, and avoid wildcards or extra entries. A broad redirect list lets a crafted link return a valid assertion to an address you do not control. Recheck this value whenever the SonarQube hostname changes, since a stale entry can also break sign-in.

Protect the PKCS#8 private key

If you enable assertion encryption, the private key that SonarQube uses is the sensitive item, not the public certificate. Store the PKCS#8 file with restricted file permissions, keep it out of shared configuration repositories and limit who can export keys from the client's Keys tab. Record the key's creation date and set a rotation plan, because replacing it requires updating the client and SonarQube together.

Limit groups in assertions

The groups attribute sent to SonarQube should include only the Keycloak groups that SonarQube uses for access decisions. Sending every group a user belongs to exposes internal structure to a third-party application and can grant unintended roles if group names are reused. Confirm which groups the mapper emits by signing in with a test account and inspecting the assertion before you enable group synchronization for all users.

Keep a local administrator

Keep at least one local SonarQube administrator account that does not depend on Keycloak, and record how it is protected and who can use it. If the realm, certificate or client is misconfigured, SAML sign-in fails for everyone, including administrators. Test the local login after go-live and confirm it still works after each change to the SAML settings.

Separate admin and public hostnames

Keycloak's production guide recommends exposing the admin console and Administration REST API on a different hostname or context path from public frontend URLs, and limiting the reverse proxy to the paths sign-in needs. Apply the same discipline to the realm your SonarQube client uses: restrict admin access to a management network, and confirm which paths the proxy forwards before publishing the login endpoint to users.

Common SonarQube SAML failures and their causes

This table lists the failures a team should test for when wiring SonarQube Server to Keycloak over SAML, with the likely cause and fix for each. Read it as a test checklist: reproduce each symptom in a non-production instance before go-live, then confirm the fix against the SonarQube and Keycloak settings in your own environment.

FailureLikely causeFix
Redirect URI mismatch after sign-inThe Keycloak SAML client's valid redirect URI does not exactly match <SonarQubeBaseURL>/oauth2/callback/saml, often because of http versus https, a port, or a trailing slash.Set the valid redirect URI to the exact SonarQube base URL plus /oauth2/callback/saml, then retry sign-in from a clean browser session.
Login fails or user identity is emptyThe login attribute mapper is missing or maps the wrong Keycloak user property, so SonarQube receives no usable login value.Add the required login mapper in the SAML client, map it to the user attribute SonarQube expects, and inspect the SAML response to confirm the value is present.
Display name is blank or wrongThe name attribute mapper is missing or points at an attribute that is empty for some users.Add the name mapper, confirm each test user has the source attribute populated, and check the name value in the assertion.
Email missing from the SonarQube profileNo email mapper is configured, or the user record in Keycloak has no verified email value.Add an email mapper and confirm the user's email is set in Keycloak. Check the SonarQube documentation for whether email is required in your version.
Groups do not appear in SonarQubeThe mapper is a user attribute or other type instead of a Group list or Role list mapper, or single role attribute is not enabled, so the groups attribute is not in the expected form.Use a Group list or Role list mapper named as SonarQube expects, enable single role attribute, and check the assertion for a groups attribute before testing group sync.
Group membership not updated on next sign-inJust-in-time sync only runs when the user signs in, so changes made in Keycloak are not visible until the next login, or the user is not a member of the mapped group.Sign out, sign back in with a test user after changing group membership, and confirm the group name in the assertion matches the SonarQube group name.
Signature or decryption errors after encryption setupThe private key was not converted to PKCS#8, the key pair was not generated in the client's Keys tab, or the SonarQube key does not match the certificate Keycloak uses.Generate the key pair in the client's Keys tab, convert the private key to PKCS#8 as SonarQube documents, and load the matching key on the SonarQube side before enabling encryption.
Assertions rejected as not yet valid or expiredClock skew between SonarQube, Keycloak and the identity path, or a time zone or NTP problem on one host.Synchronize time on both servers with NTP and verify that clock offset is small before troubleshooting SAML settings.
Redirects to the wrong host or broken linksThe SonarQube base URL setting does not match the public address users type, or a reverse proxy passes an internal host name.Set the SonarQube base URL to the public address, match it in the Keycloak client, and test from the same URL users will use.

Questions buyers ask about SonarQube Keycloak SAML setup

How much effort does a SonarQube and Keycloak SAML integration take?

The core integration is a single SAML client in Keycloak, a redirect URI, a few attribute mappers and a SonarQube SAML configuration, so the configuration itself is not large. Effort rises with the number of decisions around it: how groups map to SonarQube permissions, whether assertions are signed or encrypted, how the certificate is exchanged, and how login is tested with real users. Ask any provider to split the quote into design, build, testing and handover so you can see which items your environment drives.

Can our team set up SonarQube SAML with Keycloak without outside help?

Yes, if your team already runs Keycloak and SonarQube and has someone comfortable with SAML concepts. SonarSource documents the Keycloak setup step by step, including the client, the valid redirect URI of the form SonarQube base URL followed by the SAML callback path, and the required login and name mappers. The points that usually need a second look are group synchronization and optional encryption, because a wrong mapper type or key format can cause quiet login or group failures. An outside team is most useful for review, testing against your directory and documenting the result.

What does the work need from our staff?

Plan for a Keycloak administrator who can create clients and mappers, a SonarQube administrator who can configure SAML and groups, and a person who owns the group model in your directory. Security or compliance staff should review the signing and encryption choices and the certificate handling. Someone must also be available to run test sign-ins with accounts from each group, since that is where most mapping problems appear. Confirm these roles and their availability before the build starts.

How long will the integration take in our environment?

Duration depends on how many groups you map, how clean your existing Keycloak realm is, whether you need encryption, and how quickly your change process approves configuration in production. Teams with a test SonarQube instance and a staging Keycloak realm can move faster than teams that must build both. Ask for a timeline tied to a written scope, and confirm your approval windows and test environments before agreeing on dates.

Does group sync with SonarQube require a paid edition?

Confirm this with SonarSource before you commit to a design, because edition features and their names can change between releases. The SonarQube documentation for Keycloak SAML describes group synchronization through a groups attribute from a Group list or Role list mapper with single role attribute enabled. Check the SonarQube Server edition and feature documentation for your version, and ask your SonarSource contact whether group-based permission assignment through SAML is available on the edition you license.

What ongoing work follows the SonarQube and Keycloak SAML setup?

Ongoing work includes reviewing group membership rules as teams change, testing sign-in after SonarQube and Keycloak upgrades, and tracking certificate or key expiry if you use request signing or assertion encryption. If encryption is enabled, the key pair generated in the client's Keys tab and the PKCS#8 private key need a documented rotation procedure. Keycloak also ships releases on a regular cadence, so schedule a test sign-in after each upgrade of either product. Retainer support can cover these tasks if your team does not want to own them.

Should we enable assertion encryption and request signing?

Enable them when your security review requires it or when your SonarQube and Keycloak deployment crosses a trust boundary that calls for signed or encrypted assertions. Encryption requires generating a key pair in the Keycloak client's Keys tab and converting the private key to PKCS#8 for SonarQube, which adds a key to manage. Both options add a configuration step that can break sign-in if mismatched, so test them in a non-production instance first and record who holds the keys.

What DeployOpen delivers for a SonarQube SAML integration

DeployOpen plans and implements the Keycloak SAML client, its mappers and the SonarQube Server SAML settings inside your own infrastructure, so the sign-in path is defined before any user depends on it. The work covers the client with its redirect URI at <SonarQubeBaseURL>/oauth2/callback/saml, the login and name attribute mappers SonarQube requires, and the groups mapping that supports just-in-time group sync. Optional assertion encryption and request signing are included when they are in the agreed scope, including generating the key pair on the client's Keys tab and converting the private key to PKCS#8.

Testing is run with test users before anything reaches your workforce. DeployOpen signs in with users in different groups, checks the name and email values SonarQube stores, confirms that group membership changes take effect at the next sign-in, and checks the failure paths, such as a user outside the mapped groups. Each finding is reported with the setting that caused it and the fix applied, and the flows are retested after changes.

You receive written documentation for your security team covering the Keycloak client settings, mapper definitions, SonarQube configuration, key handling and the test results, so reviewers can check the setup without reverse engineering it. Scope, deliverables and the acceptance tests are agreed in writing before work starts, and a quote follows from that written scope. Confirm with your SonarQube edition and version that the SAML option is available to you, and confirm with your security team who will own the signing key and its rotation after handover.

How DeployOpen scopes and supports this integration

DeployOpen treats Keycloak and SonarQube SAML single sign-on as a fixed-scope engagement inside your own infrastructure. The work covers the Keycloak SAML client, the attribute and group mappers, optional assertion encryption and signing, and the test and handover evidence your team needs to operate the sign-in path.

How we scope

  • Confirm your SonarQube Server base URL, so the SAML client's valid redirect URI matches the callback path exactly.
  • Agree which SonarQube groups map to which Keycloak groups, and who approves changes to that mapping.
  • Decide in writing whether assertion encryption and request signing are in scope, since both need a PKCS#8 key.

How we build

  • Create the Keycloak SAML client with the redirect URI, login and name attribute mappers, and the groups mapper configured as SonarQube expects.
  • Configure the groups attribute from a Group list or Role list mapper with single role attribute enabled, then test just-in-time group sync.
  • If required, generate the key pair in the client's Keys tab, convert the private key to PKCS#8, and verify encrypted assertions end to end.

How we hand over

  • Deliver a written configuration record listing client settings, mappers, group mappings and where key material is stored.
  • Document the sign-in test cases used, including a user with no group membership and a user who changes group.
  • Walk your identity and SonarQube administrators through the steps to add a group, rotate a key and recover admin access.

How we support

  • Scope ongoing support, upgrades and continuous testing as a retainer if you want DeployOpen to keep the integration current.
  • Plan re-testing after Keycloak or SonarQube upgrades, since SAML settings and mapper behavior can change between releases.
  • Ask for the retainer terms, response expectations and included retesting in the written quote before work starts.

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.