RealmDeployDocs
GuidesSingle sign-on for apps

Keycloak SSO for SonarQube

Sign in to SonarQube Server or Community Build with Keycloak over SAML, with login, name, email and group attributes for just-in-time group sync.

SonarQube delegates sign-in to Keycloak over SAML 2.0. It does not support generic OpenID Connect, so SAML is the way to connect it to Keycloak. SAML sign-in is part of every SonarQube Server edition and of SonarQube Community Build; SCIM provisioning is only in Enterprise and Data Center editions.

Checked against the SonarQube Server 2026.5 and SonarQube Community Build docs and Keycloak 26.8 on 25 November 2026. The steps follow SonarQube's own page for Keycloak.

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

Before you start

Set the Server base URL in SonarQube under Administration → Configuration → General settings → General → General, for example https://sonarqube.example.com. SonarQube builds its SAML callback from it, and its docs ask for HTTPS when sign-in is delegated.

In Keycloak

Create the SAML client

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

SettingValue
Client typeSAML
Client IDsonarqube. No spaces. SonarQube calls this value its Application ID.
Valid redirect URIshttps://sonarqube.example.com/oauth2/callback/saml

Choose Save.

Then, on the client's Keys tab, turn Client signature required off. It is on by default, and SonarQube's page asks for it off. Leave Sign documents on the Settings tab on, which is the default.

Add the attribute mappers

  1. On the sonarqube client, open the Client scopes tab and choose sonarqube-dedicated.
  2. For each row, choose Configure a new mapper (or Add mapper → By configuration), pick User Property, fill it in and save:
NamePropertySAML Attribute NameNeeded by SonarQube
LoginusernameloginYes
Nameusername, or another user property such as firstNamenameYes
EmailemailemailNo

SonarQube allows only letters, digits and ., -, _ and @ in a login, so usernames with other characters fail.

The group mapper is in Groups and roles.

Get the IdP values

Open Realm settings → General and follow the SAML 2.0 Identity Provider Metadata link at the bottom, or open it directly:

https://auth.example.com/realms/acme/protocol/saml/descriptor

You need three values from it. The SAML metadata viewer shows them, and the SAML certificate extractor pulls out the certificate.

ValueWhere in the metadataFor your realm
Entity IDEntityDescriptor → entityIDhttps://auth.example.com/realms/acme
Sign-in URLSingleSignOnService → Locationhttps://auth.example.com/realms/acme/protocol/saml
CertificateX509CertificateThe realm's signing certificate, also under Realm settings → Keys, RS256 row, Certificate

In SonarQube

Open Administration → Configuration → General settings → Authentication → SAML, choose Create Configuration, and fill in:

FieldValue
Application IDsonarqube
Provider NameKeycloak, the label on SonarQube's login button
Provider IDhttps://auth.example.com/realms/acme
SAML login URLhttps://auth.example.com/realms/acme/protocol/saml
Identity provider certificateThe realm certificate
SAML user login attributelogin
SAML user name attributename
SAML user email attributeemail
SAML group attributegroups, only with the group mapper below

Save the configuration and choose Test Configuration. A new tab shows whether sign-in worked and which attributes arrived. When the test passes, choose Enable configuration.

SonarQube supports only sign-in started from SonarQube, not from Keycloak. It also does not support SAML single logout: signing out of SonarQube leaves the Keycloak session open.

Groups and roles

SonarQube's just-in-time provisioning creates each user at first sign-in and updates their group memberships at every sign-in. It does not create groups.

  1. In SonarQube, create the groups under Administration → Security → Groups with exactly the names used in Keycloak, case included, and give them permissions.
  2. In Keycloak, add one more mapper to sonarqube-dedicated with Add mapper → By configuration. Use one of these:
Your groups live inMapper typeNameGroup or Role attribute nameSingle Group or Single Role AttributeFull group path
Keycloak GroupsGroup listGroupsgroupsOnOff
Realm Roles (not client roles)Role listGroupsgroupsOnn/a
  1. In SonarQube, set SAML group attribute to groups.

