Start Free
Latest | Analyzing source code | Scanners | Scanner environment | TLS certificates on client side

Managing the TLS certificates on the client side

On this page

If your SonarQube Server instance is configured with HTTPS 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.

Server authentication

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

Step 1: Add the certificate for your scanner

The way you add your self-signed certificate depends on your scanner.

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. 

or:

  • Provide a custom Java TrustStore. This operation depends on your scanner version:
    • Version >= 5.0: We recommend using the properties sonar.scanner.truststorePath and sonar.scanner.truststorePassword. If this does not work, please retry after upgrading to the next scanner minor version.
      You can also use the properties described below for version <= 4.0.
    • Version <= 4.0: Use the following properties:
      • javax.net.ssl.trustStore: path to the TrustStore file (pkcs12 format is recommended).
      • javax.net.ssl.trustStorePassword: password of the TrustStore.

This scanner is 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.
  • 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.

The operation depends on the version of your SonarScanner for .NET.

Scanner version > = 10.0

You can use a PKCS#12 keystore as explained below. 

Consider the following when generating the PKCS#12 keystore:

  • 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 property sonar.scanner.truststorePath.
  • The default password for the TrustStore is changeit. This password can be overridden using the property sonar.scanner.truststorePassword.

To override the default parameters, set the sonar properties in the begin step, and, for the password, also in the end step. 

Generating the PKCS#12 keystore

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:"<truststorePassword>" -nokeys
  • With Keytool 
keytool -import -storetype PKCS12 -alias sonar -keystore truststore.p12 -file server.pem -storepass "<truststorePassword>"

Scanner version < = 9.1

You must use the operating system TrustStore. Proceed as follows:

1. From scanner version 7.0, disable JRE auto-provisioning (JRE auto-provisioning is not compatible with the system TrustStore if you use SonarScanner for .NET). To do so, set the sonar.scanner.skipJreProvisioning property to true and make sure you run the Java runtime environment version required by your SonarQube server.

2. Add the self-signed server certificate to the operating system TrustStore:

    • On Linux:
      1. Copy the self-signed server certificate to /usr/local/share/ca-certificates
      2. Run sudo update-ca-certificates
    • On macOS: use Keychain Access or use the following command:
sudo security add-trusted-cert -d -r trustRoot \
     -k /Library/Keychains/System.keychain <path/to/certificate>
    • On Windows: use certutil. Here is an example:
certutil -addstore -f "ROOT" <path/to/certificate>

3. Add the self-signed certificate to the Java TrustStore for SonarScanner CLI (which is used by SonarScanner for .NET) as explained in the SonarScanner for NPM or CLI tab, for SonarScanner CLI < 6.0

The operation depends on the version of your SonarScanner for NPM or SonarScanner CLI.

SonarScanner for NPM >= 4.0 and SonarScanner CLI >= 6.0

You must provide a PKCS#12 keystore.

Consider the following when generating the PKCS#12 keystore:

  • 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 property sonar.scanner.truststorePath.
  • The default password for the TrustStore is changeit. This password can be overridden using the property sonar.scanner.truststorePassword.
Generating the PKCS#12 keystore

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:"<truststorePassword>" -nokeys
  • With Keytool 
keytool -import -storetype PKCS12 -alias sonar -keystore truststore.p12 -file server.pem -storepass "<truststorePassword>"
If running the scanner in Docker: use a mounted volume

The preferred way is to mount a folder containing the PKCS #12 file under /opt/sonar-scanner/.sonar/ssl.

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=<truststorePassword> // Not needed if the default password is used

SonarScanner for NPM < 4.0 and SonarScanner CLI < 6.0

This scanner is 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.
  • 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.

For information about setting the mentioned sonar properties, see Using SonarScanner for .NET, Configuring SonarScanner for NPM, or Configuring SonarScanner CLI.

Step 2: Additional step depending on your CI tool

If you use GitHub Action or Azure Pipelines, an additional step is necessary as described below.

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).

If you want to add the SonarQube analysis to your Azure build pipeline and your SonarQube Server instance uses a self-signed certificate, you must provide the server certificate so that the AzureDevOps Extension for SonarQube can connect to SonarQube Server during the Prepare Analyze Configuration and Run Code Analysis tasks.

Proceed as follows:

  • Define the following environment variable (this setup is required for the Prepare Analyze Configuration task):
    • Key: NODE_EXTRA_CA_CERTS
    • Value: path to the certificate

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. 

Diagram of multual TLS client certificate

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

Was this page helpful?

© 2008-2025 SonarSource SA. All rights reserved.

Creative Commons License