#12224·InvenTree

LDAP login with Active Directory fails until OPT_REFERRALS is disabled

Author: markusEmm123Created Jun 22, 2026Updated Sep 25, 2026
Labelssetupinactivedocumentation

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

LDAP authentication against Microsoft Active Directory fails with:

Authentication failed for : failed to map the username to a DN.

even though:

bind credentials are correct LDAP search filter is correct manual ldapsearch returns the expected user

The root cause appears to be Active Directory referrals.

Adding

ldap:
  global_options:
    OPT_REFERRALS: OPT_OFF

immediately fixes the problem.

Not sure if this belongs here or should be handled by the python_ldap community.

Steps to Reproduce

LDAP configuration:

ldap:
  enabled: true
  debug: true

  server_uri: "ldap://ldap.example.local:389"

  bind_dn: "DOMAIN\\ldap_bind"
  bind_password: "secret"

  search_base_dn: "DC=example,DC=local"
  search_filter_str: "(sAMAccountName=%(user)s)"

Attempt login with a valid AD user.

Expected behaviour

Expecting successful login or more fitting error message.

Observed behaviour

Login fails:

Authentication failed for user: failed to map the username to a DN.

Debugging inside the container shows:

u.settings.USER_SEARCH.execute(...)

returns exactly one matching LDAP object.

However:

u._search_for_user_dn()

returns None until referrals are disabled.

Direct python-ldap tests also fail when referrals are enabled and succeed when:

ldap.set_option(ldap.OPT_REFERRALS, 0)

is configured.

Workaround

ldap:
  global_options:
    OPT_REFERRALS: OPT_OFF

After restarting all containers, authentication works normally.

Suggested improvement

Either:

document that Active Directory deployments may require ldap: global_options: OPT_REFERRALS: OPT_OFF

or

disable referrals automatically for Active Directory configurations.

Additionally, logging could be improved because the current message

failed to map the username to a DN

does not indicate that the underlying issue is referral handling.

Deployment Method

Docker

Version Information

InvenTree: 1.3.0 (Docker) django-auth-ldap: 5.3.0 python-ldap: 3.4.5 Active Directory backend

Try to reproduce on the demo site

I tried to reproduce

Is the bug reproducible on the demo site?

Not reproducible

Relevant log output

bash