通过基本身份验证来验证sonarScanner

时间:2017-04-21 13:54:06

标签: sonarqube sonarqube-scan

我对这个问题很沮丧, 我们的sonarqube服务器支持http基本身份验证,本地运行器因401错误而失败。是否有可能为它提供凭据? AOfficial docs展示了如何提供sonarqube的内部用户...... http://www.it1me.com/it-answers?id=35790175&s=User%20talk:Omotecho&ttl=Authenticate+sonar- 通过+基本+ AUTH转轮+

关于它的任何想法或经验?

2 个答案:

答案 0 :(得分:0)

执行分析需要“执行分析”权限。 要为扫描仪设置凭据,您需要使用sonar.login和sonar.password。 有关详细信息,请查看:

答案 1 :(得分:0)

我知道这个问题已经很老了,但是我花了一天的时间弄清楚以下问题:

TLDR: 即使配置了凭据,声纳运行器也不会使用它们来首次调用服务器。端点是/ batch / index。 您必须允许对该端点的公共访问。对于所有其他网址,基本身份验证就可以了。

更多详细信息: 我将Apache 2.4用作具有Sonar 7.9.2基本身份验证的反向代理,它位于/ sonar路径下的docker容器中。 我的用于身份验证的Apache 2.4配置的一部分

  <Location /sonar/batch/index>
    SetEnvIf User-Agent "^ScannerMaven" scanner_maven
    SetEnvIf User-Agent "^ScannerCli" scanner_maven
  </Location>
  <Location /sonar>
    <RequireAny>
      Require group sonar
      <RequireAll>
        Require expr %{REQUEST_URI} =~ m#^.*\/sonar\/batch\/index#
        Require env scanner_maven
      </RequireAll>
    </RequireAny>
    SetEnv proxy-chain-auth On
  </Location>

如您所见,路径/sonar/batch/index未使用身份验证。作为一个不是很好但总比没有好的限制,如果有人使用User-Agent ScannerMaven或ScannerCli(即声纳扫描仪)发出请求,则我设置了一个env变量。请注意,根据扫描仪的不同,用户代理很容易被伪造或更改。 对于所有其他URL,必须对位于组声纳中的用户进行身份验证。 (Apache和Sonar的用户相同,代理将具有proxy-chain-auth的凭据转发给Sonar。)

此设置已通过maven测试:mvn sonar:sonar

使用

    <profiles>
      <profile>
        <id>sonar</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
          <sonar.host.url>https://myhost/sonar/</sonar.host.url>
          <sonar.login>${env.SONARUSER}</sonar.login>
          <sonar.password>${env.SONARPWD}</sonar.password>
        </properties>
      </profile>
    </profiles>

    [...]

    <plugin>
        <groupId>org.sonarsource.scanner.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.7.0.1746</version>
    </plugin>