From d91f499dc8a40c23ebd9ea606ae8dbc9d211fbdb Mon Sep 17 00:00:00 2001 From: Oliver Walsh Date: Fri, 2 Feb 2024 11:53:50 +0000 Subject: [PATCH] Enabled memcached session backend and clear cache when service config changes The keystone endpoint is cached and may not be valid across config changes. Toggling keystone TLS in particular will change the keystone url and break any existing horizon session. This switches from cookie session backend to memcached backend and uses the CONFIG_HASH as the cache prefix to ensure caches are invalidated if/when the config changes. Jira: OSPRH-4392 --- templates/horizon/config/local_settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/horizon/config/local_settings.py b/templates/horizon/config/local_settings.py index 05f97f5c..137a158e 100644 --- a/templates/horizon/config/local_settings.py +++ b/templates/horizon/config/local_settings.py @@ -95,7 +95,9 @@ CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache', - 'LOCATION': [ {{.memcachedServers}} ] + 'LOCATION': [ {{.memcachedServers}} ], + # To drop the cached sessions when config changes + 'KEY_PREFIX': os.environ['CONFIG_HASH'] }, } @@ -103,6 +105,7 @@ # SESSION_ENGINE to django.contrib.sessions.backends.signed_cookies # as shown below: #SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' +SESSION_ENGINE = 'django.contrib.sessions.backends.cache' # Send email to the console by default