DefectDojo / godojo

Golang installer for DefectDojo
GNU General Public License v3.0
25 stars 22 forks source link

prepInstall.go uses different envar names for database gear #55

Closed noloader closed 2 years ago

noloader commented 2 years ago

prepInstall.go is using different envar names for for database gear.

For example, dojoConfig.yml specifies:

 DB:
    Engine: "PostgreSQL" # DD_DB_Engine - Database engine to use (SQLite, MySQL, PostgreSQL, MariaDB) Note: CASE sEnSiTiVE!
    Local: true # DD_DB_Local - Boolean for when DB is on the same host/server/vm (local)
    Exists: false # DD_DB_Exists - Boolean for when DB for DefectDojo already exists so no install needed
    Ruser: "postgres" # DD_DB_Ruser - Superuser for the database, root for MySQL/MaraiDB & posgres for PostgreSQL. Note: this and Rpass below REQUIRED for remote and existing DBs
    Rpass: "vee0Thoanae1daePooz0ieka" # DD_DB_Rpass - Password for the database superuser TODO: Note: set to 24 random characters if left blank
    Name: "dojodb" # DD_DB_Name - Name of the database that DefectDojo will use
    User: "dojodbusr" # DD_DB_User - Username of the database user that DefectDojo will use
    Pass: "vee0Thoanae1daePooz0ieka" # DD_DB_Pass - Password for the database user DefectDojo will use Note: set to 24 random characters
    Host: "localhost" # DD_DB_Host - Database hostname
    Port: 5432 # DD_DB_Port - Port the database is listening on - 3306 for MySQL/MariaDB and 5432 for PostgreSQL
    Drop: false # DD_DB_Drop - Boolean to tell the installer to drop an existing DB if found

But prepInstall.go has:

        case "DD_DATABASE_ENGINE":
            conf.Settings.DatabaseEngine = v
        case "DD_DATABASE_HOST":
            conf.Settings.DatabaseHost = v
        case "DD_DATABASE_NAME":
            conf.Settings.DatabaseName = v
        case "DD_DATABASE_PASSWORD":
            conf.Settings.DatabasePassword = v
        case "DD_DATABASE_PORT":
            conf.Settings.DatabasePort = v
        case "DD_DATABASE_TYPE":
            conf.Settings.DatabaseType = v
        case "DD_DATABASE_URL":
            conf.Settings.DatabaseURL = v
        case "DD_DATABASE_USER":
            conf.Settings.DatabaseUser = v

It is causing a lot of confusion. And worse, it seems to be breaking my ability to add a variable for DD_DB_Exists so the installer will actually skip the database installation and configuration when DD_DB_Exists=true.

When I attempt to add a DD_DATABASE_EXISTS it produces a compile error:

./prepInstall.go:277:17: conf.Settings.DatabaseExists undefined (type "github.com/mtesauro/godojo/config".SettingsConfig has no field or method DatabaseExists)
mtesauro commented 2 years ago

Two things here:

(1) Those multiple values for DB configuration are joined to create the DB URL needed for DefectDojo's configuration. There's also historical/framework issues in that Django supports providing a Python dict for the database configuration like:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'OPTIONS': {
            'service': 'my_service',
            'passfile': '.my_pgpass',
        },
    }
}

Support for DB URL was added to DefectDojo as many users who weren't familiar with Python data types like dict had issues with configuring the DB using syntax like above. Most people get URLs so that support was added to DefectDojo. However, the Django framework still understands a DB configuration like above and it seemed easier to have people provide individual values in dojoConfig.yml vs construct the full DB URL if they only need to change a single or few elements of that DB URL.

(2) As I said in issue #53 , I'll look into DD_DATABASE_EXISTS. I'm pretty sure that was address in the current refactor.