I'm trying to set up LDAP authentication for Django admin, but keep getting errors LDAPError(2, 'No such file or directory'), and LDAPError(34, 'Numerical result out of range').
I have a working LDAP authentication setup for an Apache server app (anonymized):
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthLDAPURL ldap://
ldap.my-domain.eu:999/OU=Internal,OU=Users,DC=my-domain,DC=eu?sAMAccountName?sub AuthLDAPBindDN "CN=MyApp,OU=System,OU=Users,DC=my-domain,DC=eu"
AuthLDAPBindPassword XXXXXXXX
I tried to copy these settings to a Django app like this:
AUTH_LDAP_SERVER_URI = "ldap://
ldap.my-domain.eu:999/OU=Internal,OU=Users,DC=my-domain,DC=eu?sAMAccountName?sub"
AUTH_LDAP_BIND_DN = "CN=MyApp,OU=System,OU=Users,DC=my-domain,DC=eu"
AUTH_LDAP_BIND_PASSWORD = "XXXXXXXX"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=Users,dc=my-domain,dc=eu",
ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "OU=Users,DC=my-domain,DC=eu",
"is_staff": "OU=Users,DC=my-domain,DC=eu",
}
AUTH_LDAP_CONNECTION_OPTIONS = {
ldap.OPT_REFERRALS: 0,
}
But the Django login doesn't work. Admin tells me I have a wrong username/password, Apache error log for the Django site shows:
[Mon Nov 03 16:46:31 2014] [error] Caught LDAPError while authenticating jiri.vyskocil: LDAPError(2, 'No such file or directory')
[Mon Nov 03 16:46:36 2014] [error] Caught LDAPError while authenticating jiri.vyskocil: LDAPError(34, 'Numerical result out of range')
[Mon Nov 03 16:46:53 2014] [error] Caught LDAPError while authenticating jiri.vyskocil: LDAPError(34, 'Numerical result out of range')
First time I try to login after restarting the Django app (running through mod_wsgi - I do a touch wsgi.py to "restart", but restarting apache has the same effect), I get LDAPError(2, 'No such file or directory'), subsequent login attempts give me a LDAPError(34, 'Numerical result out of range').
Any ideas on what am I doing wrong? I don't have admin access to the LDAP server, so I have to debug locally from the web server.
Thank you,
Jiri