Skip to content

Commit

Permalink
Revert "Feature: Support for multiple AUTH_LDAP_REQUIRE_GROUP from en…
Browse files Browse the repository at this point in the history
…vironment variables"
  • Loading branch information
tobiasge committed Sep 4, 2024
1 parent 52f38a3 commit 942f978
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
3 changes: 2 additions & 1 deletion configuration/ldap/extra.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
####
## This file contains extra configuration options that can't be configured
## directly through environment variables.
## All variables set here overwrite any existing found in ldap_config.py
## All vairables set here overwrite any existing found in ldap_config.py
####

# # This Python script inherits all the imports from ldap_config.py
# from django_auth_ldap.config import LDAPGroupQuery # Imported since not in ldap_config.py

# # Sets a base requirement of membetship to netbox-user-ro, netbox-user-rw, or netbox-user-admin.
# AUTH_LDAP_REQUIRE_GROUP = (
Expand Down
14 changes: 2 additions & 12 deletions configuration/ldap/ldap_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os import environ

import ldap
from django_auth_ldap.config import LDAPGroupQuery, LDAPSearch
from django_auth_ldap.config import LDAPSearch


# Read secret from file
Expand Down Expand Up @@ -86,22 +86,12 @@ def _import_group_type(group_type_name):
# Define a group required to login.
AUTH_LDAP_REQUIRE_GROUP = environ.get('AUTH_LDAP_REQUIRE_GROUP_DN')

# If non-empty string, AUTH_LDAP_REQUIRE_GROUP will be treated as a list delimited by this separator
AUTH_LDAP_REQUIRE_GROUP_SEPARATOR = environ.get('AUTH_LDAP_REQUIRE_GROUP_DN_SEPARATOR', '')

# Define special user types using groups. Exercise great caution when assigning superuser status.
AUTH_LDAP_USER_FLAGS_BY_GROUP = {}

if AUTH_LDAP_REQUIRE_GROUP is not None:
# Build an LDAPGroupQuery when AUTH_LDAP_REQUIRE_GROUP should be treated as a list
if AUTH_LDAP_REQUIRE_GROUP_SEPARATOR:
_groups = list(filter(None, AUTH_LDAP_REQUIRE_GROUP.split(AUTH_LDAP_REQUIRE_GROUP_SEPARATOR)))
AUTH_LDAP_REQUIRE_GROUP = LDAPGroupQuery(_groups[0])
for i in range(1, len(_groups)):
AUTH_LDAP_REQUIRE_GROUP |= LDAPGroupQuery(_groups[i])

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": AUTH_LDAP_REQUIRE_GROUP,
"is_active": environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', ''),
"is_staff": environ.get('AUTH_LDAP_IS_ADMIN_DN', ''),
"is_superuser": environ.get('AUTH_LDAP_IS_SUPERUSER_DN', '')
}
Expand Down

0 comments on commit 942f978

Please sign in to comment.