This version of the SonarQube documentation is no longer maintained. It relates to a version of SonarQube that is not active.

TLS certificates on client side

If your SonarQube Server instance is secured, add the self-signed certificate to the CI/CD host. If mutual TLS is used, an additional setup is required.

If your SonarQube Server instance is Securing SonarQube Server behind a proxy and a self-signed certificate then you must add the self-signed certificate to the trusted CA certificates of the SonarScanner.

In addition, if mutual TLS is used then you must define the access to the client certificate at the SonarScanner level.

Managing the self-signed server certificate

Introduction to server authentication

During the TLS authentication of the server, the client requests the server certificate from the server and verifies that this certificate is signed by a CA it trusts by checking its TrustStore. In case a self-signed server certificate is used, it must be added to the TrustStore of the client. The figure below shows the certificates involved in the authentication of SonarQube Server by the SonarScanner.

Adding the self-signed server certificate to the trusted CA certificates

For all recent scanners, a common SSL configuration

A common configuration for all recent scanners

We are aiming to simplify the SSL configuration for all scanners. This is a work in progress and not all scanners are updated, but we recommend always following those generic steps to be future-proof, and then look at each scanner-specific guidelines on top of it.

All scanners should support a PKCS #12 keystore containing the server or CA certificates to trust (a.k.a. the TrustStore).

  • The default location for the TrustStore is $SONAR_USER_HOME/ssl/truststore.p12 (default value for SONAR_USER_HOME is ~/.sonar). This location can be overridden using the scanner property sonar.scanner.truststorePath

  • The default password for the TrustStore is changeit. This password can be overridden using the property sonar.scanner.truststorePassword

Please see the Using the scanner page in Begin step command line parameters for more details about adding these to your .NET project.

SonarScanner for .NET version 10.0 and newer

If you have specified the TrustStore password in the begin step, you must also specify it in the end step. For more details, see the list of Using the scanner and Using the scanner command line parameters.

The SonarScanner for .NET 10.0+ does not support a certificate revocation list (CRL) when the issuing certificate authority is given via the TrustStore file. This means that revoked certificates will still be trusted when the issuing certificate is given via the TrustStore file.

You can still install the Certificate Authority certificate in your system TrustStore to have CRL support:

  • On Linux and MacOS:

    1. Copy the self-signed server certificate to /usr/local/share/ca-certificates

    2. Run sudo update-ca-certificates

  • On Windows: use certutil. Here is an example:

certutil -addstore -f "ROOT" <path/to/certificate>
When running the SonarQube scan GitHub Action

If you use the sonarqube-scan-action for your GitHub Action and your SonarQube Server instance has certificates that need to be recognized by the GitHub runner, you’ll need to set the SONAR_ROOT_CERT environment variable in GitHub.

To do this, go to your GitHub repository > Settings > Secrets and Variables and add the SONAR_ROOT_CERT environment variable in PEM format. You can also add it at the level of your GitHub organization (recommended).

Due to a known GitHub issue, if your GitHub Action v4 and above

  • uses SONAR_ROOT_CERT

  • and is executed in a containerized environment, for example when the job running the action declares container: <docker-image-name>

you need to explicitly set the SONAR_USER_HOME environment variable to be the "$HOME/.sonar".

You can do that by adding the following step before executing the action:

# Workaround for https://github.com/actions/runner/issues/863

- name: Workaround for containerized environments

  run: echo "SONAR_USER_HOME=$HOME/.sonar" >> $GITHUB_ENV

- name: Run sonar analysis

  uses: SonarSource/sonarqube-scan-action@<action version>

  ...
If using Azure DevOps

If you have integrated SonarQube Server with Azure DevOps, define the following environment variable to add the server self-signed certificate:

  • Key: NODE_EXTRA_CA_CERTS

  • Value: path to the certificate

For SonarScanner for .NET <=9.2

*Note that the SonarScanner for .NET version 9.2 was deprecated and should not be used.

For scanner versions 9.1 and earlier

Add the self-signed server certificate to the operating system truststore:

  • On Linux and MacOS:

    1. Copy the self-signed server certificate to /usr/local/share/ca-certificates

    2. Run sudo update-ca-certificates

  • On Windows: use certutil. Here is an example:

