You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

delegated-auth.md 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. ---
  2. title: Delegating Authentication
  3. url: /instance-administration/delegated-auth/
  4. ---
  5. SonarQube comes with an onboard user database, as well as the ability to delegate authentication via HTTP Headers, GitHub Authentication, GitLab Authentication, SAML, or LDAP. Each method offers user identity management, group synchronization/mapping, and authentication.
  6. ## Group Mapping
  7. When using group mapping, the following caveats apply regardless of which delegated authentication method is used:
  8. * membership in synchronized groups will override any membership locally configured in SonarQube _at each login_
  9. * membership in a group is synched only if a group with the same name exists in SonarQube
  10. * membership in the default group `sonar-users` remains (this is a built-in group) even if the group does not exist in the identity provider
  11. [[warning]]
  12. |When group mapping is configured, the delegated authentication source becomes the one and only place to manage group membership, and the user's groups are re-fetched with each log in.
  13. ## HTTP Header Authentication
  14. You can delegate user authentication to third-party systems (proxies/servers) using HTTP Header Authentication.
  15. When this feature is activated, SonarQube expects that the authentication is handled prior any query reaching the server.
  16. The tool that handles the authentication should:
  17. * intercept calls to the SonarQube server
  18. * take care of the authentication
  19. * update the HTTP request header with the relevant SonarQube user information
  20. * re-route the request to SonarQube with the appropriate header information
  21. ![HTTP Header Authentication flow](/images/http-header-authentication.png)
  22. All the parameters required to activate and configure this feature are available in SonarQube server configuration file (in _$SONARQUBE-HOME/conf/sonar.properties_).
  23. Using Http header authentication is an easy way integrate your SonarQube deployment with an in-house SSO implementation.
  24. ## GitHub Authentication
  25. You can delegate authentication to GitHub Enterprise using a dedicated GitHub OAuth application. Alternately, if you're using the pull request decoration provided as part of [Developer Edition](https://redirect.sonarsource.com/editions/developer.html) and [above](https://www.sonarsource.com/plans-and-pricing/) you can harness the [GitHub application needed for PR decoration](/instance-administration/github-application/) to also provide authentication.
  26. ### Dedicated GitHub OAuth application
  27. 1. You'll need to first create a GitHub OAuth application. Click [here](https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/) for general instructions:
  28. 1. "Homepage URL" is the public URL to your SonarQube server, for example "https://sonarqube.mycompany.com". For security reasons HTTP is not supported. HTTPS must be used. The public URL is configured in SonarQube at **[Administration -> General -> Server base URL](/#sonarqube-admin#/admin/settings)**
  29. 1. "Authorization callback URL" is <Homepage URL>/oauth2/callback, for example "https://sonarqube.mycompany.com/oauth2/callback"
  30. 1. In SonarQube, navigate to **[Administration > Configuration > General Settings > Security > GitHub](/#sonarqube-admin#/admin/settings?category=security)**:
  31. 1. Set **Enabled** to `true`
  32. 1. Set the **Client ID** to the value provided by the GitHub developer application
  33. 1. Set the **Client Secret** to the value provided by the GitHub developer application
  34. On the login form, the new "Log in with GitHub" button allows users to connect with their GitHub Enterprise accounts.
  35. ### Re-use GitHub PR decoration application
  36. 1. In the GitHub app, in **Permission & events > User permissions**: Add **Read-only** access in **Emails**.
  37. 1. In SonarQube settings, update the **Client ID** and **Client Secret** and use values defined in the GitHub app
  38. If you previously used a dedicated GitHub OAuth application for authentication, it can be removed.
  39. ## GitLab Authentication
  40. You can delegate authentication to GitLab using a dedicated GitLab OAuth application.
  41. Create a GitLab OAuth application from your GitLab account. Click [here](https://docs.gitlab.com/ee/integration/oauth_provider.html/) for general instructions.
  42. 1. In the **Name** text box, name your app SonarQube.
  43. 1. In the **Redirect URI** text box, enter your SonarQube URL with the path `/oauth2/callback/gitlab/`. For example, `https://YourSonarQubeURL.com/oauth2/callback/gitlab/`.
  44. 1. Under **Scopes**, select **api**.
  45. After saving your application, GitLab gives you your **Application ID** and **Secret**. Keep these at hand, open your SonarQube instance, and navigate to **[Administration > Configuration > General Settings > Security](/#sonarqube-admin#/admin/settings?category=security/)** to finish setting up GitLab authentication:
  46. 1. Set **Enabled** to `true`.
  47. 1. Enter the Application ID provided by GitLab in the **Application ID** text box.
  48. 1. Enter the Secret provided by GitLab in the **Secret** text box.
  49. On the login form, the new "Log in with GitLab" button allows users to connect with their GitLab accounts.
  50. ### GitLab group synchronization
  51. Setting **Synchronize groups** to `true` associates GitLab groups with SonarQube groups of the same name (if they exist). GitLab user's inherit membership to subgroups from parent groups so a user that is a member of a group will also be a member of the group's subgroups.
  52. To synchronize a GitLab group or subgroup with a SonarQube group, name the SonarQube group with the full path of the of the GitLab group or subgroup URL. For example, say you have a GitLab group named "My Group" with a subgroup named "My Subgroup" and the subgroup URL is `https://YourGitLabURL.com/my-group/my-subgroup`. You would name your SonarQube group `my-group/my-subgroup` to synchronize it with your GitLab subgroup.
  53. ## SAML Authentication
  54. You can delegate authentication to a SAML 2.0 Identity Provider using SAML Authentication.
  55. ### Limitations
  56. * SAML requests are not signed. Client signature validation should be disabled in the Identity Provider.
  57. * SAML encrypted responses are not supported. SAML encryption should be disabled in the Identity Provider.
  58. ### Example: Using Keycloak as a SAML Identity Provider
  59. The following example may be useful if you're using Keycloak as a SAML Identity Provider. If you're not using Keycloak, your settings are likely to be different.
  60. [[collapse]]
  61. | ## In the Keycloak server, create a new SAML client
  62. | Create a new client
  63. |
  64. | 1. "Client ID" is something like "sonarqube"
  65. | 1. "Client Protocol" must be set to "saml"
  66. | 1. "Client SAML Endpoint" can be left empty
  67. |
  68. | Configure the new client
  69. |
  70. | 1. in Settings
  71. | 1. Set"Client Signature Required" to OFF
  72. | 1. Set "Valid Redirect URIs" to "<Your SonarQube URL>/oauth2/callback/*, E.G https://sonarqube.mycompany.com/oauth2/callback/saml
  73. | 1. in Client Scopes > Default Client Scopes , remove "role_list" from "Assigned Default Client Scopes" (to prevent the error `com.onelogin.saml2.exception.ValidationError: Found an Attribute element with duplicated Name` during authentication)
  74. | 1. In Mappers create a mapper for each user attribute (Note that values provided below for Name, SAML Attribute Name, Role Attribute Name are only example values):
  75. | 1. Create a mapper for the login:
  76. | * Name: Login
  77. | * Mapper Type: User Property
  78. | * Property: Username (Note that the login should not contain any special characters other than `.-_@` to meet SonarQube restrictions.)
  79. | * SAML Attribute Name: login
  80. | 1. Create a mapper for the name:
  81. | * Name: Name
  82. | * Mapper Type: User Property
  83. | * User Attribute: Username (It can also be another attribute you would previously have specified for the users)
  84. | * SAML Attribute Name: name
  85. | 1. (Optional) Create a mapper for the email:
  86. | * Name: Email
  87. | * Mapper Type: User Property
  88. | * Property: Email
  89. | * SAML Attribute Name: email
  90. | 1. (Optional) Create a mapper for the groups (If you rely on a list of roles defined in "Roles" of the Realm (not in "Roles" of the client)):
  91. | * Name: Groups
  92. | * Mapper Type: Role list
  93. | * Role Attribute Name: groups
  94. | * Single Role Attribute: ON
  95. | 1. If you rely on a list of groups defined in "Groups":
  96. | * Name: Groups
  97. | * Mapper Type: Group list
  98. | * Role Attribute Name: groups
  99. | * Single Role Attribute: ON
  100. | * Full Group Path: OFF
  101. |
  102. | Download the XML configuration file from Keycloak.
  103. [[collapse]]
  104. | ## In SonarQube, Configure SAML authentication
  105. | Go to **[Administration > Configuration > General Settings > Security > SAML](/#sonarqube-admin#/admin/settings?category=security)**
  106. | * **Enabled** should be set to true
  107. | * **Application ID** is the value of the "Client ID" you set in Keycloak (for example "sonarqube")
  108. | * **Provider ID** is the value of the "EntityDescriptor" > "entityID" attribute in the XML configuration file (for example "http://keycloak:8080/auth/realms/sonarqube" where sonarqube is the name of the realm)
  109. | * **SAML login url** is the value of "SingleSignOnService" > "Location" attribute in the XML configuration file (for example "http://keycloak:8080/auth/realms/sonarqube/protocol/saml")
  110. | * **Provider certificate** is the value you get from *Reaml Settings* -> *Keys* -> click on the *Certificate* button
  111. | * **SAML user login attribute** is the value set in the login mapper in "SAML Attribute Name"
  112. | * **SAML user name attribute** is the value set in the name mapper in "SAML Attribute Name"
  113. | * (Optional) **SAML user email attribute** is the value set in the email mapper in "SAML Attribute Name"
  114. | * (Optional) **SAML group attribute** is the value set in the groups mapper in "Role/Group Attribute Name"
  115. |
  116. | In the login form, the new button "Log in with SAML" allows users to connect with their SAML account.
  117. ## LDAP Authentication
  118. You can configure SonarQube authentication and authorization to an LDAP server (including LDAP Service of Active Directory) by configuring the correct values in _$SONARQUBE-HOME/conf/sonar.properties_.
  119. The main features are:
  120. * Password checking against the external authentication engine.
  121. * Automatic synchronization of usernames and emails.
  122. * Automatic synchronization of relationships between users and groups (authorization).
  123. * Ability to authenticate against both the external and the internal authentication systems. There is an automatic fallback on SonarQube internal system if the LDAP server is down.
  124. * During the first authentication trial, if the user's password is correct, the SonarQube database is automatically populated with the new user. Each time a user logs into SonarQube, the username, the email and the groups this user belongs to that are refreshed in the SonarQube database. You can choose to have group membership synchronized as well, but this is not the default.
  125. &nbsp;| Apache DS | OpenLDAP | Open DS | Active Directory
  126. ----|-----------|----------|---------|-----------------
  127. Anonymous | ![](/images/check.svg) |![](/images/check.svg) |![](/images/check.svg) | &nbsp;
  128. Simple|![](/images/check.svg)|![](/images/check.svg)|![](/images/check.svg)|![](/images/check.svg)
  129. LDAPS|![](/images/check.svg)|![](/images/check.svg)| |![](/images/check.svg)
  130. DIGEST-MD5|![](/images/check.svg)| |![](/images/check.svg)|![](/images/check.svg)
  131. CRAM-MD5|![](/images/check.svg)| |![](/images/check.svg)|![](/images/check.svg)
  132. GSSAPI|![](/images/check.svg)| | |
  133. ![](/images/check.svg) = successfully tested
  134. ### Setup
  135. 1. Configure LDAP by editing _$SONARQUBE-HOME/conf/sonar.properties_ (see table below)
  136. 2. Restart the SonarQube server and check the log file for:
  137. ```
  138. INFO org.sonar.INFO Security realm: LDAP ...
  139. INFO o.s.p.l.LdapContextFactory Test LDAP connection: OK
  140. ```
  141. 1. Log into SonarQube
  142. 1. On logout users will be presented a login page (_/sessions/login_), where they can choose to login as technical user or a domain user by passing appropriate credentials
  143. From SonarScanners, we recommend using [local technical users](/instance-administration/security/) for authentication against SonarQube Server.
  144. **General Configuration**
  145. Property|Description|Default value|Required|Example
  146. ---|---|---|---|---
  147. `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's internal database.| none |Yes|`LDAP` (only possible value)
  148. `sonar.authenticator.downcase`|Set to true when connecting to a LDAP server using a case-insensitive setup.|`false`|No
  149. `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`
  150. `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`
  151. `ldap.bindPassword`|The password of the user to connect with. Leave this blank for anonymous access to the LDAP directory.|none|No|`secret`
  152. `ldap.authentication`|Possible values: `simple`, `CRAM-MD5`, `DIGEST-MD5`, `GSSAPI`. See [the tutorial on authentication mechanisms](http://java.sun.com/products/jndi/tutorial/ldap/security/auth.html)|`simple`|No
  153. `ldap.realm`|See [Digest-MD5 Authentication](http://java.sun.com/products/jndi/tutorial/ldap/security/digest.html), [CRAM-MD5 Authentication](http://java.sun.com/products/jndi/tutorial/ldap/security/crammd5.html)| none|No|example.org
  154. `ldap.contextFactoryClass`|Context factory class.|`com.sun.jndi.ldap.LdapCtxFactory`|No
  155. `ldap.StartTLS`|Enable use of `StartTLS`|`false`|No
  156. `ldap.followReferrals`|Follow referrals or not. See [Referrals in the JNDI](http://docs.oracle.com/javase/jndi/tutorial/ldap/referral/jndi.html)|`true`
  157. **User Mapping**
  158. Property|Description|Default value|Required|Example for Active Directory
  159. ---|---|---|---|---
  160. `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`
  161. `ldap.user.request`|LDAP user request.|`(&(objectClass=inetOrgPerson)(uid={login}))`|No|`(&(objectClass=user)(sAMAccountName={login}))`
  162. `ldap.user.realNameAttribute`|Attribute in LDAP defining the user’s real name.|`cn`|No|
  163. `ldap.user.emailAttribute`|Attribute in LDAP defining the user’s email.|`mail`|No|
  164. **Group Mapping**
  165. Only groups (not roles) and static groups (not dynamic groups) are supported. Click [here](http://identitycontrol.blogspot.fr/2007/07/static-vs-dynamic-ldap-groups.html) for more information.
  166. For the delegation of authorization, [groups must be first defined in SonarQube](/instance-administration/security/). Then, the following properties must be defined to allow SonarQube to automatically synchronize the relationships between users and groups.
  167. Property|Description|Default value|Required|Example for Active Directory
  168. ---|---|---|---|---
  169. `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`
  170. `ldap.group.request`|LDAP group request.|`(&(objectClass=groupOfUniqueNames)(uniqueMember={dn}))`|No|`(&(objectClass=group)(member={dn}))`
  171. `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`
  172. ### Sample Configuration
  173. ```
  174. # LDAP configuration
  175. # General Configuration
  176. sonar.security.realm=LDAP
  177. ldap.url=ldap://myserver.mycompany.com
  178. ldap.bindDn=my_bind_dn
  179. ldap.bindPassword=my_bind_password
  180. # User Configuration
  181. ldap.user.baseDn=ou=Users,dc=mycompany,dc=com
  182. ldap.user.request=(&(objectClass=inetOrgPerson)(uid={login}))
  183. ldap.user.realNameAttribute=cn
  184. ldap.user.emailAttribute=mail
  185. # Group Configuration
  186. ldap.group.baseDn=ou=Groups,dc=sonarsource,dc=com
  187. ldap.group.request=(&(objectClass=posixGroup)(memberUid={uid}))
  188. ```
  189. ## Advanced LDAP Topics
  190. ### Authentication Methods
  191. * **`Anonymous`** - Used when only read-only access to non-protected entries and attributes is needed when binding to the LDAP server.
  192. * **`Simple`** Simple authentication is not recommended for production deployments not using the ldaps secure protocol since it sends a cleartext password over the network.
  193. * **`CRAM-MD5`** - The Challenge-Response Authentication Method (CRAM) based on the HMAC-MD5 MAC algorithm ([RFC 2195](http://tools.ietf.org/html/rfc2195)).
  194. * **`DIGEST-MD5`** - This is an improvement on the CRAM-MD5 authentication method ([RFC 2831](http://www.ietf.org/rfc/rfc2831.txt)).
  195. * **`GSSAPI`** - GSS-API is Generic Security Service API ([RFC 2744](http://www.ietf.org/rfc/rfc2744.txt)). One of the most popular security services available for GSS-API is the Kerberos v5, used in Microsoft's Windows 2000 platform.
  196. For a full discussion of LDAP authentication approaches, see [RFC 2829](http://www.ietf.org/rfc/rfc2829.txt) and [RFC 2251](http://www.ietf.org/rfc/rfc2251.txt).
  197. ### Multiple Servers
  198. To configure multiple servers:
  199. ```
  200. # List the different servers
  201. ldap.servers=server1,server2
  202. # Configure server1
  203. ldap.server1.url=ldap://server1:1389
  204. ldap.server1.user.baseDn=dc=dept1,dc=com
  205. ...
  206. # Configure server2
  207. ldap.server2.url=ldap://server2:1389
  208. ldap.server2.user.baseDn=dc=dept2,dc=com
  209. ...
  210. ```
  211. Authentication will be tried on each server, in the order they are listed in the configurations, until one succeeds. User/Group mapping will be performed against the first server on which the user is found.
  212. Note that all the LDAP servers must be available while (re)starting the SonarQube server.
  213. ### Troubleshooting
  214. * Detailed connection logs (and potential error codes received from LDAP server) are output to SonarQube's _$SONARQUBE_HOME/logs/web.log_, when logging is in `DEBUG` mode.
  215. * Time out when running SonarQube analysis using LDAP
  216. Java parameters are documented here: http://docs.oracle.com/javase/jndi/tutorial/ldap/connect/config.html. Such parameters can be set in `sonar.web.javaAdditionalOpts` in _$SONARQUBE-HOME/conf/sonar.properties_.