From 17eb2a9a2dd84730bd816248485ebfa44d771078 Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Mon, 20 Mar 2023 10:32:15 -0500 Subject: [PATCH 1/3] Add suppport for REMOTE_AUTH_BACKEND as iterable --- netbox/netbox/settings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 45fe3284104..39baaa2ad16 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -396,10 +396,11 @@ def _setting(name, default=None): ] # Set up authentication backends -AUTHENTICATION_BACKENDS = [ - REMOTE_AUTH_BACKEND, - 'netbox.authentication.ObjectPermissionBackend', -] +if isinstance(REMOTE_AUTH_BACKEND, list) or isinstance(REMOTE_AUTH_BACKEND, tuple): + AUTHENTICATION_BACKENDS = [x for x in REMOTE_AUTH_BACKEND] +else: + AUTHENTICATION_BACKENDS = [REMOTE_AUTH_BACKEND] +AUTHENTICATION_BACKENDS.append('netbox.authentication.ObjectPermissionBackend') # Time zones USE_TZ = True From a20d486fd81b7112f943378b7c7857bfd984dea1 Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Mon, 20 Mar 2023 10:49:01 -0500 Subject: [PATCH 2/3] Closes #11977: Support for multiple auth backends --- docs/configuration/remote-authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/remote-authentication.md b/docs/configuration/remote-authentication.md index 07adf5c6a24..1fda8d0d35d 100644 --- a/docs/configuration/remote-authentication.md +++ b/docs/configuration/remote-authentication.md @@ -16,7 +16,7 @@ If true, NetBox will automatically create local accounts for users authenticated Default: `'netbox.authentication.RemoteUserBackend'` -This is the Python path to the custom [Django authentication backend](https://docs.djangoproject.com/en/stable/topics/auth/customizing/) to use for external user authentication. NetBox provides two built-in backends (listed below), though custom authentication backends may also be provided by other packages or plugins. +This is the Python path to the custom [Django authentication backend](https://docs.djangoproject.com/en/stable/topics/auth/customizing/) to use for external user authentication. NetBox provides two built-in backends (listed below), though custom authentication backends may also be provided by other packages or plugins. Provide a string for a single backend, or an iterable for multiple backends, which will be attempted in the order given. * `netbox.authentication.RemoteUserBackend` * `netbox.authentication.LDAPBackend` From 7de8290402603b110fec734e22f47d76ebbee592 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 28 Mar 2023 08:13:22 -0400 Subject: [PATCH 3/3] Tweak list casting --- netbox/netbox/settings.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 39baaa2ad16..cf2b06a8b25 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -396,11 +396,12 @@ def _setting(name, default=None): ] # Set up authentication backends -if isinstance(REMOTE_AUTH_BACKEND, list) or isinstance(REMOTE_AUTH_BACKEND, tuple): - AUTHENTICATION_BACKENDS = [x for x in REMOTE_AUTH_BACKEND] -else: - AUTHENTICATION_BACKENDS = [REMOTE_AUTH_BACKEND] -AUTHENTICATION_BACKENDS.append('netbox.authentication.ObjectPermissionBackend') +if type(REMOTE_AUTH_BACKEND) not in (list, tuple): + REMOTE_AUTH_BACKEND = [REMOTE_AUTH_BACKEND] +AUTHENTICATION_BACKENDS = [ + *REMOTE_AUTH_BACKEND, + 'netbox.authentication.ObjectPermissionBackend', +] # Time zones USE_TZ = True