【问题标题】:LDAPInvalidDNSyntaxResult error when binding LDAP connection in Flask app在 Flask 应用程序中绑定 LDAP 连接时出现 LDAPInvalidDNSyntaxResult 错误
【发布时间】:2020-04-10 15:50:37
【问题描述】:

我有一个 Flask 应用程序,我正在尝试使用 flask-ldap3-login 包连接到我的 LDAP 服务器 (OpenLDAP),但我似乎无法正确绑定连接。

我的环境变量设置为:

LDAP_HOST = 'openldap'
LDAP_BASE_DN = 'dc=example,dc=org'
LDAP_BIND_USER_DN = 'cn=admin,dc=example,dc=org'
LDAP_BIND_USER_PASSWORD = 'admin'
LDAP_USER_DN = 'ou=users'
LDAP_USER_RDN_ATTR = 'cn'
LDAP_USER_LOGIN_ATTR = 'cn'

当我使用 result = ldap_manager.authenticate(username, password) 进行身份验证时,我收到一条回复说:

LDAPInvalidDNSyntaxResult - 34 - invalidDNSyntax - None - invalid DN - bindResponse - None

因此结果是:

{'user_info': (None,), 'user_id': (None,), 'user_dn': (None,), 'user_groups': [], 'status': <AuthenticationResponseStatus.fail: 1>}

这是我的 LDAP 结构:

这是一个示例用户 DN:

如果我尝试通过ldapsearch 命令进行连接,我会得到正确的响应:

# ldapsearch -x -b "ou=users,dc=example,dc=org" -H "ldap://openldap" -D "cn=admin,dc=example,dc=org" -W
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <ou=users,dc=example,dc=org> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# users, example.org
dn: ou=users,dc=example,dc=org
ou: users
objectClass: organizationalUnit
objectClass: top

# gramsay, users, example.org
dn: cn=gramsay,ou=users,dc=example,dc=org
givenName: Gordon
sn: Ramsay
cn: gramsay
uid: gramsay
userPassword:: <password>
uidNumber: 1000
gidNumber: 500
homeDirectory: /home/users/gramsay
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top

# iausers, users, example.org
dn: cn=iausers,ou=users,dc=example,dc=org
cn: iausers
gidNumber: 500
objectClass: posixGroup
objectClass: top

# search result
search: 2
result: 0 Success

# numResponses: 4
# numEntries: 3

我的连接方式是否有问题,或者可能是我的 LDAP 服务器上的结构有问题?

【问题讨论】:

    标签: python flask ldap openldap flask-login


    【解决方案1】:

    问题最终是flask-ldap3-login 试图与提供的用户名/密码进行直接绑定,而不是管理员凭据,这是无效的。相反,我需要设置 LDAP_ALWAYS_SEARCH_BIND = True 以确保执行搜索绑定而不是直接绑定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-03
      • 1970-01-01
      • 2017-02-18
      • 2017-07-07
      • 2022-01-05
      • 1970-01-01
      • 2022-10-07
      相关资源
      最近更新 更多