Skip to content

Allow specifying database client certificates via environment variables #1105

Open
@Jauchi

Description

@Jauchi

Desired Behavior

Client side certificates enhance security by requiring mutual authentication for databases.

Support is already baked into netbox, there are just no environment variables to expose the functionality.

Contrast to Current Behavior

Currently, database configuration needs to be done in the extra.py config file.

Required Changes

Replace

DATABASE = {
'NAME': environ.get('DB_NAME', 'netbox'), # Database name
'USER': environ.get('DB_USER', ''), # PostgreSQL username
'PASSWORD': _read_secret('db_password', environ.get('DB_PASSWORD', '')),
# PostgreSQL password
'HOST': environ.get('DB_HOST', 'localhost'), # Database server
'PORT': environ.get('DB_PORT', ''), # Database port (leave blank for default)
'OPTIONS': {'sslmode': environ.get('DB_SSLMODE', 'prefer')},
# Database connection SSLMODE
'CONN_MAX_AGE': _environ_get_and_map('DB_CONN_MAX_AGE', '300', _AS_INT),
# Max database connection age
'DISABLE_SERVER_SIDE_CURSORS': _environ_get_and_map('DB_DISABLE_SERVER_SIDE_CURSORS', 'False', _AS_BOOL),
# Disable the use of server-side cursors transaction pooling
}

with

    DATABASE = {
        'NAME': environ.get('DB_NAME', 'netbox'),       # Database name
        'USER': environ.get('DB_USER', ''),             # PostgreSQL username
        'PASSWORD': environ.get('DB_PASSWORD', ''), # password
        'HOST': environ.get('DB_HOST', 'localhost'),    # Database server
        'PORT': environ.get('DB_PORT', ''),             # Database port (leave blank for default)
        'OPTIONS': {
          'sslmode': environ.get('DB_SSLMODE', 'prefer'), # Database connection SSLMODE
          'sslcert': environ.get('DB_CLIENT_SSL_CERT', None),
          'sslkey':  environ.get('DB_CLIENT_SSL_KEY',  None),
          'sslrootcert': environ.get('DB_CLIENT_SSL_CA', None)
        },
        'CONN_MAX_AGE': environ.get('DB_CONN_MAX_AGE', 300), # Max database connection age
        'DISABLE_SERVER_SIDE_CURSORS': environ.get('DB_DISABLE_SERVER_SIDE_CURSORS', False)
    }

(added sslcert, sslkey, sslrootcert parameters)

Discussion: Benefits and Drawbacks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions