From 64d4a19ccfe74db6feadf3d3321f690643514725 Mon Sep 17 00:00:00 2001 From: Jens L Date: Thu, 18 Apr 2024 20:53:27 +0200 Subject: [PATCH] root: expose session storage configuration (#9337) * root: expose session storage configuration Signed-off-by: Jens Langhammer * fix Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- authentik/lib/default.yml | 2 ++ authentik/root/settings.py | 11 ++++++++++- website/docs/installation/configuration.mdx | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/authentik/lib/default.yml b/authentik/lib/default.yml index 149c0c0cc7..61f74e78c3 100644 --- a/authentik/lib/default.yml +++ b/authentik/lib/default.yml @@ -59,6 +59,8 @@ remote_debug: false log_level: info +session_storage: cache + error_reporting: enabled: false sentry_dsn: https://151ba72610234c4c97c5bcff4e1cffd8@authentik.error-reporting.a7k.io/4504163677503489 diff --git a/authentik/root/settings.py b/authentik/root/settings.py index 7d3bf211ec..00f959a766 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -7,6 +7,7 @@ from hashlib import sha512 from pathlib import Path from celery.schedules import crontab +from django.conf import ImproperlyConfigured from sentry_sdk import set_tag from authentik import ENV_GIT_HASH_KEY, __version__ @@ -211,7 +212,15 @@ CACHES = { DJANGO_REDIS_SCAN_ITERSIZE = 1000 DJANGO_REDIS_IGNORE_EXCEPTIONS = True DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True -SESSION_ENGINE = "django.contrib.sessions.backends.cache" +match CONFIG.get("session_storage", "cache"): + case "cache": + SESSION_ENGINE = "django.contrib.sessions.backends.cache" + case "db": + SESSION_ENGINE = "django.contrib.sessions.backends.db" + case _: + raise ImproperlyConfigured( + "Invalid session_storage setting, allowed values are db and cache" + ) SESSION_SERIALIZER = "authentik.root.sessions.pickle.PickleSerializer" SESSION_CACHE_ALIAS = "default" # Configured via custom SessionMiddleware diff --git a/website/docs/installation/configuration.mdx b/website/docs/installation/configuration.mdx index d11669aa56..ddcabd51e4 100644 --- a/website/docs/installation/configuration.mdx +++ b/website/docs/installation/configuration.mdx @@ -313,6 +313,14 @@ Configure how long reputation scores should be saved for in seconds. Note that t Defaults to `86400`. +### `AUTHENTIK_SESSION_STORAGE` + +:::info +Requires authentik 2024.4 +::: + +Configure if the sessions are stored in the cache or the database. Defaults to `cache`. Allowed values are `cache` and `db`. Note that changing this value will invalidate all previous sessions. + ### `AUTHENTIK_WEB__WORKERS` :::info