We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Redis (Unix) Socket?
**Describe your question/**
Is it possible to run an authentik docker container (server and worker) with a redis unix socket rather than tcp?
Directly overwriting redis variables via user_settings.py doesn't appear to modify anything despite @BeryJu suggesting in [pull request #4036](https://github.com/goauthentik/authentik/pull/4036) it should be viable.

**Relevant infos**
Docker compose:
version: '3.4'

services:
  server:
    image: ${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server}:latest
    restart: unless-stopped
    command: server
    environment:
      AUTHENTIK_POSTGRESQL__HOST: ${PG_HOST}
      AUTHENTIK_POSTGRESQL__USER: ${PG_USER}
      AUTHENTIK_POSTGRESQL__NAME: ${PG_NAME}
      AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}
      AUTHENTIK_REDIS__HOST: ${REDIS_HOST}
      AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
      AUTHENTIK_LISTEN__HTTP: ${AUTHENTIK_LISTEN__HTTP}
      AUTHENTIK_LISTEN__HTTPS: ${AUTHENTIK_LISTEN__HTTPS}
    volumes:
      - ./media:/media
      - ./custom-templates:/templates
      - /run/redis/redis-server.sock:/run/redis/redis-server.sock
      - /var/run/postgresql/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432
      - ./user_settings.py:/data/user_settings.py
    ports:
      - "${AUTHENTIK_PORT_HTTP}:${AUTHENTIK_PORT_HTTP}"
      - "${AUTHENTIK_PORT_HTTPS}:${AUTHENTIK_PORT_HTTPS}"
  worker:
    image: ${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server}:latest
    restart: unless-stopped
    command: worker
    environment:
      AUTHENTIK_POSTGRESQL__HOST: ${PG_HOST}
      AUTHENTIK_POSTGRESQL__USER: ${PG_USER}
      AUTHENTIK_POSTGRESQL__NAME: ${PG_NAME}
      AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}
      AUTHENTIK_REDIS__HOST: ${REDIS_HOST}
      AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
    user: authentik
    volumes:
      - ./media:/media
      - ./certs:/certs
      - ./custom-templates:/templates
      - /run/docker.sock:/var/run/docker.sock
      - /run/redis/redis-server.sock:/run/redis/redis-server.sock
      - /var/run/postgresql/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432
      - ./user_settings.py:/data/user_settings.py

I didn't include the definition for ${REDIS_HOST} as sockets cannot be passed via environmental variables per [pull 4036](https://github.com/goauthentik/authentik/pull/4036).

**Logs**
DBG undefined | event=Loaded config logger=authentik.lib.config timestamp=1679734632.5913134 file=/authentik/lib/default.yml 
DBG undefined | event=Loaded environment variables logger=authentik.lib.config timestamp=1679734632.5915806 count=7 
INF undefined | event=Starting authentik bootstrap logger=authentik.lib.config timestamp=1679734632.59165 
INF undefined | event=PostgreSQL connection successful logger=authentik.lib.config timestamp=1679734632.5988 
INF undefined | event=Redis Connection failed, retrying... (Error 99 connecting to localhost:6379. Cannot assign requested address.) logger=authentik.lib.config timestamp=1679734633.600902 redis_url=redis://:@localhost:6379/0 

**Version and Deployment (please complete the following information):**
 - authentik version: 2023.3
 - Deployment: docker-compose

**Additional context**
docker exec -it authentik-stack-server-1 bash
authentik@283a42f97c09:/$ cd /data
authentik@283a42f97c09:/data$ ls -la
total 27
drwxr-xr-x  2 root root           3 Mar 25 08:24 .
drwxr-xr-x 33 root root          39 Mar 25 08:24 ..
-rw-rw-r--  1 1022 _runit-log 16463 Mar 25 08:45 user_settings.py
authentik@283a42f97c09:/data$ cat user_settings.py | grep redis
REDIS_PROTOCOL_PREFIX = "redis://"
if CONFIG.y_bool("redis.tls", False):
    REDIS_PROTOCOL_PREFIX = "rediss://"
    REDIS_CELERY_TLS_REQUIREMENTS = f"?ssl_cert_reqs={CONFIG.y('redis.tls_reqs')}"
_redis_url = (
    f"{quote_plus(CONFIG.y('redis.password'))}@{quote_plus(CONFIG.y('redis.host'))}:"
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": 'unix://run/redis/redis-server.sock',
        "TIMEOUT": int(CONFIG.y("redis.cache_timeout", 300)),
        "OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"},
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": 'unix://run/redis/redis-server.sock',
CELERY_BROKER_URL = 'redis+socket:///run/redis/redis-server.sock'
CELERY_RESULT_BACKEND = 'redis+socket:///run/redis/redis-server.sock'
    "redis": "WARNING",
authentik@283a42f97c09:/data$ 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lifecycle/wait_for_db.py`
Content:
```
1 #!/usr/bin/env python
2 """This file needs to be run from the root of the project to correctly
3 import authentik. This is done by the dockerfile."""
4 from sys import exit as sysexit
5 from time import sleep
6 from urllib.parse import quote_plus
7 
8 from psycopg import OperationalError, connect
9 from redis import Redis
10 from redis.exceptions import RedisError
11 
12 from authentik.lib.config import CONFIG, redis_url
13 
14 
15 def check_postgres():
16     while True:
17         try:
18             conn = connect(
19                 dbname=CONFIG.get("postgresql.name"),
20                 user=CONFIG.get("postgresql.user"),
21                 password=CONFIG.get("postgresql.password"),
22                 host=CONFIG.get("postgresql.host"),
23                 port=CONFIG.get_int("postgresql.port"),
24                 sslmode=CONFIG.get("postgresql.sslmode"),
25                 sslrootcert=CONFIG.get("postgresql.sslrootcert"),
26                 sslcert=CONFIG.get("postgresql.sslcert"),
27                 sslkey=CONFIG.get("postgresql.sslkey"),
28             )
29             conn.cursor()
30             break
31         except OperationalError as exc:
32             sleep(1)
33             CONFIG.log("info", f"PostgreSQL connection failed, retrying... ({exc})")
34     CONFIG.log("info", "PostgreSQL connection successful")
35 
36 
37 def check_redis():
38     url = redis_url(CONFIG.get("redis.db"))
39     while True:
40         try:
41             redis = Redis.from_url(url)
42             redis.ping()
43             break
44         except RedisError as exc:
45             sleep(1)
46             sanitized_url = url.replace(quote_plus(CONFIG.get("redis.password")), "******")
47             CONFIG.log(
48                 "info", f"Redis Connection failed, retrying... ({exc})", redis_url=sanitized_url
49             )
50     CONFIG.log("info", "Redis Connection successful")
51 
52 
53 def wait_for_db():
54     CONFIG.log("info", "Starting authentik bootstrap")
55     # Sanity check, ensure SECRET_KEY is set before we even check for database connectivity
56     if CONFIG.get("secret_key") is None or len(CONFIG.get("secret_key")) == 0:
57         CONFIG.log("info", "----------------------------------------------------------------------")
58         CONFIG.log("info", "Secret key missing, check https://goauthentik.io/docs/installation/.")
59         CONFIG.log("info", "----------------------------------------------------------------------")
60         sysexit(1)
61     check_postgres()
62     check_redis()
63     CONFIG.log("info", "Finished authentik bootstrap")
64 
65 
66 if __name__ == "__main__":
67     wait_for_db()
68
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lifecycle/wait_for_db.py b/lifecycle/wait_for_db.py
--- a/lifecycle/wait_for_db.py
+++ b/lifecycle/wait_for_db.py
@@ -3,7 +3,6 @@
 import authentik. This is done by the dockerfile."""
 from sys import exit as sysexit
 from time import sleep
-from urllib.parse import quote_plus
 
 from psycopg import OperationalError, connect
 from redis import Redis
@@ -35,7 +34,7 @@
 
 
 def check_redis():
-    url = redis_url(CONFIG.get("redis.db"))
+    url = CONFIG.get("cache.url") or redis_url(CONFIG.get("redis.db"))
     while True:
         try:
             redis = Redis.from_url(url)
@@ -43,10 +42,7 @@
             break
         except RedisError as exc:
             sleep(1)
-            sanitized_url = url.replace(quote_plus(CONFIG.get("redis.password")), "******")
-            CONFIG.log(
-                "info", f"Redis Connection failed, retrying... ({exc})", redis_url=sanitized_url
-            )
+            CONFIG.log("info", f"Redis Connection failed, retrying... ({exc})")
     CONFIG.log("info", "Redis Connection successful")

{"golden_diff": "diff --git a/lifecycle/wait_for_db.py b/lifecycle/wait_for_db.py\n--- a/lifecycle/wait_for_db.py\n+++ b/lifecycle/wait_for_db.py\n@@ -3,7 +3,6 @@\n import authentik. This is done by the dockerfile.\"\"\"\n from sys import exit as sysexit\n from time import sleep\n-from urllib.parse import quote_plus\n \n from psycopg import OperationalError, connect\n from redis import Redis\n@@ -35,7 +34,7 @@\n \n \n def check_redis():\n-    url = redis_url(CONFIG.get(\"redis.db\"))\n+    url = CONFIG.get(\"cache.url\") or redis_url(CONFIG.get(\"redis.db\"))\n     while True:\n         try:\n             redis = Redis.from_url(url)\n@@ -43,10 +42,7 @@\n             break\n         except RedisError as exc:\n             sleep(1)\n-            sanitized_url = url.replace(quote_plus(CONFIG.get(\"redis.password\")), \"******\")\n-            CONFIG.log(\n-                \"info\", f\"Redis Connection failed, retrying... ({exc})\", redis_url=sanitized_url\n-            )\n+            CONFIG.log(\"info\", f\"Redis Connection failed, retrying... ({exc})\")\n     CONFIG.log(\"info\", \"Redis Connection successful\")\n", "issue": "Redis (Unix) Socket?\n**Describe your question/**\r\nIs it possible to run an authentik docker container (server and worker) with a redis unix socket rather than tcp?\r\nDirectly overwriting redis variables via user_settings.py doesn't appear to modify anything despite @BeryJu suggesting in [pull request #4036](https://github.com/goauthentik/authentik/pull/4036) it should be viable.\r\n\r\n**Relevant infos**\r\nDocker compose:\r\nversion: '3.4'\r\n\r\nservices:\r\n  server:\r\n    image: ${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server}:latest\r\n    restart: unless-stopped\r\n    command: server\r\n    environment:\r\n      AUTHENTIK_POSTGRESQL__HOST: ${PG_HOST}\r\n      AUTHENTIK_POSTGRESQL__USER: ${PG_USER}\r\n      AUTHENTIK_POSTGRESQL__NAME: ${PG_NAME}\r\n      AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}\r\n      AUTHENTIK_REDIS__HOST: ${REDIS_HOST}\r\n      AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}\r\n      AUTHENTIK_LISTEN__HTTP: ${AUTHENTIK_LISTEN__HTTP}\r\n      AUTHENTIK_LISTEN__HTTPS: ${AUTHENTIK_LISTEN__HTTPS}\r\n    volumes:\r\n      - ./media:/media\r\n      - ./custom-templates:/templates\r\n      - /run/redis/redis-server.sock:/run/redis/redis-server.sock\r\n      - /var/run/postgresql/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432\r\n      - ./user_settings.py:/data/user_settings.py\r\n    ports:\r\n      - \"${AUTHENTIK_PORT_HTTP}:${AUTHENTIK_PORT_HTTP}\"\r\n      - \"${AUTHENTIK_PORT_HTTPS}:${AUTHENTIK_PORT_HTTPS}\"\r\n  worker:\r\n    image: ${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server}:latest\r\n    restart: unless-stopped\r\n    command: worker\r\n    environment:\r\n      AUTHENTIK_POSTGRESQL__HOST: ${PG_HOST}\r\n      AUTHENTIK_POSTGRESQL__USER: ${PG_USER}\r\n      AUTHENTIK_POSTGRESQL__NAME: ${PG_NAME}\r\n      AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}\r\n      AUTHENTIK_REDIS__HOST: ${REDIS_HOST}\r\n      AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}\r\n    user: authentik\r\n    volumes:\r\n      - ./media:/media\r\n      - ./certs:/certs\r\n      - ./custom-templates:/templates\r\n      - /run/docker.sock:/var/run/docker.sock\r\n      - /run/redis/redis-server.sock:/run/redis/redis-server.sock\r\n      - /var/run/postgresql/.s.PGSQL.5432:/var/run/postgresql/.s.PGSQL.5432\r\n      - ./user_settings.py:/data/user_settings.py\r\n\r\nI didn't include the definition for ${REDIS_HOST} as sockets cannot be passed via environmental variables per [pull 4036](https://github.com/goauthentik/authentik/pull/4036).\r\n\r\n**Logs**\r\nDBG undefined | event=Loaded config logger=authentik.lib.config timestamp=1679734632.5913134 file=/authentik/lib/default.yml \r\nDBG undefined | event=Loaded environment variables logger=authentik.lib.config timestamp=1679734632.5915806 count=7 \r\nINF undefined | event=Starting authentik bootstrap logger=authentik.lib.config timestamp=1679734632.59165 \r\nINF undefined | event=PostgreSQL connection successful logger=authentik.lib.config timestamp=1679734632.5988 \r\nINF undefined | event=Redis Connection failed, retrying... (Error 99 connecting to localhost:6379. Cannot assign requested address.) logger=authentik.lib.config timestamp=1679734633.600902 redis_url=redis://:@localhost:6379/0 \r\n\r\n**Version and Deployment (please complete the following information):**\r\n - authentik version: 2023.3\r\n - Deployment: docker-compose\r\n\r\n**Additional context**\r\ndocker exec -it authentik-stack-server-1 bash\r\nauthentik@283a42f97c09:/$ cd /data\r\nauthentik@283a42f97c09:/data$ ls -la\r\ntotal 27\r\ndrwxr-xr-x  2 root root           3 Mar 25 08:24 .\r\ndrwxr-xr-x 33 root root          39 Mar 25 08:24 ..\r\n-rw-rw-r--  1 1022 _runit-log 16463 Mar 25 08:45 user_settings.py\r\nauthentik@283a42f97c09:/data$ cat user_settings.py | grep redis\r\nREDIS_PROTOCOL_PREFIX = \"redis://\"\r\nif CONFIG.y_bool(\"redis.tls\", False):\r\n    REDIS_PROTOCOL_PREFIX = \"rediss://\"\r\n    REDIS_CELERY_TLS_REQUIREMENTS = f\"?ssl_cert_reqs={CONFIG.y('redis.tls_reqs')}\"\r\n_redis_url = (\r\n    f\"{quote_plus(CONFIG.y('redis.password'))}@{quote_plus(CONFIG.y('redis.host'))}:\"\r\n        \"BACKEND\": \"django_redis.cache.RedisCache\",\r\n        \"LOCATION\": 'unix://run/redis/redis-server.sock',\r\n        \"TIMEOUT\": int(CONFIG.y(\"redis.cache_timeout\", 300)),\r\n        \"OPTIONS\": {\"CLIENT_CLASS\": \"django_redis.client.DefaultClient\"},\r\n        \"BACKEND\": \"channels_redis.core.RedisChannelLayer\",\r\n        \"BACKEND\": \"django_redis.cache.RedisCache\",\r\n        \"LOCATION\": 'unix://run/redis/redis-server.sock',\r\nCELERY_BROKER_URL = 'redis+socket:///run/redis/redis-server.sock'\r\nCELERY_RESULT_BACKEND = 'redis+socket:///run/redis/redis-server.sock'\r\n    \"redis\": \"WARNING\",\r\nauthentik@283a42f97c09:/data$ \n", "before_files": [{"content": "#!/usr/bin/env python\n\"\"\"This file needs to be run from the root of the project to correctly\nimport authentik. This is done by the dockerfile.\"\"\"\nfrom sys import exit as sysexit\nfrom time import sleep\nfrom urllib.parse import quote_plus\n\nfrom psycopg import OperationalError, connect\nfrom redis import Redis\nfrom redis.exceptions import RedisError\n\nfrom authentik.lib.config import CONFIG, redis_url\n\n\ndef check_postgres():\n    while True:\n        try:\n            conn = connect(\n                dbname=CONFIG.get(\"postgresql.name\"),\n                user=CONFIG.get(\"postgresql.user\"),\n                password=CONFIG.get(\"postgresql.password\"),\n                host=CONFIG.get(\"postgresql.host\"),\n                port=CONFIG.get_int(\"postgresql.port\"),\n                sslmode=CONFIG.get(\"postgresql.sslmode\"),\n                sslrootcert=CONFIG.get(\"postgresql.sslrootcert\"),\n                sslcert=CONFIG.get(\"postgresql.sslcert\"),\n                sslkey=CONFIG.get(\"postgresql.sslkey\"),\n            )\n            conn.cursor()\n            break\n        except OperationalError as exc:\n            sleep(1)\n            CONFIG.log(\"info\", f\"PostgreSQL connection failed, retrying... ({exc})\")\n    CONFIG.log(\"info\", \"PostgreSQL connection successful\")\n\n\ndef check_redis():\n    url = redis_url(CONFIG.get(\"redis.db\"))\n    while True:\n        try:\n            redis = Redis.from_url(url)\n            redis.ping()\n            break\n        except RedisError as exc:\n            sleep(1)\n            sanitized_url = url.replace(quote_plus(CONFIG.get(\"redis.password\")), \"******\")\n            CONFIG.log(\n                \"info\", f\"Redis Connection failed, retrying... ({exc})\", redis_url=sanitized_url\n            )\n    CONFIG.log(\"info\", \"Redis Connection successful\")\n\n\ndef wait_for_db():\n    CONFIG.log(\"info\", \"Starting authentik bootstrap\")\n    # Sanity check, ensure SECRET_KEY is set before we even check for database connectivity\n    if CONFIG.get(\"secret_key\") is None or len(CONFIG.get(\"secret_key\")) == 0:\n        CONFIG.log(\"info\", \"----------------------------------------------------------------------\")\n        CONFIG.log(\"info\", \"Secret key missing, check https://goauthentik.io/docs/installation/.\")\n        CONFIG.log(\"info\", \"----------------------------------------------------------------------\")\n        sysexit(1)\n    check_postgres()\n    check_redis()\n    CONFIG.log(\"info\", \"Finished authentik bootstrap\")\n\n\nif __name__ == \"__main__\":\n    wait_for_db()\n", "path": "lifecycle/wait_for_db.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\"\"\"This file needs to be run from the root of the project to correctly\nimport authentik. This is done by the dockerfile.\"\"\"\nfrom sys import exit as sysexit\nfrom time import sleep\n\nfrom psycopg import OperationalError, connect\nfrom redis import Redis\nfrom redis.exceptions import RedisError\n\nfrom authentik.lib.config import CONFIG, redis_url\n\n\ndef check_postgres():\n    while True:\n        try:\n            conn = connect(\n                dbname=CONFIG.get(\"postgresql.name\"),\n                user=CONFIG.get(\"postgresql.user\"),\n                password=CONFIG.get(\"postgresql.password\"),\n                host=CONFIG.get(\"postgresql.host\"),\n                port=CONFIG.get_int(\"postgresql.port\"),\n                sslmode=CONFIG.get(\"postgresql.sslmode\"),\n                sslrootcert=CONFIG.get(\"postgresql.sslrootcert\"),\n                sslcert=CONFIG.get(\"postgresql.sslcert\"),\n                sslkey=CONFIG.get(\"postgresql.sslkey\"),\n            )\n            conn.cursor()\n            break\n        except OperationalError as exc:\n            sleep(1)\n            CONFIG.log(\"info\", f\"PostgreSQL connection failed, retrying... ({exc})\")\n    CONFIG.log(\"info\", \"PostgreSQL connection successful\")\n\n\ndef check_redis():\n    url = CONFIG.get(\"cache.url\") or redis_url(CONFIG.get(\"redis.db\"))\n    while True:\n        try:\n            redis = Redis.from_url(url)\n            redis.ping()\n            break\n        except RedisError as exc:\n            sleep(1)\n            CONFIG.log(\"info\", f\"Redis Connection failed, retrying... ({exc})\")\n    CONFIG.log(\"info\", \"Redis Connection successful\")\n\n\ndef wait_for_db():\n    CONFIG.log(\"info\", \"Starting authentik bootstrap\")\n    # Sanity check, ensure SECRET_KEY is set before we even check for database connectivity\n    if CONFIG.get(\"secret_key\") is None or len(CONFIG.get(\"secret_key\")) == 0:\n        CONFIG.log(\"info\", \"----------------------------------------------------------------------\")\n        CONFIG.log(\"info\", \"Secret key missing, check https://goauthentik.io/docs/installation/.\")\n        CONFIG.log(\"info\", \"----------------------------------------------------------------------\")\n        sysexit(1)\n    check_postgres()\n    check_redis()\n    CONFIG.log(\"info\", \"Finished authentik bootstrap\")\n\n\nif __name__ == \"__main__\":\n    wait_for_db()\n", "path": "lifecycle/wait_for_db.py"}]}