certutil -addstore -f "ROOT" <path/to/certificate>

When using certstores, you must disable JRE provisioning and use the SonarScanner for CLI logic. Add the self-signed certificate to the Java TrustStore as explained below in For SonarScanner for Maven, Gradle, CLI < 6.0 , or NPM < 4.0.

For SonarScanner for Maven, Gradle, CLI < 6.0 , or NPM < 4.0

For SonarScanners Maven, Gradle, CLI 5.0.1 and earlier, or NPM 3.5 and earlier

These scanners are still relying on the Java VM for the SSL configuration.

You can either:

  • Insert your certificate in the default JVM truststore (something like \jre\lib\security\cacerts). To add the self-signed server certificate to the default truststore, use the JVM tool keytool. The instructions depend on your operating system and you will find many resources online, such as this one for Linux.

    See also: Advanced installation

  • Provide a custom Java truststore by using the following properties:

    • javax.net.ssl.trustStore: path to the truststore file (pkcs12 format is recommended)

    • javax.net.ssl.trustStorePassword: password of the truststore.

If running the scanner with Docker

There is no Docker image for the SonarScanner for .NET therefore, this section does not apply.

If you need to configure a self-signed certificate for the scanner to communicate with your SonarQube Server instance, the preferred way is to mount a folder containing a PKCS #12 file named truststore.p12 (default password changeit) under /opt/sonar-scanner/.sonar/ssl.

If you have a PEM or DER certificate, you can use OpenSSL or Keytool to generate the PKCS #12 keystore:

  • With OpenSSL:

openssl pkcs12 -export -caname sonar -out "truststore.p12" -in "server.pem" -passout pass:"<a password>" -nokeys
  • With Keytool

keytool -import -storetype PKCS12 -alias sonar -keystore truststore.p12 -file server.pem -storepass "<a password>"

If running the scanner in Docker: use a mounted volume

By default, the scanner expects the TrustStore password to be changeit. If you need to use a different password, inform the scanner using the -Dsonar.scanner.truststorePassword=<YOUR PASSWORD> property.

docker pull sonarsource/sonar-scanner-cli
docker run \
    --rm \
    -v ${DIR_WITH_TRUSTSTORE_DOT_P12}:/opt/sonar-scanner/.sonar/ssl \
    -v ${YOUR_CACHE_DIR}:/opt/sonar-scanner/.sonar/cache \
    -v ${YOUR_REPO}:/usr/src \
    -e SONAR_HOST_URL="http://${SONARQUBE_URL}" \
    sonarsource/sonar-scanner-cli \
    -Dsonar.scanner.truststorePassword=<a password> // Not needed if the default password is used

Managing the client certificates

Introduction to client authentication

If mutual TLS is used then both the client and the server authenticate the other party. During the TLS authentication of the client, the client must provide its certificate with the corresponding CA certificate chain (intermediate and root CA certificates) to the server. The client manages its certificates in its own keystore. The figure below shows the certificates involved in SonarQube Server’s TLS authentication of the SonarScanner.

Defining the access to the client certificates

For SonarScanner for Maven, Gradle, CLI, or NPM

Store the client certificate and CA certificate chain in a keystore file and define the access to this file through the following properties:

  • javax.net.ssl.keyStore or (for SonarScanner CLI from version 6.0 and SonarScanner for NPM from version 4.0) sonar.scanner.keystorePath: path to the keystore file.

  • javax.net.ssl.keyStorePassword or (for SonarScanner CLI from version 6.0 and SonarScanner for NPM from version 4.0) sonar.scanner.keystorePassword: password of the keystore file.

For SonarScanner for .NET
  1. Store the client certificate and CA certificate chain in a keystore file and define the access to this file through the following properties:

    • sonar.clientcert.path : path to the keystore file, must be set in the begin step.

    • sonar.clientcert.password: password of the keystore file, must be set in both the begin and end steps.

  2. In addition, set the following options before the end step (for the SonarScanner CLI invocation):

    • javax.net.ssl.keyStore: same value as sonar.clientcert.path

    • javax.net.ssl.keyStorePassword: same value as sonar.clientcert.password

Last updated

Was this helpful?