tobybatch / kimai2

Docker containers for the kimai2 web application including docker-compose and kubernetes/helm deployment.
MIT License
181 stars 96 forks source link

[BUG] Exception\SuspiciousOperationException: Untrusted Host #65

Closed urinal-cake closed 4 years ago

urinal-cake commented 4 years ago

Again, this may be an issue with my lack of reading documentation properly, or not having the correct setup. Are there pre-requisites that I'm not aware of? Does the docker-compose properly take care of downloading and handling nginx?

Describe the bug After starting the docker containers with the command 'docker-compose up -d' and navigating to the IP of the host that has kimai installed, the application in any browser displays a message that the host is untrusted. This appears to be a Symfony issue that, after researching, may be related to the docker-compose file not being correctly configured?

To Reproduce Steps to reproduce the behaviour:

  1. sudo git clone https://github.com/tobybatch/kimai2.git kimai
  2. sudo cd /opt/kimai
  3. Comment out lines in the docker-compose related to start_period (18, 36, 54) to get around https://github.com/tobybatch/kimai2/issues/64
  4. docker-compose up -d
  5. Notice the following error is displayed:

    Fatal error: Uncaught Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException: Untrusted Host "10.20.10.132". in /opt/kimai/vendor/symfony/http-foundation/Request.php:1191 Stack trace: #0 /opt/kimai/vendor/symfony/http-kernel/EventListener/ValidateRequestListener.php(41): Symfony\Component\HttpFoundation\Request->getHost() #1 /opt/kimai/vendor/symfony/event-dispatcher/EventDispatcher.php(298): Symfony\Component\HttpKernel\EventListener\ValidateRequestListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\RequestEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\EventDispatcher)) #2 /opt/kimai/vendor/symfony/event-dispatcher/EventDispatcher.php(260): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher{closure}(Object(Symfony\Component\HttpKernel\Event\RequestEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\EventDispatcher)) #3 /opt/kimai/vendor/symfony/event-dispatcher/EventDispatcher.php(235): Symfony\Component\EventDispatcher in /opt/kimai/vendor/friendsofsymfony/rest-bundle/View/ViewHandler.php on line 366

Desktop (please complete the following information):

Command used to run the container

Docker compose file (with passwords redacted)

services:

  sqldb:
    image: mysql:5.7
    environment:
      - MYSQL_DATABASE=kimai
      - MYSQL_USER=kimaiuser
      - MYSQL_PASSWORD=kimaipassword
      - MYSQL_ROOT_PASSWORD=changemeplease
    volumes:
      - /var/lib/mysql
    command: --default-storage-engine innodb
    restart: unless-stopped
    healthcheck:
      test: mysqladmin -pchangemeplease ping -h localhost
      interval: 20s
      start_period: 10s
      timeout: 10s
      retries: 3 

  nginx:
    build: compose
    ports:
      - 8001:80
    volumes:
      - ./nginx_site.conf:/etc/nginx/conf.d/default.conf
    restart: unless-stopped
    depends_on:
      - kimai
    volumes:
      - public:/opt/kimai/public
    healthcheck:
      test:  wget --spider http://nginx/health || exit 1 
      interval: 20s
      start_period: 10s
      timeout: 10s
      retries: 3 

  kimai:
    image: kimai/kimai2:fpm-alpine-1.5-prod
    environment:
      - APP_ENV=prod
      - TRUSTED_HOSTS=localhost
      - ADMINMAIL=admin@kimai.local
      - ADMINPASS=changemeplease
    volumes:
      - public:/opt/kimai/public
      - var:/opt/kimai/var
    restart: unless-stopped
    healthcheck:
      test: wget --spider http://nginx || exit 1
      interval: 20s
      start_period: 10s
      timeout: 10s
      retries: 3

  postfix:
    image: catatnight/postfix
    environment:
      maildomain: neontribe.co.uk
      smtp_user: kimai:kimai
    restart: unless-stopped
    restart: always

volumes:
    var:
    public:

Additional context Fresh new virtual machine with nothing but docker and docker-compose installed. Also, excuse me if I'm missing some crucial steps. I'm new to a fair bit of this.

urinal-cake commented 4 years ago

I had another developer that found that if you change - TRUSTED_HOSTS=localhost,theIpOfYourHost then it will work

tobybatch commented 4 years ago

@urinal-cake you are completely correct it's due to the trusted hosts setting. I'll create a bug to cover this and see if we can document it better.

z3rone commented 4 years ago

@tobybatch I guess my confusion was that I've included the port with the hostname, Maybe you could point out in the doc that the port should be omitted.

Thanks for the support!

calarndt commented 2 years ago

This issue's solution is not complete... Quoting @urinal-cake I had another developer that found that if you change

Excellent solution if one were to know WHERE to change that. It exists in only in two .json files on my system. Both files buried way deep down inside /var/lib/docker which to me appears to be the wrong place to change it.

I tried prefacing my docker command with that variable. No dice still my host is untrusted... No idea where to go from here...

tobybatch commented 2 years ago

https://tobybatch.github.io/kimai2/runtime-args.html#runtime-arguments