To allow users to log in with GitLab credentials, you'll need to connect SonarQube to a GitLab OAuth 2 application. This will also allow you to configure users and groups.
- First, you'll need a GitLab OAuth 2 application. We recommend creating a dedicated application for authentication and provisioning, but if you're already using one for pull request decoration (see GitLab integration), you can also use it for authentication and provisioning. See the GitLab documentation for information on how to create the application.
- Specify the following settings in your GitLab application:
- Name: Your app's name, such as SonarQube.
- Redirect URI: <Your SonarQube URL>/oauth2/callback/gitlab. For example, https://sonarqube.mycompany.com/oauth2/callback/gitlab.
- Scopes: Select api and read_user.
- Save your application.
GitLab then takes you to the application's page, where you can find your Application ID and Secret.
- In SonarQube, Navigate to Administration > Configuration > General Settings > Authentication > GitLab and click Create configuration.
- Fill the following fields with information from your GitLab application:
- Application ID
- GitLab URL: We recommend using https://gitlab.com. You can also use your own GitLab server URL.
- Synchronize user groups: For each GitLab group they belong to, users will be assigned to a group with the same name (if it exists) in SonarQube.
On SonarQube, groups you want to synchronize must be named according to their GitLab URL:
- Click Save configuration.
Once you've created your GitLab configuration, you can choose how users and groups are provisioned to SonarQube. For an overview of the available provisioning methods, see Authentication and provisioning.
Step 1: In SonarQube, go to Authentication > GitLab and click Enable configuration.
Step 2: Select a provisioning method. The available options are:
- Just-in-Time user and group provisioning (default):
- The Allow users to sign up option allows new users to authenticate. When enabled, users are provisioned when they authenticate through Gitlab for the first time. When disabled, only existing users can authenticate to the server.
- Use Allowed groups to restrict users allowed on SonarQube to certain GitLab groups. Only members of these groups (and sub-groups) will be allowed to authenticate. Enter the group slug as it appears in the GitLab URL, for instance, if the group URL is
https://gitlab.com/my-gitlab-group, then enter
If the allowed groups are not entered, any user with a GitLab account can log in to the SonarQube instance (assuming Allow users to sign up is set to true).
- User information and group memberships are updated at each authentication.
- Automatic user and group provisioning:
- Users and groups are synchronized on an hourly basis. The first synchronization happens immediately when you enable the feature.
- The following information is required:
- Provisioning token: GitLab token used for user provisioning. You can use either a group or a personal access token, as long as it has visibility on the desired groups. The token's scope must include read_api.
- Allowed groups: Only members of these groups (and sub-groups) will be provisioned. Enter the group slug as it appears in the GitLab URL, for example, "my-gitlab-group". Provisioning can only start from a group that has no parent, you can't define a sub-group here.
- You can check the status of the synchronization on this configuration page, in the Automatic user and group provisioning box.
- If needed, you can manually trigger a synchronization by clicking Synchronize now.
- Groups in SonarQube are named after the GitLab groups' names, for example, GroupA/GroupB.
- The user's email address is only set when the user authenticates. Automatic synchronization won't set or update emails.
Step 3: Click Save.
From the login page, your users can now log in to SonarQube using their GitLab accounts by clicking the Log in with GitLab button.