Search code examples
javascriptdockerdocker-composesonarqubesonarqube-scan

You're not authorized to run analysis. Please contact the project administrator Sonarqube local


I have very basic setup of sonarqube. It is in initial phase only and it's kind of strange that I'm not able to access sonarqube report at localhost:9090 (default is of course 9000 but I just changed it to 9090). I'm able to login to sonarqube at localhost:9090

When I run node sonarqube-scanner.js command, it gets executed successfully as shown below but it gives authorization error,

INFO: Analysis report generated in 225ms, dir size=144.8 kB
INFO: Analysis report compressed in 338ms, zip size=49.6 kB INFO:

INFO: EXECUTION FAILURE INFO:

INFO: Total time: 6:16.209s INFO: Final Memory: 16M/60M INFO:

ERROR: Error during SonarScanner execution
ERROR: You're not authorized to run analysis. Please contact the project administrator.

My sonarqube-scanner.js file is as below, as you can I tried with everything eg login, password, token

const scanner = require('sonarqube-scanner');
scanner(
  {
    serverUrl: "http://localhost:9090",
    login: "XXX",
    password: "XXX",
    token: "sqa_bXXXXXXXXXXXXXXXXX",
    options: {
      "sonar.sources": "./src"
    },
  },
  () => process.exit()
);

And I use sonarqube docker image as below

docker-compose.yml

version: "3"
services:
  sonarqube:
    image: sonarqube:community
    depends_on:
      - db
    environment:
      SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
      SONAR_JDBC_USERNAME: sonar
      SONAR_JDBC_PASSWORD: sonar
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
    ports:
      - "9090:9000"
  db:
    image: postgres:12
    environment:
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

volumes:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:
  postgresql:
  postgresql_data:

NOTE : At localhost:9090->Administration->Security-> all checkboxes are checked for all users. Still it is not working.


Solution

  • I literally don't know if anything has changed but I observed one thing as below,

    Earlier few days ago,

    I was able to generate the report directly to localhost:9090 but all of sudden from today it started indicating You're not authorized to run analysis. Please contact the project administrator.

    The Problem

    Earlier it used to generate the report on-the-fly directly and create the project on its own. What I mean by that is even when your server is not configured with any project (consider it is completely blank) and if you are running the sonar analysis for the first time, it used to create the project on-the-fly on the sonarqube-server (localhost).

    This not not the case anymore (at least in my case)
    in my case, my sonarqube-server was completely empty (without any project) and when I was trying to run the sonar analysis again for the first time, it started throwing the error that you are not authorized.

    Solution

    I just had to create the project manually in sonarqube-server. Then when I ran the analysis, it ran successfully without any problem.

    I hope this answer will help someone in future.