SonarQube Connector
The SonarQube connector is a connector that enables connections to any SonarQube instance.
You can use the SonarQube Connector to securely access SonarQube in CI/CD pipelines for code quality analysis, security scanning, and quality gate checks.
Additionally, the connector enables centralized management of SonarQube access configurations across namespaces, eliminating the need to duplicate SonarQube tokens in each namespace.
TOC
OverviewIntegration RequirementsCreating a Simple SonarQube ConnectorFields ReferenceCapabilities of SonarQube ConnectorAuthenticationCredential Permissions RequiredSonarQube Connector Proxy and Configuration with sonar-project.properties FileProxy Addresssonar-project.properties Configuration FileUsing sonar-project.properties in PodsHealth ChecksBest PracticesTroubleshootingOverview
This document covers:
- Integration Requirements: Prerequisites for target SonarQube instances
- Creating SonarQube connector
- Advanced Features: Proxy capabilities and configuration capabilities about SonarQube connector
Integration Requirements
SonarQube Prerequisites
- The SonarQube instance must be accessible via HTTP/HTTPS
- SonarQube version should support the API endpoints used by the connector:
/api/authentication/validate- for authentication validation/api/system/status- for liveness checking
Creating a Simple SonarQube Connector
Here's how to create a basic SonarQube Connector for a self-hosted SonarQube instance:
Fields Reference
spec.connectorClassName:
sonarqube (constant), specifies the ConnectorClass name for SonarQube integration.
spec.address:
Target SonarQube server address, for example:
- Self-hosted:
https://sonarqube.example.com
spec.auth (optional):
Specifies the authentication method for the SonarQube instance.
-
spec.auth.name: Should betokenAuthfor SonarQube connector. -
spec.auth.secretRef: Specifies the secret containing the authentication token for the SonarQube instance. The secret must be created in the same namespace as the connector.
Optional Metadata fields:
-
cpaas.io/description: Description information for the SonarQube connector, for example:
Capabilities of SonarQube Connector
Authentication
The SonarQube connector supports the following authentication types:
tokenAuth: Token-based authentication, corresponding secret type:connectors.cpaas.io/bearer-token
For example:
SonarQube supports multiple token types:
- User Token: Personal access token for individual users
- Project Analysis Token: Token scoped to specific projects (recommended for CI/CD)
- Global Analysis Token: Token for analyzing any project (use with caution)
For production environments, we recommend using Project Analysis Tokens with minimal required permissions.
For comprehensive status information, see Connector Status Documentation.
Credential Permissions Required
The required permissions for the configured credential depend on how you intend to use it in your Pods/Pipelines.
For example:
- Code Analysis: If you only need to perform code analysis, the token requires "Execute Analysis" permission on the target project.
- Quality Gate Checks: For checking quality gate status, the token needs read permissions on quality gates.
- Creating Projects: For creating new projects during analysis, additional permissions are required.
For security best practices, we recommend creating tokens with minimal required permissions. When additional privileges are needed, create separate Connectors with more privileged tokens and use namespace isolation to control which users can access each Connector.
SonarQube Connector Proxy and Configuration with sonar-project.properties File
To enable clients to access SonarQube without handling tokens directly, the SonarQube connector provides a proxy server that automatically injects authentication information.
Clients can use this proxy server to access SonarQube without needing to configure tokens on the client side.
To simplify usage, the SonarQube connector provides a sonar-project.properties file that can be mounted into Pods via CSI. When executing scanner operations in the Pod, the proxy service automatically injects authentication information.
Proxy Address
Upon Connector creation, the system automatically provisions a proxy service for the target SonarQube instance.
The proxy endpoint is recorded in status.proxy.httpAddress:
For example:
sonar-project.properties Configuration File
The SonarQube connector provides the following configuration:
sonar-project.properties:
- Provides a
sonar-project.propertiesconfiguration file. This configuration file is mounted into the Pod via CSI, enabling access to the SonarQube instance through the proxy without requiring token configuration on the client side.
Example of the configuration file generated in the ConfigMap:
The configuration includes:
sonar.host.url: The actual SonarQube server addresssonar.scanner.proxyHost: Proxy hostname for secure accesssonar.scanner.proxyPort: Proxy port (80 for HTTP, 443 for HTTPS)sonar.scanner.proxyUser: Encoded connector namespace and namesonar.scanner.proxyPassword: Authentication token (automatically managed)
Sonar Scanner 8.0+ disables tunnel proxy authentication by default. To enable authentication proxy support, you need to add the parameter -Djdk.http.auth.tunneling.disabledSchemes= via SONAR_SCANNER_OPTS during execution.
Using sonar-project.properties in Pods
The connector mounts a sonar-project.properties configuration file via CSI that contains scanner settings with proxy configuration.names.
To use it in your Pod:
The scanner will use the proxy configuration to access SonarQube securely without requiring direct token access.
If your SonarQube instance uses HTTPS, you need to import the CA certificate into the Java truststore in the scanner container:
ca.cert is automatically mounted by the connector and contains the CA certificate of the Connector Proxy server. More details can be found in the Connectors CSI Built-in Configurations.
Health Checks
The SonarQube connector performs automatic health checks to verify connectivity:
Liveness Probe:
- Endpoint:
/api/system/status - Expected Response: HTTP 200 with
{"status": "UP"} - Purpose: Ensures the SonarQube instance is operational
Authentication Probe:
- Endpoint:
/api/authentication/validate - Expected Response: HTTP 200 with
{"valid": true} - Purpose: Validates that the provided token is valid
These probes run automatically and the results are reflected in the Connector's status conditions.
Best Practices
- Namespace Isolation: Create separate connectors for different teams or projects using namespace isolation
- Token Rotation: Regularly rotate authentication tokens and update the secrets accordingly
- Monitor Status: Monitor the connector's Ready condition to detect authentication or connectivity issues
- Minimize Permissions: Grant only the minimum permissions required for your specific use case
Troubleshooting
If the connector shows a non-Ready status:
- Check Authentication: Verify the token in the secret is valid and has not expired
- Verify Connectivity: Ensure the SonarQube instance is accessible from the Kubernetes cluster
- Review Logs: Check connector-proxy-service logs for detailed error messages
- Validate Address: Confirm the
spec.addressis correct and includes the protocol (https://) - API Access: Ensure the SonarQube instance allows API access from your cluster
For more troubleshooting guidance, see Troubleshooting Guide.