From 172bfceb31ffc195d4cc68063ab5c802474a672a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 11 May 2021 02:01:22 +0200 Subject: [PATCH] root: fix db backup failing when password has special chars Signed-off-by: Jens Langhammer --- authentik/lib/connector.py | 13 +++++++++++++ authentik/root/settings.py | 7 ++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 authentik/lib/connector.py diff --git a/authentik/lib/connector.py b/authentik/lib/connector.py new file mode 100644 index 0000000000..3ba0e25cac --- /dev/null +++ b/authentik/lib/connector.py @@ -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) diff --git a/authentik/root/settings.py b/authentik/root/settings.py index 914c00daf3..747aa9fb13 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -321,7 +321,8 @@ CELERY_RESULT_BACKEND = ( DBBACKUP_STORAGE = "django.core.files.storage.FileSystemStorage" DBBACKUP_STORAGE_OPTIONS = {"location": "./backups" if DEBUG else "/backups"} 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"): DBBACKUP_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" @@ -334,7 +335,7 @@ if CONFIG.y("postgresql.s3_backup"): "endpoint_url": CONFIG.y("postgresql.s3_backup.host"), } j_print( - "Database backup to S3 is configured.", + "Database backup to S3 is configured", 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), ) j_print( - "Error reporting is enabled.", + "Error reporting is enabled", env=CONFIG.y("error_reporting.environment", "customer"), )