root: fix db backup failing when password has special chars

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-11 02:01:22 +02:00
parent 932b19999e
commit 172bfceb31
2 changed files with 17 additions and 3 deletions

View File

@ -0,0 +1,13 @@
"""Fix dbbackup quoting the password"""
from dbbackup.db.postgresql import PgDumpConnector
class PgCustom(PgDumpConnector):
"""Fix dbbackup quoting the password"""
def run_command(self, *args, **kwargs):
if self.settings.get("PASSWORD"):
env = kwargs.get("env", {})
env["PGPASSWORD"] = self.settings["PASSWORD"]
kwargs["env"] = env
return super(PgDumpConnector, self).run_command(*args, **kwargs)

View File

@ -321,7 +321,8 @@ CELERY_RESULT_BACKEND = (
DBBACKUP_STORAGE = "django.core.files.storage.FileSystemStorage" DBBACKUP_STORAGE = "django.core.files.storage.FileSystemStorage"
DBBACKUP_STORAGE_OPTIONS = {"location": "./backups" if DEBUG else "/backups"} DBBACKUP_STORAGE_OPTIONS = {"location": "./backups" if DEBUG else "/backups"}
DBBACKUP_CONNECTOR_MAPPING = { DBBACKUP_CONNECTOR_MAPPING = {
"django_prometheus.db.backends.postgresql": "dbbackup.db.postgresql.PgDumpConnector" "django_prometheus.db.backends.postgresql": "authentik.lib.connector.PgCustom",
"django.db.backends.postgresql": "authentik.lib.connector.PgCustom",
} }
if CONFIG.y("postgresql.s3_backup"): if CONFIG.y("postgresql.s3_backup"):
DBBACKUP_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" DBBACKUP_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
@ -334,7 +335,7 @@ if CONFIG.y("postgresql.s3_backup"):
"endpoint_url": CONFIG.y("postgresql.s3_backup.host"), "endpoint_url": CONFIG.y("postgresql.s3_backup.host"),
} }
j_print( j_print(
"Database backup to S3 is configured.", "Database backup to S3 is configured",
host=CONFIG.y("postgresql.s3_backup.host"), host=CONFIG.y("postgresql.s3_backup.host"),
) )
@ -356,7 +357,7 @@ if _ERROR_REPORTING:
send_default_pii=CONFIG.y_bool("error_reporting.send_pii", False), send_default_pii=CONFIG.y_bool("error_reporting.send_pii", False),
) )
j_print( j_print(
"Error reporting is enabled.", "Error reporting is enabled",
env=CONFIG.y("error_reporting.environment", "customer"), env=CONFIG.y("error_reporting.environment", "customer"),
) )