Skip to content

Commit e846332

Browse files
committed
Add saml2 as an optional dependency
Activate SAML2 endpoints in case a SAML_CONFIG is provided.
1 parent 9efd16d commit e846332

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

.github/workflows/scripts/before_install.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ services:
7979
image: "docker.io/pulp/pulp-fixtures:latest"
8080
env:
8181
BASE_URL: "http://pulp-fixtures:8080"
82+
- name: "saml2-idp"
83+
image: "ghcr.io/pfrest/mock-saml2-idp:latest"
84+
env:
85+
SP_ENTITY_ID: "http://pulp"
86+
SP_ACS_LOCATION: "http://pulp/saml/acs/"
8287
VARSYAML
8388

8489
if [ "$TEST" = "s3" ]; then

ci_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
pulpcore[saml2]

pulpcore/app/settings.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from django.core.exceptions import ImproperlyConfigured
2020
from dynaconf import DjangoDynaconf, Dynaconf, Validator
2121
from dynaconf.base import Settings
22-
from dynaconf.utils.functional import empty
2322

2423
from pulpcore import constants
2524

@@ -606,8 +605,24 @@ def otel_middleware_hook(settings):
606605
return data
607606

608607

608+
def saml2_settings_hook(settings):
609+
data = {"dynaconf_merge": True}
610+
if "SAML_CONFIG" in settings:
611+
data["INSTALLED_APPS"] = ["djangosaml2"]
612+
data["MIDDLEWARE"] = ["djangosaml2.middleware.SamlSessionMiddleware"]
613+
data["AUTHENTICATION_BACKENDS"] = ["djangosaml2.backends.Saml2Backend"]
614+
if "LOGIN_URL" not in settings:
615+
data["LOGIN_URL"] = "/saml2/login/"
616+
if "SESSION_COOKIE_SECURE" not in settings:
617+
data["SESSION_COOKIE_SECURE"] = True
618+
if "SESSION_EXPIRE_AT_BROWSER_CLOSE" not in settings:
619+
data["SESSION_EXPIRE_AT_BROWSER_CLOSE"] = True
620+
return data
621+
622+
609623
del preload_settings
610624

625+
611626
class PulpSettings(Settings):
612627
def _ready(self):
613628
self._store = self._store.to_dict()
@@ -637,7 +652,7 @@ def _ready(self):
637652
otel_metrics_dispatch_interval_validator,
638653
distributed_publication_retention_period_validator,
639654
],
640-
post_hooks=(otel_middleware_hook,),
655+
post_hooks=(otel_middleware_hook, saml2_settings_hook),
641656
)
642657

643658
_logger = getLogger(__name__)

pulpcore/app/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ class NoSchema(p.callback.cls):
243243
path("", include("social_django.urls", namespace=settings.SOCIAL_AUTH_URL_NAMESPACE))
244244
)
245245

246+
if "djangosaml2" in settings.INSTALLED_APPS:
247+
urlpatterns.append(path("saml2/", include("djangosaml2.urls")))
248+
246249
#: The Pulp Platform v3 API router, which can be used to manually register ViewSets with the API.
247250
root_router = PulpDefaultRouter()
248251

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ s3 = ["django-storages[boto3]==1.14.6"]
7272
google = ["django-storages[google]==1.14.6"]
7373
azure = ["django-storages[azure]==1.14.6"]
7474
prometheus = ["django-prometheus"]
75+
saml2 = ["djangosaml2>=1.12.0,<1.13"]
7576
kafka = [
7677
# Pinned because project warns "things might (and will) break with every update"
7778
"cloudevents==1.11.0",

0 commit comments

Comments
 (0)