Skip to content
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

Recommended Active Directory config is not correct: invalidCredentials #199

Open
MakarovDi opened this issue Jul 25, 2021 · 4 comments
Open

Comments

@MakarovDi
Copy link

The recommended configuration for Active Directory integration:

c.LDAPAuthenticator.lookup_dn = True
c.LDAPAuthenticator.lookup_dn_search_filter = '({login_attr}={login})'
c.LDAPAuthenticator.lookup_dn_search_user = 'ldap_search_user_technical_account'
c.LDAPAuthenticator.lookup_dn_search_password = 'secret'
c.LDAPAuthenticator.user_search_base = 'ou=people,dc=wikimedia,dc=org'
c.LDAPAuthenticator.user_attribute = 'sAMAccountName'
c.LDAPAuthenticator.lookup_dn_user_dn_attribute = 'cn'
c.LDAPAuthenticator.escape_userdn = False
c.LDAPAuthenticator.bind_dn_template = '{username}'

This config will result in

LDAPBindError: automatic bind not successful - invalidCredentials

The problem is the last row of the config:

c.LDAPAuthenticator.bind_dn_template = '{username}'

Because of this row the resolved dn will never be used (link to the code):

...
        if self.lookup_dn:
            username, resolved_dn = self.resolve_username(username)
            if not username:
                return None
            if str(self.lookup_dn_user_dn_attribute).upper() == "CN":
                # Only escape commas if the lookup attribute is CN
                username = re.subn(r"([^\\]),", r"\1\,", username)[0]
            if not bind_dn_template:                     # <------- bind_dn_template =  '{username}'
                bind_dn_template = [resolved_dn]         # <------- resolved_dn will never be used!

        is_bound = False
        for dn in bind_dn_template:
            if not dn:
...

So the working configuration is:

c.LDAPAuthenticator.lookup_dn = True
c.LDAPAuthenticator.lookup_dn_search_filter = '({login_attr}={login})'
c.LDAPAuthenticator.lookup_dn_search_user = 'ldap_search_user_technical_account'
c.LDAPAuthenticator.lookup_dn_search_password = 'secret'
c.LDAPAuthenticator.user_search_base = 'ou=people,dc=wikimedia,dc=org'
c.LDAPAuthenticator.user_attribute = 'sAMAccountName'
c.LDAPAuthenticator.lookup_dn_user_dn_attribute = 'cn'
c.LDAPAuthenticator.escape_userdn = False

Related issues

Issues #101, #144, #125 are probably related.

@welcome
Copy link

welcome bot commented Jul 25, 2021

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@cprivitere
Copy link

Can confirm, following the above advice fixed our issues with being told the users were not in any of the allowed groups no matter what groups we put in there. So the config as presented on the readme seems to enable auth to work, but not group lookups. The config suggested above enables both.

@mluds
Copy link

mluds commented Dec 2, 2021

Removing c.LDAPAuthenticator.bind_dn_template = '{username}' also fixed AD authentication for me.

@felipempda
Copy link

It worked for me as well. Also use_lookup_dn_username = false was important to make Unix usernames consistent with login (instead of LDAP's CN) as pointed out on documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants