Sonarqube授权 - 当sonar.forceAuthentication启用时如何使用sonar-maven-plugin进行授权

shh*_*hha 6 authorization runner sonar-runner sonarqube sonarqube-scan

我有默认配置的sonarqube 6.5.当sonar.forceAuthentication标志设置为false时,我可以通过下面给出的命令创建和分析项目.

mvn sonar:sonar -Dsonar.host.url=https://mySonarHost/sonar -Dsonar.login=mySonarUserKey

当我启用sonar.forceAuthentication参数(sonar.forceAuthentication = true)时,我无法分析项目.我总是得到maven错误:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project storm: Not authorized. Please check the properties sonar.login and sonar.password. -> [Help 1]

它不适用于默认管理员帐户,也不适用于创建的用户帐户(具有分析项目的权限).我也试过不使用用户密钥,但用户的登录名和密码(-Dsonar.login以及-Dsonar.passwordmaven配置),但它也不起作用.我试过使用不同的声纳版本(从4.5.7到5.6.6到最新的6.5,但我总是得到相同的结果).

在连接期间,我在access.log中收到了这样的消息:

IP_ADDRESS - - [08/Sep/2017:12:03:33 +0200] "GET /sonar/batch/index HTTP/1.1" 200 - "-" "ScannerMaven/3.3.0.603/3.5.0" "SOME_KEY"
IP_ADDRESS - - [08/Sep/2017:12:03:33 +0200] "GET /sonar/api/settings/values.protobuf HTTP/1.1" 401 - "-" "ScannerMaven/3.3.0.603/3.5.0" "SOME_KEY"
Run Code Online (Sandbox Code Playgroud)

我需要将sonar.forceAuthentication参数设置为true(只有受信任的用户才能访问它).

知道如何配置和访问带有凭证参数的maven的sonarqube吗?

小智 7

你同时设置sonar.loginsonar.password参数(https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven#AnalyzingwithSonarQubeScannerforMaven-Security)?

请注意,在最新版本(如SonarQube 6.5)中,您应该使用用户令牌并将其设置在sonar.login参数中:https://docs.sonarqube.org/display/SONAR/User+Token


Sab*_*han 7

这是我用来为我的项目更新 Sonar Cube Dashboard 的最小命令,

mvn clean install  sonar:sonar -Dsonar.host.url=<Server_URL> -Dsonar.login=<Token_For_Your_User_Id> -Dsonar.projectKey=<It will be calculated by default using group id & artifact id but its advisable that you use a unique string for all users> -Dsonar.projectName=<Descriptive Project Name to show on dashboard> -Dsonar.projectVersion=<if you wish to specify a version number>
Run Code Online (Sandbox Code Playgroud)

如果字符串中包含空格,您始终可以将其用双引号括起来。

在使用上述命令之前,您需要为 Eric 提供的答案中指定的用户 ID 生成令牌。无需传递密码属性。