-
Notifications
You must be signed in to change notification settings - Fork 104
Add feature to find users in the directory by email #150
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
base: master
Are you sure you want to change the base?
Conversation
Having the connection-handling logic in a separate class allows more extensibility.
7555cb3
to
e26d0ef
Compare
To explain the use case a bit more, for Zulip servers that are using LDAP authentication for most accounts but also managing some accounts using Zulip's built-in email/password authentication, we would really like to enforce the rule that "if an email address has an LDAP account, it can't login using email/password". For that, we need a way to do in LDAP email -> (account data) lookups, not just the username -> (account data) lookups that are typically done for LDAP authentication. We're happy to put active work into improving this PR and/or helping maintain this feature should upstream be interested in merging this. . (And thanks for a great library!) |
Just wanted to do a quick ping on this; I'd particularly love feedback on "if django-auth-ldap were to add this feature, is this what you'd call the setting?", since it'll be somewhat annoying for our users if we ship a version of this from a temporary fork with a slightly different version of the setting name. |
This would definitely be a useful feature for any of our apps that have dual authentication. It'd also be the basis of a feature I'm hoping to work on to be able to prepopulate a user from the AD (in advance of their first login). I guess nothing ever happened with this PR? |
I would love to see it integrated and we'd be happy to help do so; I think the project's maintainer has been busy as it hasn't been reviewed, even for "is this the right interface". |
Hi, thanks for the suggestion and working on it. Can you explain why this feature should live in django-auth-ldap? This feature suggests offering the capability to query the LDAP for the application benefit. Why not use python-ldap or ldap3 to query to the LDAP directly?
I’m not sure that rule would be shared by all users. Perhaps others would prefer their application first look up in the database, and then default to LDAP authentication, e.g. if only superusers are created in the database, the “regular” users living in the LDAP. |
@francoisfreitag thanks for the thoughtful reply! The first commit, which refactors the
Agreed -- which is why the change here doesn't implement that sort of policy logic in the library; that belongs in the application. Instead, I think of this as an optional hook for applications that want it, along the lines of https://django-auth-ldap.readthedocs.io/en/latest/permissions.html. |
I like the idea of extracting the connection for reuse. It is much clearer than tying it to the I am not convinced by the chosen approach of extracting a mixin to factor out the logic to establish a connection. IMO, the connections should be an object on their own. A separate connection might also help solving #174. Regarding the second part, casting LDAP results to users, I wonder about the use cases? |
Opened #249 to address the |
I agree that the |
Thinking about the original use case, the feature can probably be implemented by a
That avoids establishing a separate LDAP connection and needing to rebind, and that remains related to the authentication of a user. What do you think?
I’m unclear on the use case for this feature? In all cases, improvements can certainly be made towards facilitating the creation of an |
Just for some extra context, in my use case's this would be handy so we could create a workflow to "pre-create" valid users and assign them permissions on the Django side in advance of their first login. We aren't able to get more groups created in LDAP and having users login once, then doing permissions and re-logging in isn't ideal. |
So you would basically crawl the LDAP based on some search pattern, and create the corresponding Django users? |
#response_container_BBPPID{font-family: initial; font-size:initial; color: initial;} Yup - That's the idea.LDAP handles the authentication and Django the authorization. Since the account won't have a valid password set, and access is only granted if it's In the correct group/OU there are no security concerns. Being able to populate the user with whatever permissions/groups are required in advance is the goal. From: ***@***.***Sent: May 25, 2021 1:14 AMTo: ***@***.***Reply to: ***@***.***Cc: ***@***.***; ***@***.***Subject: Re: [django-auth-ldap/django-auth-ldap] Add feature to find users in the directory by email (#150)
So you would basically crawl the LDAP based on some search pattern, and create the corresponding Django users?
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.
|
To crawl the LDAP, the authentication backend and authentication machinery is not needed. To instantiate a user, the code on this PR makes a new search per user being constructed. Since the username comes from the LDAP, these searches are unnecessary and should be avoided. |
Till now, we've been forking django-auth-ldap at https://github.com/zulip/django-auth-ldap to put the LDAPReverseEmailSearch feature in it, hoping to get it merged upstream in django-auth-ldap/django-auth-ldap#150 The efforts to get it merged have stalled for now however and we don't want to be on the fork forever, so this commit puts the email search feature as a clumsy workaround inside our codebase and switches to using the latest upstream release instead of the fork.
Till now, we've been forking django-auth-ldap at https://github.com/zulip/django-auth-ldap to put the LDAPReverseEmailSearch feature in it, hoping to get it merged upstream in django-auth-ldap/django-auth-ldap#150 The efforts to get it merged have stalled for now however and we don't want to be on the fork forever, so this commit puts the email search feature as a clumsy workaround inside our codebase and switches to using the latest upstream release instead of the fork.
Till now, we've been forking django-auth-ldap at https://github.com/zulip/django-auth-ldap to put the LDAPReverseEmailSearch feature in it, hoping to get it merged upstream in django-auth-ldap/django-auth-ldap#150 The efforts to get it merged have stalled for now however and we don't want to be on the fork forever, so this commit puts the email search feature as a clumsy workaround inside our codebase and switches to using the latest upstream release instead of the fork.
Till now, we've been forking django-auth-ldap at https://github.com/zulip/django-auth-ldap to put the LDAPReverseEmailSearch feature in it, hoping to get it merged upstream in django-auth-ldap/django-auth-ldap#150 The efforts to get it merged have stalled for now however and we don't want to be on the fork forever, so this commit puts the email search feature as a clumsy workaround inside our codebase and switches to using the latest upstream release instead of the fork.
Example use:
more extensive examples in tests.
If I can get some feedback whether this is mergeable in this form, or if I should make some changes, I'll add documentation too.
We need this in https://github.com/zulip/zulip to, during authentication, be able to check if an email belongs to ldap. This feature should be useful to users in general though, so I'm submitting as a PR.