I am attempting to authenticate a Django application against an LDAP server and am receiving some strange behavior. Please keep in mind I don't know much about LDAP so if I misuse some LDAP terminology, excuse me. Also note that throughout this question my_domain is the domain name of my company and user_id is the uid of the authenticating user.
Here is the pertinent part of my settings.py configuration file:
AUTHENTICATION_BACKENDS = [
'django_auth_ldap.backend.LDAPBackend'
]
AUTH_LDAP_SERVER_URI = 'ldaps://ipa.my_domain.com:636'
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,cn=users,cn=accounts,dc=my_domain,dc=com"
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "cn=all,cn=groups,cn=accounts,dc=my_domain,dc=com",
"is_staff": "cn=all,cn=groups,cn=accounts,dc=my_domain,dc=com",
"is_superuser": "cn=all,cn=groups,cn=accounts,dc=my_domain,dc=com"
}
AUTH_LDAP_ALWAYS_UPDATE_USER = True
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("cn=groups,cn=accounts,dc=my_domain,dc=com",
ldap.SCOPE_SUBTREE, "(objectClass=member)"
)
AUTH_LDAP_GLOBAL_OPTIONS = {
ldap.OPT_X_TLS_REQUIRE_CERT: False,
ldap.OPT_REFERRALS: False,
}
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn"}
When I attempt to log in to my application, I receive this error:
Populating Django user user_id search_s('uid=user_id,cn=users,cn=accounts,dc=my_domain,dc=com', 0, '(objectClass=*)') returned 1 objects: uid=user_id,cn=users,cn=accounts,dc=my_domain,dc=com Caught LDAPError while authenticating user_id: INSUFFICIENT_ACCESS({'desc': 'Insufficient access'},)
However, when I flip this flag from True to false:
AUTH_LDAP_ALWAYS_UPDATE_USER = False
Authentication succeeds. Now here is the strange part: even though authentication succeeds, my attributes are not mapped to my Django User object (the ones specified in AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn"}
). When I manually inspect request.user.ldap_user.attrs
all the attributes are there.
Now here comes the question, what exactly does 'Populating Django user' mean? What is causing an 'INSUFFICIENT_ACCESS' error and why does flipping that one flag fix (hide?) the problem?
Thanks.