LDAP
You can configure SonarQube Server authentication and authorization to an LDAP server (including the LDAP service of Active Directory) by configuring the correct values in <sonarqubeHome>/conf/sonar.properties
.
The main features are:
- Password checking against the external authentication engine.
- Automatic synchronization of usernames and emails.
- Automatic synchronization of relationships between users and groups (authorization).
- During the first successful authentication, the user account is created in the SonarQube Server database. Each time a user logs into SonarQube, the username and the email are synchronized.
- Group synchronization is an option that will sync SonarQube Server group memberships with the LDAP service.
Apache DS | OpenLDAP | Open DS | Active Directory | |
Anonymous | ||||
Simple | ||||
LDAPS | ||||
DIGEST-MD5 | ||||
CRAM-MD5 | ||||
GSSAPI |
= successfully tested
Setup
- Configure LDAP by editing
<sonarqubeHome>/conf/sonar.properties
(see table below). - Restart SonarQube Server and check the log file for:
INFO org.sonar.INFO Security realm: LDAP ...
INFO o.s.p.l.LdapContextFactory Test LDAP connection: OK - Log in to SonarQube Server.
- On log out users will be presented with a login page (
/sessions/login
), where they can choose to log in as a technical user or a domain user by passing the appropriate credentials.
For SonarScanners, we recommend using manually created technical accounts for authentication against SonarQube Server.
General Configuration
Property | Description | Default value | Required | Example |
sonar.security.realm | Set this to LDAP authenticate first against the external sytem. If the external system is not reachable or if the user is not defined in the external system, authentication will be performed against SonarQube Server's internal database. | none | Yes | LDAP (only possible value) |
sonar.authenticator.downcase | Set to true when connecting to a LDAP server using a case-insensitive setup. | false | No | |
ldap.url | URL of the LDAP server. If you are using ldaps, you should install the server certificate into the Java truststore. | none | Yes | ldap://localhost:10389 |
ldap.bindDn | The username of an LDAP user to connect (or bind) with. Leave this blank for anonymous access to the LDAP directory. | none | No | cn=sonar,ou=users,o=mycompany |
ldap.bindPassword | The password of the user to connect with. Leave this blank for anonymous access to the LDAP directory. | none | No | secret |
ldap.authentication | Possible values: simple , CRAM-MD5 , DIGEST-MD5 , GSSAPI . See the tutorial on authentication mechanisms | simple | No | |
ldap.realm | See Digest-MD5 Authentication, CRAM-MD5 Authentication | none | No | example.org |
ldap.contextFactoryClass | Context factory class. | com.sun.jndi.ldap.LdapCtxFactory | No | |
ldap.StartTLS | Enable use of StartTLS | false | No | |
ldap.followReferrals | Follow referrals or not. See Referrals in the JNDI | true | ||
ldap.saslQop | Quality of protection request | none | No | auth |
ldap.saslStrength | Cryptographic protection request | none | No | medium |
ldap.saslMaxbuf | Maximum receive buffer size | none | No | 16384 |
User Mapping
Property | Description | Default value | Required | Example for Active Directory |
ldap.user.baseDn | Distinguished Name (DN) of the root node in LDAP from which to search for users. | None | Yes | cn=users,dc=example,dc=org |
ldap.user.request | LDAP user request. | (&(objectClass=inetOrgPerson)(uid={login})) | No | (&(objectClass=user)(sAMAccountName={login})) |
ldap.user.realNameAttribute | Attribute in LDAP defining the user’s real name. | cn | No | |
ldap.user.emailAttribute | Attribute in LDAP defining the user’s email. | mail | No |
Group synchronization
Only groups and static groups are supported. Roles and dynamic groups are not supported; this page about Static Vs Dynamic LDAP Group management offers more detail about the differences.
To delege authorization, groups must first be defined in SonarQube Server. See the Group synchronization section on the Overview page for more details. After your groups are created, the following properties must be defined to allow SonarQube Server to automatically synchronize the relationships between users and groups.
Property | Description | Default value | Required | Example for Active Directory |
ldap.group.baseDn | Distinguished Name (DN) of the root node in LDAP from which to search for groups. | none | No | cn=groups,dc=example,dc=org |
ldap.group.request | LDAP group request. | (&(objectClass=groupOfUniqueNames)(uniqueMember={dn})) | No | (&(objectClass=group)(member={dn})) |
ldap.group.idAttribute | Property used to specifiy the attribute to be used for returning the list of user groups in the compatibility mode. | cn | No | sAMAccountName |
Configuration sample
Advanced LDAP Topics
Authentication Methods
Anonymous
- Used when only read-only access to non-protected entries and attributes is needed when binding to the LDAP server.Simple
Simple authentication is not recommended for production deployments not using the LDAP secure protocol since it sends a cleartext password over the network.CRAM-MD5
- The Challenge-Response Authentication Method (CRAM), based on the HMAC-MD5 MAC algorithm (RFC 2195).DIGEST-MD5
- This is an improvement on the CRAM-MD5 authentication method (RFC 2831).GSSAPI
- GSS-API is Generic Security Service API (RFC 2744). One of the most popular security services available for GSS-API is the Kerberos v5, used in Microsoft's Windows 2000 platform.
For a full discussion of LDAP authentication approaches, see RFC 2829 and RFC 2251.
Multiple Servers
To configure multiple servers:
Authentication will be tried on each server, in the order they are listed in the configurations until one succeeds.
Note that all the LDAP servers must be available while (re)starting SonarQube Server.
Migrate users to a new authentication method
If you are changing your delegated authentication method and migrating existing users from your previous authentication method, you can use the api/users/update_identity_provider
web API to update your users' identity provider.
About user and identity provider IDs
To avoid the risk of misidentification, the following identification methods are used on all LDAP setups, including SonarQube Server instances with a single LDAP connection:
- The local login of a new account is made unique with a suffix to the identifier. eg.
login_<additional_id>
. - The name of the External Identity Provider is also made unique with the addition of the server key provided in the configuration, e.g.,
LDAP_<server_key>
where<server_key>
is defined throughldap.servers
property.
Troubleshooting
- Detailed connection logs (and potential error codes received from the LDAP server) are output to SonarQube Server's
<sonarqubeHome>/logs/web.log
, when logging is inDEBUG
mode. - If you experience time outs when running SonarQube Server analysis using LDAP, Java parameters are documented here. Such parameters can be set in
sonar.web.javaAdditionalOpts
in<sonarqubeHome>/conf/sonar.properties
.
Was this page helpful?