Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying database client certificates via environment variables #1105

Open
Jauchi opened this issue Oct 14, 2023 · 0 comments
Open

Comments

@Jauchi
Copy link

Jauchi commented Oct 14, 2023

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

crimmy68 pushed a commit to crimmy68/netbox-docker that referenced this issue Aug 31, 2024
also included variables in netbox.env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant