当SonarQube服务器使用HTTP时,如何在sonar-cxx插件中禁用SSL?

后端开发 2026-07-10

我在各自的Docker容器中运行SonarScanner CLI和 SonarQube。

我使用的是SonarQube的免费版本,因此添加了 cxx sonarqube插件 v2.2.2。

SonarScanner的版本是12.1,SonarQube Docker版本是: 26.3.0.120487,SonarQube服务器托管在HTTP URL上,而不是HTTPS。

然而,当我启动分析时,社区版C++插件 (sonar-cxx) 会整个扫描器崩溃。它尝试初始化一个SSL上下文以从服务器下载规则,但失败了,因为它在我选择的扫描器容器中寻找一个不存在的密钥库路径。

日志如下:

09:00:49.879 INFO trust store based on javax.net.ssl not loadable: The value for the system property [javax.net.ssl.keyStore] is absent
09:00:49.892 ERROR Error during SonarScanner Engine execution
nl.altindag.ssl.exception.GenericKeyStoreException: java.lang.IllegalArgumentException: Failed to load the keystore from the classpath for the given path: [/usr/lib/jvm/java-21-amazon-corretto.x86_64/lib/security/cacerts]
    at nl.altindag.ssl.util.KeyStoreUtils.loadKeyStore(KeyStoreUtils.java:91)
    at nl.altindag.ssl.SSLFactory$Builder.withTrustMaterial(SSLFactory.java:308)
    at org.sonar.cxx.sensors.utils.SSLContextBuilder.createSSLContext(SSLContextBuilder.java:107)
    at org.sonar.cxx.sensors.utils.SonarServerWebApi.setServerConfig(SonarServerWebApi.java:174)
    at org.sonar.cxx.sensors.utils.CxxIssuesReportSensor.downloadRulesFromServer(CxxIssuesReportSensor.java:95)
    at org.sonar.cxx.sensors.utils.CxxIssuesReportSensor.executeImpl(CxxIssuesReportSensor.java:84)
    at org.sonar.cxx.sensors.utils.CxxReportSensor.execute(CxxReportSensor.java:101)
    ...
Caused by: java.lang.IllegalArgumentException: Failed to load the keystore from the classpath for the given path: [/usr/lib/jvm/java-21-amazon-corretto.x86_64/lib/security/cacerts]
    at nl.altindag.ssl.util.internal.ValidationUtils.requireNotNull(ValidationUtils.java:41)
    at nl.altindag.ssl.util.KeyStoreUtils.loadKeyStore(KeyStoreUtils.java:88)
    ... 26 common frames omitted

该路径在我的Docker容器中存在 /usr/lib/jvm/java-21-amazon-corretto.x86_64/lib/security/cacerts
我的 sonar.host.urlhttp://<hostname>:9000,由于我无法进行SSL验证,我尝试在Dockerfile镜像中安装另一个Java,但没有成功,或者将 Sonar_scanner_opts 修改为指定cacerts路径。
我不理解这个错误。

由于我的服务器使用HTTP,我不需要SSL验证。是否可以在我的 sonar-project.propertiesSONAR_SCANNER_OPTS 中添加某个特定属性,以完全禁用sonar-cxx插件中的SSL上下文初始化,还是应该把SonarQube服务器改为HTTPS?

解决方案

Your issue seems to be related to a bug in sonar cxx plugin, I created a pull request to fix the issue here: https://github.com/SonarOpenCommunity/sonar-cxx/pull/3044

根本原因是它试图从类路径加载指定的路径,而不是从文件系统加载,这导致你所遇到的崩溃。

希望维护者能够尽快发布新版本。顺便说一下,我在源代码中没有看到禁用ssl的方法。所以现在看来,唯一的办法就是希望这个修复能尽快实现并发布。

更新2026-04-16

有一个新版本应该可以解决你遇到的问题。你可以在这里找到包含该错误修复的最新版本 https://github.com/SonarOpenCommunity/sonar-cxx/releases/tag/latest-snapshot

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章