Search code examples
sonarqubesonarqube7

Can't use port 80 on SonarQube


The first time when I tried to run SonarQube with root user this fails. Searching in internet I find that the new Sonar should be execute by a non-root user. I created the user sonar with the folow command useradd -m -s /bin/bash sonar and I executed chmod -R 777 sonaqube-7.0. Then I loggin with sonar user: sudo su sonar. When I execute ./sonar.sh console all works fine. But when I change the port by default 9000 to port 80, this fails. Using the command netstat -plunt I check if the port 80 is in use, but the only ports that I use is 22 (sshd), 5432 (postgres) and 25 (exim4).I thinks that this happed because the user sonar has not permission to use the port 80. How cant I use the port 80 with SonarQube?

My current Operating system is debian 9


Solution

  • Exists some ways to allow non-root user use the port 80 and 433, using iptables to redirect the port petitions, CAP_NET_BIND_SERVICE and authbind. The way more easy isauthbind.

    Use authbind to grant one-time access, with finer user/group/port control:

    The authbind (man page) tool exists precisely for this.

    1. Install authbind using your favorite package manager.

    2. Configure it to grant access to the relevant ports, e.g. to allow 80 and 443 from all users and groups:

      sudo touch /etc/authbind/byport/80
      sudo touch /etc/authbind/byport/443
      sudo chmod 777 /etc/authbind/byport/80
      sudo chmod 777 /etc/authbind/byport/443
      
    3. Now execute your command via authbind (optionally specifying --deep or other arguments, see the man page):

      authbind --deep /path/to/binary command line args
      

      E.g.

      authbind --deep java -jar SomeServer.jar
      

    This option grants trust to the user/group and provides control over per-port access but, AFAIK, supports only IPv4.

    These are the links that I used to document me:

    1. allow non-root process to bind to port 80 and 443
    2. Is there a way for non-root processes to bind to "privileged" ports on Linux?
    3. how to run a server on port 80 as a normal user on linux