Skip to content

Commit 33fadea

Browse files
✨(backend) make forward auth request uri header configurable
In our deployment we're using Traefik, not nginx, as an ingress. Traefik uses X-Forwarded-Uri instead of X-Original-Uri. This adds a setting which lets users adapt Docs to their ingress proxy of choice Signed-off-by: Erin Shepherd <erin.shepherd@e43.eu>
1 parent e747e03 commit 33fadea

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/backend/core/api/viewsets.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,10 +1777,13 @@ def attachment_upload(self, request, *args, **kwargs):
17771777

17781778
def _auth_get_original_url(self, request):
17791779
"""
1780-
Extracts and parses the original URL from the "HTTP_X_ORIGINAL_URL" header.
1780+
Extracts and parses the original URL from the configured parameter header.
17811781
Raises PermissionDenied if the header is missing.
17821782
1783-
The original url is passed by nginx in the "HTTP_X_ORIGINAL_URL" header.
1783+
The original url is passed by reverse proxy in the header
1784+
MEDIA_AUTH_URL_PARAMETER setting.
1785+
1786+
For nginx (the default) this is set to HTTP_X_ORIGINAL_URL.
17841787
See corresponding ingress configuration in Helm chart and read about the
17851788
nginx.ingress.kubernetes.io/auth-url annotation to understand how the Nginx ingress
17861789
is configured to do this.
@@ -1791,9 +1794,9 @@ def _auth_get_original_url(self, request):
17911794
reasons.
17921795
"""
17931796
# Extract the original URL from the request header
1794-
original_url = request.META.get("HTTP_X_ORIGINAL_URL")
1797+
original_url = request.META.get(settings.MEDIA_AUTH_URL_PARAMETER)
17951798
if not original_url:
1796-
logger.debug("Missing HTTP_X_ORIGINAL_URL header in subrequest")
1799+
logger.debug(f"Missing {settings.MEDIA_AUTH_URL_PARAMETER} header in subrequest")
17971800
raise drf.exceptions.PermissionDenied()
17981801

17991802
logger.debug("Original url: '%s'", original_url)

src/backend/impress/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class Base(Configuration):
129129
default=50, environ_name="SEARCH_INDEXER_QUERY_LIMIT", environ_prefix=None
130130
)
131131

132+
MEDIA_AUTH_URL_PARAMETER = values.Value(
133+
default="HTTP_X_ORIGINAL_URL", environ_name="MEDIA_AUTH_URL_PARAMETER", environ_prefix=None)
134+
132135
# Static files (CSS, JavaScript, Images)
133136
STATIC_URL = "/static/"
134137
STATIC_ROOT = os.path.join(DATA_DIR, "static")

0 commit comments

Comments
 (0)