-
-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Populating LDAP config via os.environ.get is incompatible with LDAPGroupQuery #290
Comments
Thank you for raising this issue. It would help to know exactly which version of Netbox you're on in general. LDAP is a feature I don't use and neither do I have a test environment for it. But if someone can suggest a PR, I will be happy to review whether it is semantically correct, but I will have no way to check whether it would be correct. If you haven't done so, try asking in the Slack #netbox-docker channel whether someone has already solved this problem. |
Hi, I will also continue to search for a better solution or refine ours for a PR. |
I think defining a complex filter through an environment variable is not a good option as we'd have to develop a complex parser (with stacking) and then call the functions and operators through getattr and operator.X. - It's just an error-prone and a time-consuming way. As for k8s, the script can be mounted through a cm or a secret. |
Another issue we discovered is that setting it to |
This is how we fixed it for us: # Define special user types using groups, only set if variable exists.
AUTH_LDAP_USER_FLAGS_BY_GROUP = {}
# A group needed to log in at all
if os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN') is not None:
AUTH_LDAP_REQUIRE_GROUP = os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN')
AUTH_LDAP_USER_FLAGS_BY_GROUP["is_active"] = os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN')
# Admin group DN
if os.environ.get('AUTH_LDAP_IS_ADMIN_DN') is not None:
AUTH_LDAP_USER_FLAGS_BY_GROUP["is_staff"] = os.environ.get('AUTH_LDAP_IS_ADMIN_DN')
# SuperUser group DN
if os.environ.get('AUTH_LDAP_IS_SUPERUSER_DN') is not None:
AUTH_LDAP_USER_FLAGS_BY_GROUP["is_superuser"] = os.environ.get('AUTH_LDAP_IS_SUPERUSER_DN') |
I did something different, but quite hacky which allows us to put multiple groups (although they all have to be defined) index 19277e1..f8127c8 100644
--- a/configuration/ldap_config.py
+++ b/configuration/ldap_config.py
@@ -60,13 +60,13 @@ AUTH_LDAP_GROUP_SEARCH = LDAPSearch(AUTH_LDAP_GROUP_SEARCH_BASEDN, ldap.SCOPE_SU
AUTH_LDAP_GROUP_TYPE = import_group_type(os.environ.get('AUTH_LDAP_GROUP_TYPE', 'GroupOfNamesType'))
# Define a group required to login.
-AUTH_LDAP_REQUIRE_GROUP = os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', '')
+# AUTH_LDAP_REQUIRE_GROUP = os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN','')
# Define special user types using groups. Exercise great caution when assigning superuser status.
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
- "is_active": os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', ''),
- "is_staff": os.environ.get('AUTH_LDAP_IS_ADMIN_DN', ''),
- "is_superuser": os.environ.get('AUTH_LDAP_IS_SUPERUSER_DN', '')
+ "is_active": os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', '').split('|'),
+ "is_staff": os.environ.get('AUTH_LDAP_IS_ADMIN_DN', '').split('|'),
+ "is_superuser": os.environ.get('AUTH_LDAP_IS_SUPERUSER_DN', '').split('|')
}``` |
This will be solved by #343 . |
Netbox Docker 0.26.0 was just released which addresses this issue. |
Hello, |
Current Behavior
Trying to allow more than one group for AUTH_LDAP_REQUIRE_GROUP. Following the example described in https://django-auth-ldap.readthedocs.io/en/latest/groups.html#limiting-access
Whentrying to authenticate I get an error
Caught LDAPError while authenticating xxxxxxxxxx: INVALID_DN_SYNTAX({'desc': 'Invalid DN syntax', 'info': 'Invalid DN'})
Expected Behavior
Authentication should check against both (or more) groups
Debug Information
The problem results from the way the config file reads the variables:
There the environment variable is read and assigned to AUTH_LDAP_REQUIRE_GROUP. Unfortunately in this case the variable contains a python function that would convert the string in the environment-variable to the type
django_auth_ldap.config.LDAPGroupQuery
. But the function is not executed.Current result
Expected Behavior
The text was updated successfully, but these errors were encountered: