Skip to content

Commit 28acd5c

Browse files
Bump Netbox version and use CSH SSO (#4)
* Add netbox-topology-view plugin * Fix Containerfile * Set specific version of netbox-topology-views * Update static Containerfile * Add separate static containerfile * bump netbox to 3.7.4 * bump netbox to 3.7.4 but actually this time * bump netbox-topology-views to 3.9b1 for upgrade to netbox 3.7.4 * oidc * revert netbox-topology-views to 3.9.0 (no beta) * better group mirroring * remove LDAP stuff * change login banner * remove hardcoded login/logout redirects * cursed auto-redirect to sso * update readme * remove templates --------- Co-authored-by: joe <[email protected]>
1 parent 7336372 commit 28acd5c

8 files changed

+57
-147
lines changed

.gitmodules

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[submodule "netbox"]
22
path = netbox
33
url = ../../netbox-community/netbox.git
4+
branch = v3.7.4

Containerfile

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,23 @@ RUN apt-get update && \
99
libffi-dev \
1010
libpq-dev \
1111
libssl-dev \
12-
zlib1g-dev \
13-
libldap2-dev \
14-
libsasl2-dev \
15-
libssl-dev
12+
zlib1g-dev
1613

1714
COPY netbox/requirements.txt /opt/netbox/requirements.txt
1815
COPY local_requirements.txt /opt/netbox/local_requirements.txt
19-
RUN pip install django-storages django-auth-ldap srvlookup
16+
RUN pip install django-storages
2017
RUN pip install -r /opt/netbox/requirements.txt
2118
RUN pip install -r /opt/netbox/local_requirements.txt
2219

2320
COPY netbox /opt/netbox
21+
COPY oidc_groups.py /opt/netbox/netbox/oidc_groups.py
2422

2523
COPY validators.py /opt/netbox/netbox/netbox/validators.py
2624
COPY configuration.env.py /opt/netbox/netbox/netbox/configuration.py
27-
COPY ldap_config.env.py /opt/netbox/netbox/netbox/ldap_config.py
2825
COPY gunicorn.py /opt/netbox/gunicorn.py
2926
COPY migrate.sh /opt/netbox/migrate.sh
3027

28+
3129
WORKDIR /opt/netbox
3230

3331
RUN NETBOX_SECRET_KEY="6l0~ZBT9yFIQoZxak9H=N_f6~@Yhbu~YS4s6r8-R2%GwXZVV)0" mkdocs build && \

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CSH Netbox
2-
OKD Containers for CSH's Netbox instance, now with LDAP!
2+
OKD Containers for CSH's Netbox instance, now with CSH SSO!
33

44
## Upgrading
55

configuration.env.py

+29-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
BANNER_BOTTOM = ''
9898

9999
# Text to include on the login page above the login form. HTML is allowed.
100-
BANNER_LOGIN = 'Please log in with your CSH username and password'
100+
BANNER_LOGIN = '<script>window.location.replace("/oauth/login/oidc/" + window.location.search);</script>'
101101

102102
# Base URL path if accessing NetBox within a directory. For example, if installed at https://example.com/netbox/, set:
103103
# BASE_PATH = 'netbox/'
@@ -183,7 +183,7 @@
183183
"version": 1,
184184
"disable_existing_loggers": False,
185185
"handlers": {"console": {"class": "logging.StreamHandler"}},
186-
"loggers": {"django_auth_ldap": {"level": "DEBUG", "handlers": ["console"]}},
186+
"loggers": {"social_core": {"level": "DEBUG", "handlers": ["console"]}},
187187
} if DEBUG else {}
188188

189189
# Automatically reset the lifetime of a valid session upon each authenticated request. Enables users to remain
@@ -275,11 +275,37 @@
275275

276276
# Remote authentication support
277277
REMOTE_AUTH_ENABLED = True
278-
REMOTE_AUTH_BACKEND = 'netbox.authentication.LDAPBackend'
278+
REMOTE_AUTH_BACKEND = 'social_core.backends.open_id_connect.OpenIdConnectAuth'
279279
REMOTE_AUTH_HEADER = 'HTTP_REMOTE_USER'
280280
REMOTE_AUTH_AUTO_CREATE_USER = True
281281
REMOTE_AUTH_DEFAULT_GROUPS = []
282282
REMOTE_AUTH_DEFAULT_PERMISSIONS = {}
283+
SOCIAL_AUTH_OIDC_ENDPOINT = 'https://sso.csh.rit.edu/auth/realms/csh'
284+
SOCIAL_AUTH_KEY = os.environ.get("OIDC_CLIENT_ID")
285+
SOCIAL_AUTH_SECRET = os.environ.get("OIDC_CLIENT_SECRET")
286+
SOCIAL_AUTH_NO_DEFAULT_PROTECTED_USER_FIELDS = True
287+
SOCIAL_AUTH_PROTECTED_USER_FIELDS = (
288+
"id",
289+
"pk",
290+
"email",
291+
"password",
292+
"is_active",
293+
"is_staff",
294+
"is_superuser",
295+
)
296+
297+
SOCIAL_AUTH_PIPELINE = (
298+
'social_core.pipeline.social_auth.social_details',
299+
'social_core.pipeline.social_auth.social_uid',
300+
'social_core.pipeline.social_auth.social_user',
301+
'social_core.pipeline.user.get_username',
302+
'social_core.pipeline.user.create_user',
303+
'social_core.pipeline.social_auth.associate_user',
304+
'netbox.authentication.user_default_groups_handler',
305+
'social_core.pipeline.social_auth.load_extra_data',
306+
'oidc_groups.oidc_groups_handler',
307+
'social_core.pipeline.user.user_details',
308+
)
283309

284310
# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the
285311
# version check or use the URL below to check for release in the official NetBox repository.

ldap_config.env.py

-135
This file was deleted.

local_requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
netbox-topology-views==3.8.1
1+
netbox-topology-views==3.9.0
2+
social-auth-app-django==5.4.0
23
netbox-plugin-dns==0.22.1

netbox

Submodule netbox updated 524 files

oidc_groups.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.contrib.auth.models import Group
2+
3+
4+
def oidc_groups_handler(strategy, response, user, *args, **kwargs):
5+
# mirror groups
6+
groups = [
7+
Group.objects.get_or_create(name=group)[0] for group in response["groups"]
8+
]
9+
user.groups.set(groups)
10+
11+
# give active rtps superuser and staff
12+
is_active_rtp = "active_rtp" in response["groups"]
13+
user.is_superuser = is_active_rtp
14+
user.is_staff = is_active_rtp
15+
16+
user.is_active = "member" in response["groups"]
17+
18+
# save
19+
strategy.storage.user.changed(user)

0 commit comments

Comments
 (0)