import ldap
# Server URI
AUTH_LDAP_SERVER_URI = "ldaps://synology.kensnet.priv"
# Set the DN and password for the NetBox service account.
AUTH_LDAP_BIND_DN = "CN=netbox,CN=users,DC=kensnet,DC=priv"
AUTH_LDAP_BIND_PASSWORD = bindpassword
LDAP_IGNORE_CERT_ERRORS = True
from django_auth_ldap.config import LDAPSearch, PosixGroupType, GroupOfNamesType
AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=users,dc=kensnet,dc=priv",
ldap.SCOPE_SUBTREE,
"(sAMAccountName=%(user)s)")
# If a user's DN is producible from their username, we don't need to search.
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,cn=users,dc=kensnet,dc=priv"
### EVERYTHING WORKS UP UNTIL HERE
#### Groups
# # This search ought to return all groups to which the user belongs. django_auth_ldap uses this to determine group
# # heirarchy.
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=kensnet,dc=priv", ldap.SCOPE_SUBTREE,
"(objectClass=organizationalRole")
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
# # Define a group required to login.
AUTH_LDAP_REQUIRE_GROUP = "cn=users,cn=groups,dc=kensnet,dc=priv"
# Define special user types using groups. Exercise great caution when assigning superuser status.
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_staff": "cn=staff,cn=groups,dc=kensnet,dc=priv",
"is_superuser": "cn=administrators,cn=groups,dc=kensnet,dc=priv"
}
I've got LDAPSearch configured to work with my Synology Directory Server. Users can authenticate fine but when I try to map a user to a group I get INVALID_CREDENTIALS:
import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
1) I'm using a service account. I verified the DN's by connecting using Apache Directory Studio.
2) I just promoted the service account user but I'm still facing the same error.3) Logging is not helping: it's only reiterating what the original error is telling me: Caught LDAPError while authenticating ken: INVALID_CREDENTIALS({'desc': 'Invalid credentials'},) I added logging by adding this to the config:
AUTH_LDAP_BIND_DN = "UID=netbox,CN=users,DC=kenset,DC=priv"
from django_auth_ldap.config import LDAPSearch, PosixGroupType
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=kensnet,dc=priv", ldap.SCOPE_SUBTREE, (objectClass=posixGroup)")AUTH_LDAP_GROUP_TYPE = PosixGroupType()
AUTH_LDAP_USER_ATTR_MAP = { "first_name": "cn", "last_name": "sn"}
AUTH_LDAP_USER_FLAGS_BY_GROUP = { "is_staff": f"cn={AUTH_LDAP_USER_STAFF},cn=groups,dc={dc1},dc={dc2}", "is_superuser": f"cn={AUTH_LDAP_USER_SUPERUSER},cn=groups,dc={dc1},dc={dc2}"}
I fixed the DN for the service account:
AUTH_LDAP_BIND_DN = "UID=netbox,CN=users,DC=kenset,DC=priv"I've tried at least a 100 different things so far and nothing is getting me there.
from django_auth_ldap.config import LDAPSearch, PosixGroupTypeAUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=kensnet,dc=priv", ldap.SCOPE_SUBTREE, (objectClass=posixGroup)")
Good catch! I just fixed it and re-tried and it works now. I had to get past the group search but ultimately my mispellings caught me up. Thanks for all the help James!