From 35232afa7eae8232c24fc8f7e4e0e7581ed659b9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 7 Apr 2021 15:29:45 +0200 Subject: [PATCH] core: skip backup when running in k8s and s3 backup not configured Signed-off-by: Jens Langhammer --- authentik/core/tasks.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/authentik/core/tasks.py b/authentik/core/tasks.py index 6a4072a66..d03bc7eb4 100644 --- a/authentik/core/tasks.py +++ b/authentik/core/tasks.py @@ -1,6 +1,7 @@ """authentik core tasks""" from datetime import datetime from io import StringIO +from pathlib import Path from boto3.exceptions import Boto3Error from botocore.exceptions import BotoCoreError, ClientError @@ -12,6 +13,7 @@ from structlog.stdlib import get_logger from authentik.core.models import ExpiringModel from authentik.events.monitored_tasks import MonitoredTask, TaskResult, TaskResultStatus +from authentik.lib.config import CONFIG from authentik.root.celery import CELERY_APP LOGGER = get_logger() @@ -38,6 +40,22 @@ def clean_expired_models(self: MonitoredTask): def backup_database(self: MonitoredTask): # pragma: no cover """Database backup""" self.result_timeout_hours = 25 + if Path("/var/run/secrets/kubernetes.io").exists() and not CONFIG.y( + "postgresql.s3_backup" + ): + LOGGER.info("Running in k8s and s3 backups are not configured, skipping") + self.set_status( + TaskResult( + TaskResultStatus.WARNING, + [ + ( + "Skipping backup as authentik is running in Kubernetes " + "without S3 backups configured." + ), + ], + ) + ) + return try: start = datetime.now() out = StringIO()