Tutorial: Azure AD SSO integration with SonarQube

In this tutorial, you'll learn how to integrate SonarQube with Azure Active Directory (Azure AD). When you integrate SonarQube with Azure AD, you can:

  • Control in Azure AD who has access to SonarQube.
  • Enable your users to be automatically signed-in to SonarQube with their Azure AD accounts.
  • Manage your accounts in one central location - the Azure portal.

Prerequisites

To get started, you need the following items:

  • An Azure AD subscription. If you don't have a subscription, you can get a free account.
  • SonarQube single sign-on (SSO) enabled subscription.

Note

Help on installing SonarQube can be found in the online documentation.

Scenario description

In this tutorial, you configure and test Azure AD SSO in a test environment.

  • SonarQube supports SP initiated SSO.

Note

Identifier of this application is a fixed string value so only one instance can be configured in one tenant.

To configure the integration of SonarQube into Azure AD, you need to add SonarQube from the gallery to your list of managed SaaS apps.

  1. Sign in to the Azure portal using either a work or school account, or a personal Microsoft account.
  2. On the left navigation pane, select the Azure Active Directory service.
  3. Navigate to Enterprise Applications and then select All Applications.
  4. To add new application, select New application.
  5. In the Add from the gallery section, type SonarQube in the search box.
  6. Select SonarQube from results panel and then add the app. Wait a few seconds while the app is added to your tenant.

Configure and test Azure AD SSO for SonarQube

Configure and test Azure AD SSO with SonarQube using a test user called B.Simon. For SSO to work, you need to establish a link relationship between an Azure AD user and the related user in SonarQube.

To configure and test Azure AD SSO with SonarQube, perform the following steps:

  1. Configure Azure AD SSO - to enable your users to use this feature.
    1. Create an Azure AD test user - to test Azure AD single sign-on with B.Simon.
    2. Assign the Azure AD test user - to enable B.Simon to use Azure AD single sign-on.
  2. Configure SonarQube SSO - to configure the single sign-on settings on application side.
    1. Create SonarQube test user - to have a counterpart of B.Simon in SonarQube that is linked to the Azure AD representation of user.
  3. Test SSO - to verify whether the configuration works.

Configure Azure AD SSO

Follow these steps to enable Azure AD SSO in the Azure portal.

  1. In the Azure portal, on the SonarQube application integration page, find the Manage section and select single sign-on.

  2. On the Select a single sign-on method page, select SAML.

  3. On the Set up single sign-on with SAML page, click the pencil icon for Basic SAML Configuration to edit the settings.

    Edit Basic SAML Configuration

  4. On the Basic SAML Configuration section, perform the following steps:

    a. In the Reply URL text box, type a URL using the following pattern: https://sonar.<companyspecificurl>.io/oauth2/callback/saml

    b. In the Sign-on URL text box, type one of the following URLs:

    • For Production Environment

      https://servicessonar.corp.microsoft.com/

    • For Dev Environment

      https://servicescode-dev.westus.cloudapp.azure.com

    Note

    This value is not real. Update the value with actual Reply URL which are explained later in the tutorial.

  5. On the Set up single sign-on with SAML page, in the SAML Signing Certificate section, find Certificate (Base64) and select Download to download the certificate and save it on your computer.

    The Certificate download link

  6. On the Set up SonarQube section, copy the appropriate URL(s) based on your requirement.

    Copy configuration URLs

Create an Azure AD test user

In this section, you'll create a test user in the Azure portal called B.Simon.

  1. From the left pane in the Azure portal, select Azure Active Directory, select Users, and then select All users.
  2. Select New user at the top of the screen.
  3. In the User properties, follow these steps:
    1. In the Name field, enter B.Simon.
    2. In the User name field, enter the username@companydomain.extension. For example, B.Simon@contoso.com.
    3. Select the Show password check box, and then write down the value that's displayed in the Password box.
    4. Click Create.

Assign the Azure AD test user

In this section, you'll enable B.Simon to use Azure single sign-on by granting access to SonarQube.

  1. In the Azure portal, select Enterprise Applications, and then select All applications.
  2. In the applications list, select SonarQube.
  3. In the app's overview page, find the Manage section and select Users and groups.
  4. Select Add user, then select Users and groups in the Add Assignment dialog.
  5. In the Users and groups dialog, select B.Simon from the Users list, then click the Select button at the bottom of the screen.
  6. If you are expecting a role to be assigned to the users, you can select it from the Select a role dropdown. If no role has been set up for this app, you see "Default Access" role selected.
  7. In the Add Assignment dialog, click the Assign button.

Configure SonarQube SSO

  1. Open a new web browser window and sign into your SonarQube company site as an administrator.

  2. Click on Administration > Configuration > Security and go to the SAML Plugin perform the following steps.

  3. Copy the following details from the IdP metadata and paste them into the corresponding text fields in the SonarQube plugin.

    1. IdP Entity ID
    2. Login URL
    3. X.509 Certificate
  4. Save all the details.

    saml plugin IDP

  5. On the SAML page, perform the following steps:

    Sonarqube configuration

    a. Toggle the Enabled option to yes.

    b. In Application ID text box, enter the name like sonarqube.

    c. In Provider Name text box, enter the name like SAML.

    d. In Provider ID text box, paste the value of Azure AD Identifier, which you have copied from Azure portal.

    e. In SAML login url text box, paste the value of Login URL, which you have copied from Azure portal.

    f. Open the Base64 encoded certificate in notepad, copy its content and paste it into the Provider certificate text box.

    g. In SAML user login attribute text box, enter the value http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name.

    h. In SAML user name attribute text box, enter the value http://schemas.microsoft.com/identity/claims/displayname.

    i. In SAML user email attribute text box, enter the value http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name.

    j. Click Save.

Create SonarQube test user

In this section, you create a user called B.Simon in SonarQube. Work with SonarQube Client support team to add the users in the SonarQube platform. Users must be created and activated before you use single sign-on.

Test SSO

In this section, you test your Azure AD single sign-on configuration with following options.

  • Click on Test this application in Azure portal. This will redirect to SonarQube Sign-on URL where you can initiate the login flow.

  • Go to SonarQube Sign-on URL directly and initiate the login flow from there.

  • You can use Microsoft My Apps. When you click the SonarQube tile in the My Apps, this will redirect to SonarQube Sign-on URL. For more information about the My Apps, see Introduction to the My Apps.

Next steps