Netbox-LDAP Authentication fails #1513

Closed
opened 2025-12-29 16:32:35 +01:00 by adam · 1 comment
Owner

Originally created by @Netbioox on GitHub (Jan 26, 2018).

Hello,

Just installed Netbox and I would like to implement LDAP authentication.
Here's my ldap_config.py file:

import ldap

Server URI

AUTH_LDAP_SERVER_URI = "ldap://xxx.xxx.xx"

The following may be needed if you are binding to Active Directory.

AUTH_LDAP_CONNECTION_OPTIONS = {
ldap.OPT_REFERRALS: 0
}

Set the DN and password for the NetBox service account.

AUTH_LDAP_BIND_DN = "CN=xxxxx,OU=SERVICES,DC=xx,DC=xx"
AUTH_LDAP_BIND_PASSWORD = "MYxxxxxPASS"

Include this setting if you want to ignore certificate errors. This might be needed to accept a self-signed cert.

Note that this is a NetBox-specific setting which sets:

ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)

LDAP_IGNORE_CERT_ERRORS = True

from django_auth_ldap.config import LDAPSearch

AUTH_LDAP_USER_SEARCH = LDAPSearch("OU=USERS,DC=xxx,DC=xx",ldap.SCOPE_SUBTREE,
"(uid=%(user)s)") # "(sAMAccountName=%(user)s)") > also try this

You can map user attributes to Django attributes as so.

AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}

from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, NestedGroupOfNamesType

AUTH_LDAP_GROUP_SEARCH = LDAPSearch("OU=GROUPS,DC=xxx,DC=xx", ldap.SCOPE_SUBTREE,
"(objectClass=groupOfNames)") # "(objectClass=group)") > also try this

AUTH_LDAP_GROUP_TYPE = GroupOfNamesType() ### I changed this

AUTH_LDAP_GROUP_TYPE = NestedGroupOfNamesType()

Define a group required to login

AUTH_LDAP_REQUIRE_GROUP = "CN=DN-Group,OU=GROUPS,DC=xxx,DC=xx"

Define special user types using groups. Exercise great caution when assigning superuser status.

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "put here the same as above"
"is_staff": "CN=NETBOXUSERS_Staff,OU=GROUPS,DC=xxx,DC=xx",
"is_superuser": "CN=NETBOX_USERS_Superuser,OU=GROUPS,DC=xxx,DC=xx"
}

AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600

When I try to connect with an AD User (in a group mentionned above) I got this message : "Please enter a correct username and password. Note that both fields may be case-sensitive."
I am able to log with the Admin user.

I have follow the official doc.
Thanks for your help.

Originally created by @Netbioox on GitHub (Jan 26, 2018). Hello, Just installed Netbox and I would like to implement LDAP authentication. Here's my ldap_config.py file: import ldap # Server URI AUTH_LDAP_SERVER_URI = "ldap://xxx.xxx.xx" # The following may be needed if you are binding to Active Directory. AUTH_LDAP_CONNECTION_OPTIONS = { ldap.OPT_REFERRALS: 0 } # Set the DN and password for the NetBox service account. AUTH_LDAP_BIND_DN = "CN=xxxxx,OU=SERVICES,DC=xx,DC=xx" AUTH_LDAP_BIND_PASSWORD = "MYxxxxxPASS" # Include this setting if you want to ignore certificate errors. This might be needed to accept a self-signed cert. # Note that this is a NetBox-specific setting which sets: # ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER) LDAP_IGNORE_CERT_ERRORS = True from django_auth_ldap.config import LDAPSearch AUTH_LDAP_USER_SEARCH = LDAPSearch("OU=USERS,DC=xxx,DC=xx",ldap.SCOPE_SUBTREE, "(uid=%(user)s)") # "(sAMAccountName=%(user)s)") > also try this # You can map user attributes to Django attributes as so. AUTH_LDAP_USER_ATTR_MAP = { "first_name": "givenName", "last_name": "sn", "email": "mail" } from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, NestedGroupOfNamesType AUTH_LDAP_GROUP_SEARCH = LDAPSearch("OU=GROUPS,DC=xxx,DC=xx", ldap.SCOPE_SUBTREE, "(objectClass=groupOfNames)") # "(objectClass=group)") > also try this # AUTH_LDAP_GROUP_TYPE = GroupOfNamesType() ### I changed this AUTH_LDAP_GROUP_TYPE = NestedGroupOfNamesType() # Define a group required to login AUTH_LDAP_REQUIRE_GROUP = "CN=DN-Group,OU=GROUPS,DC=xxx,DC=xx" # Define special user types using groups. Exercise great caution when assigning superuser status. AUTH_LDAP_USER_FLAGS_BY_GROUP = { "is_active": "put here the same as above" "is_staff": "CN=NETBOXUSERS_Staff,OU=GROUPS,DC=xxx,DC=xx", "is_superuser": "CN=NETBOX_USERS_Superuser,OU=GROUPS,DC=xxx,DC=xx" } AUTH_LDAP_FIND_GROUP_PERMS = True AUTH_LDAP_CACHE_GROUPS = True AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600 When I try to connect with an AD User (in a group mentionned above) I got this message : "Please enter a correct username and password. Note that both fields may be case-sensitive." I am able to log with the Admin user. I have follow the official doc. Thanks for your help.
adam closed this issue 2025-12-29 16:32:35 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 26, 2018):

Thank you for your interest in NetBox. GitHub issues are intended for reporting reproducible bugs and requesting features, and must be submitted using the template provided here. For general discussion, questions, or assistance with installation issues, please post to our mailing list.

@jeremystretch commented on GitHub (Jan 26, 2018): Thank you for your interest in NetBox. GitHub issues are intended for reporting reproducible bugs and requesting features, and must be submitted using the template provided [here](https://raw.githubusercontent.com/digitalocean/netbox/develop/.github/ISSUE_TEMPLATE.md). For general discussion, questions, or assistance with installation issues, please post to our [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1513