Managing the TLS certificates on the client side
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.

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 propertysonar.scanner.truststorePath
- The default password for the TrustStore is
changeit
. This password can be overridden using the propertysonar.scanner.truststorePassword
Please see the Using the SonarScanner for .NET page in Begin step command line parameters for more details about adding these to your .NET project.
SonarScanner for .NET version 9.2 and newer
The SonarScanner for .NET 9.2+ 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 the Windows Certmgr to have CRL support. To do this, please follow the instructions For scanner versions 9.1 and earlier.
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
For scanner versions 9.1 and earlier
Add the self-signed server certificate to the operating system truststore:
- On Linux and MacOS:
- Copy the self-signed server certificate to
/usr/local/share/ca-certificates
- Run
sudo update-ca-certificates
- Copy the self-signed server certificate to
- On Windows: use certutil.
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: Self Signed certificate of DevOps platforms - 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.
These javax.net properties are JVM properties, not scanner properties. They should be passed using the SONAR_SCANNER_OPTS
environment variable.
For example: SONAR_SCANNER_OPTS="-Djavax.net.ssl.trustStore=C:/ssl/truststore.p12 -Djavax.net.ssl.trustStorePassword=changeit"
On Windows, use forward slashes as path separators.
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
- 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.
- In addition, set the following options before the end step (for the SonarScanner CLI invocation):
javax.net.ssl.keyStore
: same value assonar.clientcert.path
javax.net.ssl.keyStorePassword
: same value assonar.clientcert.password
Was this page helpful?