Sonarqube authorization - how to authorize with sonar-maven-plugin when sonar.forceAuthentication is enabled

与世无争的帅哥 提交于 2019-12-21 12:01:06

问题


I've got sonarqube 6.5 with default configs. When sonar.forceAuthentication flag is set to false, I can create and analyse project through command given below.

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

When I enable sonar.forceAuthentication parameter (sonar.forceAuthentication=true), I can't analyse project. I always get maven error:

[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]

It doesn't work on default admin account nor created user account (with permission to analyse project). I've also tried not to use user key, but user' login and password (-Dsonar.login and -Dsonar.password in maven config) but it also doesn't work. I've tried to use different sonar version (from 4.5.7, through 5.6.6 to the newest, 6.5, but I always get the same result).

During the connection, I've got such messages in my 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"

It's required for me to set sonar.forceAuthentication parameter to true (only trusted users can have access to it).

Any idea how to configure and access sonarqube through maven with credential parameters?


回答1:


Did you set both sonar.login and sonar.password parameters (https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven#AnalyzingwithSonarQubeScannerforMaven-Security) ?

Note that in recent versions (like SonarQube 6.5), you should use a user token and just set it in the sonar.login parameter: https://docs.sonarqube.org/display/SONAR/User+Token




回答2:


This is a minimal command that I use to update Sonar Cube Dashboard for my project,

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>

You can always wrap a string value in double quotes if it has spaces in it.

Before using above command, you need to generate token for your user id as specified in answer provided by Eric. There is no need to pass password property.



来源:https://stackoverflow.com/questions/46114028/sonarqube-authorization-how-to-authorize-with-sonar-maven-plugin-when-sonar-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!