# GitHub

To allow users to log in with GitHub credentials, you’ll need to register SonarQube Server as a GitHub App. This will also allow you to configure user, group, and permission provisioning.

{% hint style="warning" %}
Compatibility with OAuth apps is deprecated and will be removed in the future. The use of GitHub Apps is required for automatic provisioning of users and groups. If you’re still using an OAuth app, we recommend [registering SonarQube Server as a GitHub App](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app) and following the configuration steps below. For general information on the differences between OAuth apps and GitHub Apps, see the [GitHub documentation](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps).
{% endhint %}

## Registering SonarQube Server as a GitHub App for authentication and provisioning <a href="#registering-sonarqube-as-a-github-app-for-authentication-and-provisioning" id="registering-sonarqube-as-a-github-app-for-authentication-and-provisioning"></a>

First, you’ll need to [register SonarQube Server as a GitHub App](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app). If you’ve already registered SonarQube Server as a GitHub App (see [setting-up-github-app](https://docs.sonarsource.com/sonarqube-server/10.8/devops-platform-integration/github-integration/setting-up-at-global-level/setting-up-github-app "mention")), you can also use it for user authentication and provisioning.

Configure the following settings in your GitHub App:

* **General** tab:
  * **Homepage URL**: The public URL of your SonarQube Server. For example, `https://sonarqube.mycompany.com`. For security reasons, HTTP is not supported, and you must use HTTPS. The public URL is configured in SonarQube Server at **Administration > General > Server base URL**.
  * **Callback URL**: The public URL of your SonarQube Server. For example, `https://sonarqube.mycompany.com`.
  * **Webhooks**: Deactivate the feature.
* **Permissions & events** tab:

| **Permission**                            | **Access** | **Comment**                                                                                                    |
| ----------------------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------- |
| Repository permissions > Administration   | Read-only  | <p>Only for automatic provisioning.</p><p>After saving, the App owner must validate the permission change.</p> |
| Organization permissions > Administration | Read-only  | <p>Only for automatic provisioning.</p><p>After saving, the App owner must validate the permission change.</p> |
| Organization Permissions > Members        | Read-only  | <p><br></p>                                                                                                    |
| Account permissions > Email addresses     | Read-only  | <p><br></p>                                                                                                    |

* **Install App** tab: Click **Install** and validate the installation on each organization you need.
* During App creation, or under the **Advanced** tab, you can make the App *private* or *public*:
  * Make it *private* if you only have one organization.
  * Make it *public* if you have several organizations from where you need users to authenticate and/or be provisioned. Don’t forget to list those as allowed organizations in SonarQube Server (see below).

## Connecting your GitHub App to SonarQube Server <a href="#connecting-your-github-app-to-sonarqube" id="connecting-your-github-app-to-sonarqube"></a>

**Step 1**: In SonarQube Server, Navigate to **Administration** > **Configuration** > **General Settings** > **Authentication** > **GitHub** and click **Create configuration**.

**Step 2:** Fill the following fields with information from your GitHub App:

* * **Client ID**
  * **Client Secret**
  * **GitHub App ID**
  * **Private Key**

**Step 3:** Fill the **API url** and **WEB url** fields as recommended by GitHub.

**Step 4:** If your GitHub App is public, it is important that you enter the allowed organizations in the **Organizations** field.

{% hint style="warning" %}
For automatic provisioning, not entering the allowed organizations for a public App can let undesired users authenticate to your SonarQube Server instance, as public GitHub Apps can be installed by anyone.

When using Just-in-Time provisioning, if the allowed organizations are not entered, any user with a GitHub account can log in to the SonarQube Server instance, even if the GitHub App used for authentication is private.
{% endhint %}

**Step 5:** Click **Save** **configuration**.

## Choosing the provisioning method <a href="#choosing-the-provisioning-method" id="choosing-the-provisioning-method"></a>

Once you’ve set up your GitHub configuration, you can choose how users and groups are provisioned to SonarQube Server. For an overview of the available provisioning methods, see [overview](https://docs.sonarsource.com/sonarqube-server/10.8/instance-administration/authentication/overview "mention").

**Step 1:** In SonarQube Server, from the **Authentication > GitHub** tab, click **Enable configuration**.

**Step 2:** Select a **provisioning method**. The available options are:

* * **Just-in-Time user and group provisioning (default)**:
    * Users are provisioned when they authenticate through GitHub for the first time if the option **Allow users to sign up** is enabled.
    * User information and group memberships are updated at each authentication.
    * (Optional) You can synchronize GitHub teams with existing SonarQube Server groups of the same name with the **Synchronize teams as groups** option.
  * **Automatic user, group, and permission provisioning** (starting in [Developer Edition](https://www.sonarsource.com/plans-and-pricing/developer/))
    * Users and groups will be synchronized on an hourly basis. The first synchronization happens immediately when you enable the feature.
    * Permissions are synchronized. See below for more information.
    * You can check the status of the synchronization on this configuration page, in the box **Automatic user and group provisioning** box.
    * If needed, you can manually trigger a synchronization by clicking **Synchronize now**.
    * Groups in SonarQube Server are named after the GitHub organizations and teams’ names, ie. *Organization/Team.*
    * The user’s email address is updated only when no address is set in SonarQube Server. Once a new address is set, it is only updated when the user authenticates.

**Step 3:** When you change a setting in your configuration, you can force SonarQube Server to check that it is valid by clicking **Test configuration.**

**Step 4:** Click **Save**.

From the login page, your users can now connect to SonarQube Server using their GitHub accounts by clicking the **Log in with GitHub** button.

## About user permission synchronization <a href="#about-user-permission-synchronization" id="about-user-permission-synchronization"></a>

With automatic provisioning, on top of users and groups, project-level group and user permissions are also synchronized from GitHub. Synchronization happens regularly, and it automatically adds or removes permissions from SonarQube Server.

As part of permission synchronization, you can synchronize the visibility of your projects by enabling the **Provision project visibility** option.

* When enabled, your SonarQube Server project’s visibility will match the corresponding GitHub repository’s visibility.
* When disabled, your SonarQube Server project’s visibility will be set to private, regardless of the GitHub repository’s visibility.

For all GitHub-managed users, permissions can no longer be edited on SonarQube Server GitHub projects. Changes of permissions are handled directly in GitHub.

### Permission mapping <a href="#permission-mapping" id="permission-mapping"></a>

SonarQube Server applies a default permission mapping that covers most use cases. If you have more advanced needs, you can customize this mapping so that each GitHub base role has exactly the SonarQube Server permissions you want. You can also configure permission mapping for GitHub custom roles.

To do this, click on the **Edit mapping** button in the section related to automatic provisioning.

Here is the default permission mapping. The first column lists the GitHub base role, and the first row lists the SonarQube Server permissions.

![](https://312504542-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiJj3TXBdWssTGGg8qK5I%2Fuploads%2Fgit-blob-d4ed2464287b219fe69903e67fcecc11210f47be%2Fe74103e8eb5b84c91fb9874a42b474d87d7f6467.png?alt=media)

{% hint style="info" %}
**Known limitation (GitHub Enterprise only):** When a nested team has a custom role that extends the same base role as its parent team’s custom role, the nested team will use its parent’s custom role instead of its own.
{% endhint %}
