Skip to content

Commit

Permalink
Backward compatibility for LDAP require group (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColomb authored Oct 21, 2024
1 parent 7050dd1 commit a13b904
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion charts/netbox/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: netbox
version: 5.0.0-beta.131
version: 5.0.0-beta.132
appVersion: "v4.1.4"
type: application
kubeVersion: ^1.25.0-0
Expand Down
22 changes: 10 additions & 12 deletions charts/netbox/files/ldap_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This file serves as a LDAP configuration for Netbox
https://netboxlabs.com/docs/netbox/en/stable/configuration/
https://netboxlabs.com/docs/netbox/en/stable/installation/6-ldap/#configuration
https://django-auth-ldap.readthedocs.io/en/latest/reference.html
"""

from functools import reduce
Expand Down Expand Up @@ -56,7 +57,7 @@ def _import_group_type(group_type_name: str) -> Any | None:
AUTH_LDAP_USER_SEARCH = LDAPSearch(
AUTH_LDAP_USER_SEARCH_BASEDN,
ldap.SCOPE_SUBTREE,
"(" + AUTH_LDAP_USER_SEARCH_ATTR + "=%(user)s)",
f"({AUTH_LDAP_USER_SEARCH_ATTR}=%(user)s)",
)
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
AUTH_LDAP_GROUP_SEARCH_BASEDN,
Expand All @@ -66,19 +67,16 @@ def _import_group_type(group_type_name: str) -> Any | None:
AUTH_LDAP_GROUP_TYPE = _import_group_type(AUTH_LDAP_GROUP_TYPE)

# Define a group required to login.
AUTH_LDAP_REQUIRE_GROUP = reduce(
lambda query, group: query | LDAPGroupQuery(group),
AUTH_LDAP_REQUIRE_GROUP_LIST,
LDAPGroupQuery(""),
)

# Define special user types using groups. Exercise great caution when assigning superuser status.
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": reduce(
if AUTH_LDAP_REQUIRE_GROUP_LIST:
AUTH_LDAP_REQUIRE_GROUP = reduce(
lambda query, group: query | LDAPGroupQuery(group),
AUTH_LDAP_REQUIRE_GROUP_LIST,
LDAPGroupQuery(""),
),
)

# Define special user types using groups. Exercise great caution when assigning superuser status.
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": AUTH_LDAP_REQUIRE_GROUP,
"is_staff": reduce(
lambda query, group: query | LDAPGroupQuery(group),
AUTH_LDAP_IS_ADMIN_LIST,
Expand Down
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line_length = 100
target-version = ['py38']
target-version = ["py38"]
include = '\.pyi?$'
exclude = '''
(
Expand All @@ -20,7 +20,13 @@ multi_line_output = 3
line_length = 100

[tool.pylint.main]
disable = ["duplicate-code", "import-error", "used-before-assignment", "undefined-variable"]
disable = [
"duplicate-code",
"import-error",
"possibly-used-before-assignment",
"used-before-assignment",
"undefined-variable",
]

[tool.pylint.format]
max-line-length = "100"
Expand Down

0 comments on commit a13b904

Please sign in to comment.