grim/containers/reviewboard

de25c03d102f
Parents 915dda3d764e
Children 087d8376a57e
Apply an upstream patch that _should_ solve our login issues
--- a/Dockerfile Wed Mar 22 02:28:06 2023 -0500
+++ b/Dockerfile Wed Mar 22 19:51:47 2023 -0500
@@ -17,6 +17,12 @@
RUN set -ex && \
pip install --no-cache rbjbhub
+# run through our patches
+COPY patches/ /patches/
+RUN set -ex && \
+ cd /venv/lib/python3.8/site-packages/ && \
+ find /patches -type f | sort --numeric-sort | xargs --no-run-if-empty --max-args=1 cat | patch --strip=1
+
FROM docker.io/nginx:1.21 AS nginx
COPY --from=app /venv/lib/python3.8/site-packages/reviewboard/htdocs /var/www/reviewboard/htdocs/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/01-redirect-field-name.patch Wed Mar 22 19:51:47 2023 -0500
@@ -0,0 +1,67 @@
+From 014c834a078de2bd923b86a0ccd7ce525264dea1 Mon Sep 17 00:00:00 2001
+From: David Trowbridge <trowbrds@gmail.com>
+Date: Sat, 18 Mar 2023 17:05:09 -0600
+Subject: [PATCH] Plumb through redirect URL when performing SAML autologin.
+
+When an SSO backend is configured to log in automatically, the redirect
+URL was being lost. We already have redirect URLs properly used in the
+SAML login view and SAML handshake, so this just required passing it
+along in the redirect from the login view to the SAML login view.
+
+Testing Done:
+Configured autologin for SAML and accessed /account/preferences/ while
+logged out. Saw that after the SSO flow, I was properly redirected to
+the account settings page rather than the dashboard.
+---
+ reviewboard/accounts/sso/backends/saml/views.py | 1 +
+ reviewboard/accounts/views.py | 13 ++++++++++++-
+ 2 files changed, 13 insertions(+), 1 deletion(-)
+
+diff --git a/reviewboard/accounts/sso/backends/saml/views.py b/reviewboard/accounts/sso/backends/saml/views.py
+index b91b732e21..3bcf7b137c 100644
+--- a/reviewboard/accounts/sso/backends/saml/views.py
++++ b/reviewboard/accounts/sso/backends/saml/views.py
+@@ -9,6 +9,7 @@
+ import logging
+
+ from django.conf import settings
++from django.contrib.auth import REDIRECT_FIELD_NAME
+ from django.contrib.auth.models import User
+ from django.contrib.auth.views import LoginView
+ from django.core.cache import cache
+diff --git a/reviewboard/accounts/views.py b/reviewboard/accounts/views.py
+index 0ce6a75935..0b89eb5c3d 100644
+--- a/reviewboard/accounts/views.py
++++ b/reviewboard/accounts/views.py
+@@ -1,4 +1,5 @@
+ import logging
++from urllib.parse import quote
+
+ from django.conf import settings
+ from django.contrib.auth.decorators import login_required
+@@ -13,6 +14,7 @@
+ from django.urls import reverse
+ from django.utils.decorators import method_decorator
+ from django.utils.functional import cached_property
++from django.utils.http import is_safe_url
+ from django.utils.safestring import mark_safe
+ from django.utils.translation import gettext_lazy as _
+ from django.views.decorators.csrf import csrf_protect
+@@ -79,7 +81,16 @@ def dispatch(self, request, *args, **kwargs):
+ if sso_auto_login_backend:
+ try:
+ backend = sso_backends.get('backend_id', sso_auto_login_backend)
+- return HttpResponseRedirect(backend.login_url)
++ login_url = backend.login_url
++
++ redirect_to = self.get_success_url()
++
++ if is_safe_url(url=redirect_to, host=request.get_host()):
++ login_url = '%s?%s=%s' % (login_url,
++ self.redirect_field_name,
++ quote(redirect_to))
++
++ return HttpResponseRedirect(login_url)
+ except sso_backends.ItemLookupError:
+ logging.error('Unable to find sso_auto_login_backend "%s".',
+ sso_auto_login_backend)