Once group sync is on, Keycloak is the only place to manage memberships: memberships added by hand in SonarQube are reset at the next sign-in. Every user stays in the built-in sonar-users group.

SonarQube's docs recommend renaming the built-in sonar-administrators group when group sync is used: a Keycloak group with that name would otherwise give its members admin rights.

Optional: signed requests and encrypted assertions

SonarQube can sign its requests and Keycloak can encrypt its assertions. Both use one key pair.

  1. In Keycloak, on the client's Keys tab, enable Encrypt assertions in Encryption keys config and choose Generate. Your browser downloads private.key. Keycloak keeps only the certificate. Keycloak's docs mark generating keys as deprecated and recommend making the key pair yourself and uploading only the certificate; either way SonarQube needs the private key.
  2. Convert the key to PKCS#8 on one line, as SonarQube's page shows:
echo -e "-----BEGIN RSA PRIVATE KEY-----\n$(cat private.key)\n-----END RSA PRIVATE KEY-----" > newprivate.key
openssl pkcs8 -topk8 -in newprivate.key -out pkcs8.key -nocrypt
tr -d "\n\r" < pkcs8.key
  1. In SonarQube, edit the SAML configuration: paste the certificate from Encryption keys config into Service provider certificate and the one-line key into Service provider private key.
  2. To sign requests too, turn Sign requests on in SonarQube. SonarQube's page asks for nothing more in Keycloak for this, and keeps Client signature required off.
  3. Choose Save configuration, then Test Configuration.

Delete private.key and pkcs8.key from your machine afterwards.

Test it

  1. Open https://sonarqube.example.com in a private window. The login form now has a SAML button labeled with your Provider Name. Choose it.
  2. Sign in as a test user. SonarQube creates the user on first sign-in.
  3. As an administrator, open Administration → Security → Groups and check that the user is in the groups that exist both in Keycloak and in SonarQube.
  4. To see the assertion, copy the SAMLResponse form field from your browser's network tab into the SAML response decoder and check the login, name, email and groups attributes.

Common errors

ErrorCauseFix
Keycloak shows Invalid requesterClient signature required is on, or Application ID differs from the Client ID.Turn Client signature required off and make both IDs the same.
Keycloak shows Invalid redirect uriSonarQube sent a callback that is not in Valid redirect URIs, often because Server base URL is not set or is http://.Set Server base URL and list https://sonarqube.example.com/oauth2/callback/saml exactly.
Found an Attribute element with duplicated NameKeycloak's default role_list client scope sends one Role attribute per role. SonarQube's docs for earlier releases name this error.On the client's Client scopes tab, remove role_list.
Test Configuration reports a missing login or nameThe mapper's SAML Attribute Name differs from the SonarQube field.Use login and name on both sides. Check the attributes with the SAML attribute reference.
Signature validation failsThe certificate in SonarQube is not the realm's current signing certificate.Copy it again from the IdP metadata or Realm settings → Keys.
Groups do not appearThe group does not exist in SonarQube, the names differ in case, or Full group path is on.Create the group in SonarQube with the exact name and turn Full group path off.

FAQ

Can I use OpenID Connect instead?

No. SonarQube delegates sign-in through HTTP headers, GitHub, GitLab, Bitbucket Cloud, SAML or LDAP, not generic OpenID Connect. With Keycloak, use SAML.

Is SAML available in Community Build?

Yes. SonarQube's feature table lists SAML single sign-on in Community Build and in SonarQube Server. SCIM provisioning, which also removes users, needs Enterprise or Data Center edition and supports only Microsoft Entra ID and Okta.

Does Keycloak need an outgoing connection to SonarQube?

No. Sign-in runs through the browser, and SonarQube does not use SAML single logout.

Sources

On this page