immauss / openvas

Containers for running the Greenbone Vulnerability Manager. Run as a single container with all services or separate single applications containers via docker-compose.
GNU Affero General Public License v3.0
360 stars 102 forks source link

[BUG] Logical issue with postgresql.sh in multi-container mode #223

Closed matchaxnb closed 1 year ago

matchaxnb commented 1 year ago

Describe the bug When starting this project in multi-container mode, postgresql.sh checks for an existing database, finds it existing because it exists, and exits, breaking functionality.

To Reproduce Steps to reproduce the behavior:

  1. Start the container of an already existing environment that you shut down before: cd multi-container; docker-compose -p openvas --env-file /opt/openvas/my-customer.env up -d
  2. See that ovas_postgresql is in a restart loop:
    $ docker-compose -p openvas --env-file /opt/openvas/customer.env ps
    NAME                COMMAND                  SERVICE             STATUS                PORTS
    openvas             "/scripts/start.sh o…"   openvas             running (unhealthy)   
    ovas_gsad           "/scripts/start.sh g…"   gsad                running (healthy)     0.0.0.0:8080->9392/tcp, :::8080->9392/tcp
    ovas_gvmd           "/scripts/start.sh g…"   gvmd                restarting            
    ovas_mosquitto      "/scripts/start.sh m…"   mosquitto           running (healthy)     
    ovas_notus          "/scripts/start.sh n…"   notus               running (healthy)     
    ovas_postgresql     "/scripts/start.sh p…"   postgresql          running (starting)    
    ovas_redis          "/scripts/start.sh r…"   redis               running (unhealthy)   
    ovas_scannable      "/bin/bash /entrypoi…"   scannable           running               
    $ docker-compose -p openvas --env-file /opt/openvas/bso.env logs -t postgresql
    [...]
    ovas_postgresql  | 2023-09-11T16:10:27.932823297Z  It looks like there is already a gvmd database.
    ovas_postgresql  | 2023-09-11T16:10:27.932867468Z  Failing out to prevent overwriting the existing DB
    ovas_postgresql  | 2023-09-11T16:10:34.933470145Z starting container at: Mon Sep 11 16:10:34 UTC 2023
    ovas_postgresql  | 2023-09-11T16:10:34.933736576Z Looks like this container has already been started once.
    ovas_postgresql  | 2023-09-11T16:10:34.933835091Z Just doing a little cleanup instead of the whole fs-setup.
    ovas_postgresql  | 2023-09-11T16:10:35.933990892Z Choosing container start method from:
    ovas_postgresql  | 2023-09-11T16:10:35.934046301Z postgresql
    ovas_postgresql  | 2023-09-11T16:10:35.934291175Z Starting postgresql for gvmd !!
    ovas_postgresql  | 2023-09-11T16:10:35.941703549Z Starting PostgreSQL...
    ovas_postgresql  | 2023-09-11T16:10:35.953620902Z pg_ctl: another server might be running; trying to start server anyway
    ovas_postgresql  | 2023-09-11T16:10:36.065516249Z waiting for server to start....2023-09-11 16:10:36.064 UTC [16] LOG:  redirecting log output to logging collector process
    ovas_postgresql  | 2023-09-11T16:10:36.065556609Z 2023-09-11 16:10:36.064 UTC [16] HINT:  Future log output will appear in directory "/data/var-log/postgresql".
    ovas_postgresql  | 2023-09-11T16:10:36.792522089Z  done
    ovas_postgresql  | 2023-09-11T16:10:36.792563747Z server started
    ovas_postgresql  | 2023-09-11T16:10:36.794258079Z pg exit with 0 .
    ovas_postgresql  | 2023-09-11T16:10:36.794438447Z Checking for existing DB
    ovas_postgresql  | 2023-09-11T16:10:36.888484867Z  gvmd      | gvm      | UTF8     | C.UTF-8 | C.UTF-8 | 
    ovas_postgresql  | 2023-09-11T16:10:36.888513972Z  postgres  | postgres | UTF8     | C.UTF-8 | C.UTF-8 | 
    ovas_postgresql  | 2023-09-11T16:10:36.888545631Z  template0 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
    ovas_postgresql  | 2023-09-11T16:10:36.888555943Z            |          |          |         |         | postgres=CTc/postgres
    ovas_postgresql  | 2023-09-11T16:10:36.888563109Z  template1 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
    ovas_postgresql  | 2023-09-11T16:10:36.888570440Z            |          |          |         |         | postgres=CTc/postgres
    ovas_postgresql  | 2023-09-11T16:10:36.888577679Z 
    ovas_postgresql  | 2023-09-11T16:10:37.070173238Z  It looks like there is already a gvmd database.
    ovas_postgresql  | 2023-09-11T16:10:37.070254134Z  Failing out to prevent overwriting the existing DB

When did the issue occur?

Expected behavior OpenVAS should just start in that case.

Environment (please complete the following information):

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye 
$ docker version
Client: Docker Engine - Community
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:52:17 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:52:17 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
$ docker-compose version
Docker Compose version v2.11.1

Running on Docker compose.

logs ( commands assume the container name is 'openvas' ) Please attach the output from one of the following commands:

See logs attached: openvas.logs.txt

Additional context That's about it.

immauss commented 1 year ago

This should be fixed in the latest and => 22.4.30