diff --git a/dojo/middleware.py b/dojo/middleware.py index 8d274202f90..55d994bdb72 100644 --- a/dojo/middleware.py +++ b/dojo/middleware.py @@ -76,6 +76,7 @@ def __call__(self, request): uwsgi = __import__("uwsgi", globals(), locals(), ["set_logvar"], 0) # this populates dd_user log var, so can appear in the uwsgi logs uwsgi.set_logvar("dd_user", str(request.user)) + request.META["REMOTE_USER"] = str(request.user) return response @@ -338,3 +339,4 @@ def _trigger_async_index_update(self, model_groups): for i, batch in enumerate(batches, 1): logger.debug(f"AsyncSearchContextMiddleware: Triggering batch {i}/{len(batches)} for {model_name}: {len(batch)} instances") update_watson_search_index_for_model(model_name, batch) + diff --git a/dojo/remote_user.py b/dojo/remote_user.py index 2362a05ad30..8b285188d0f 100644 --- a/dojo/remote_user.py +++ b/dojo/remote_user.py @@ -43,6 +43,12 @@ def process_request(self, request): settings.AUTH_REMOTEUSER_TRUSTED_PROXY) return None + def process_response(self, request, response): + # Set REMOTE_USER so uWSGI logs the username correctly for all auth methods + if hasattr(request, "user") and request.user and request.user.is_authenticated: + request.META["REMOTE_USER"] = request.user.username + return response + class PersistentRemoteUserMiddleware(RemoteUserMiddleware): # same as https://github.com/django/django/blob/6654289f5b350dfca3dc4f6abab777459b906756/django/contrib/auth/middleware.py#L128