We found a gap in the existing run-sonar-scanner-cli boilerplate.
When we transitioned from default JVM trust to TLS trust utilising a fallback GitHub root cert secret, the certificates were imported into the PKCS12 truststore successfully. However, on subsequent workflow runs, SonarScanner attempted to load the existing truststore without being supplied the truststore password.
This resulted in:
PKCS12 key store mac invalid - wrong password or corrupted file
The truststore itself was validated and found to be healthy. The fix ensures the truststore password is always supplied whenever a PKCS12 truststore exists.
# Persisted self-hosted runner truststores still need the PKCS12 password even when
# SONAR_ROOT_CERT is not set for the current run; otherwise SonarScanner fails before
# any network call with "PKCS12 key store mac invalid".
if [[ -f "$SONAR_SSL_TRUSTSTORE_FILE" ]] && [[ " ${scanner_args[*]} " != *" -Dsonar.scanner.truststorePassword=$SONAR_SSL_TRUSTSTORE_PASSWORD "* ]]; then
scanner_args+=("-Dsonar.scanner.truststorePassword=$SONAR_SSL_TRUSTSTORE_PASSWORD")
fi