mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Add PostgreSQL & Redis TLS/mTLS support (#3435)
This commit is contained in:
committed by
GitHub
parent
6dbbfe3b04
commit
b35a388685
@@ -116,6 +116,29 @@ elif 'mysql' in db_backend:
|
||||
|
||||
db_options = {}
|
||||
|
||||
postgresql_sslmode = config.get('database', 'sslmode', fallback='disable')
|
||||
USE_DATABASE_TLS = postgresql_sslmode != 'disable'
|
||||
USE_DATABASE_MTLS = USE_DATABASE_TLS and config.has_option('database', 'sslcert')
|
||||
|
||||
if USE_DATABASE_TLS or USE_DATABASE_MTLS:
|
||||
tls_config = {}
|
||||
if not USE_DATABASE_MTLS:
|
||||
if 'postgresql' in db_backend:
|
||||
tls_config = {
|
||||
'sslmode': config.get('database', 'sslmode'),
|
||||
'sslrootcert': config.get('database', 'sslrootcert'),
|
||||
}
|
||||
else:
|
||||
if 'postgresql' in db_backend:
|
||||
tls_config = {
|
||||
'sslmode': config.get('database', 'sslmode'),
|
||||
'sslrootcert': config.get('database', 'sslrootcert'),
|
||||
'sslcert': config.get('database', 'sslcert'),
|
||||
'sslkey': config.get('database', 'sslkey'),
|
||||
}
|
||||
|
||||
db_options.update(tls_config)
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.' + db_backend,
|
||||
@@ -228,6 +251,9 @@ if HAS_MEMCACHED:
|
||||
|
||||
HAS_REDIS = config.has_option('redis', 'location')
|
||||
USE_REDIS_SENTINEL = config.has_option('redis', 'sentinels')
|
||||
redis_ssl_cert_reqs = config.get('redis', 'ssl_cert_reqs', fallback='none')
|
||||
USE_REDIS_TLS = redis_ssl_cert_reqs != 'none'
|
||||
USE_REDIS_MTLS = USE_REDIS_TLS and config.has_option('redis', 'ssl_certfile')
|
||||
HAS_REDIS_PASSWORD = config.has_option('redis', 'password')
|
||||
if HAS_REDIS:
|
||||
OPTIONS = {
|
||||
@@ -243,6 +269,29 @@ if HAS_REDIS:
|
||||
OPTIONS["SENTINEL_KWARGS"] = {"socket_timeout": 1}
|
||||
OPTIONS["SENTINELS"] = [tuple(sentinel) for sentinel in loads(config.get('redis', 'sentinels'))]
|
||||
|
||||
if USE_REDIS_TLS or USE_REDIS_MTLS:
|
||||
tls_config = {}
|
||||
if not USE_REDIS_MTLS:
|
||||
tls_config = {
|
||||
'ssl_cert_reqs': config.get('redis', 'ssl_cert_reqs'),
|
||||
'ssl_ca_certs': config.get('redis', 'ssl_ca_certs'),
|
||||
}
|
||||
else:
|
||||
tls_config = {
|
||||
'ssl_cert_reqs': config.get('redis', 'ssl_cert_reqs'),
|
||||
'ssl_ca_certs': config.get('redis', 'ssl_ca_certs'),
|
||||
'ssl_keyfile': config.get('redis', 'ssl_keyfile'),
|
||||
'ssl_certfile': config.get('redis', 'ssl_certfile'),
|
||||
}
|
||||
|
||||
if USE_REDIS_SENTINEL is False:
|
||||
# The CONNECTION_POOL_KWARGS option is necessary for self-signed certs. For further details, please check
|
||||
# https://github.com/jazzband/django-redis/issues/554#issuecomment-949498321
|
||||
OPTIONS["CONNECTION_POOL_KWARGS"] = tls_config
|
||||
OPTIONS["REDIS_CLIENT_KWARGS"].update(tls_config)
|
||||
else:
|
||||
OPTIONS["SENTINEL_KWARGS"].update(tls_config)
|
||||
|
||||
if HAS_REDIS_PASSWORD:
|
||||
OPTIONS["PASSWORD"] = config.get('redis', 'password')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user