Postgresql - 针对Active Directory的LDAP身份验证(AD) - 来自Linux服务器的问题



>编辑

我将相同的pg_hba规则放在安装在我的 WINDOWS 笔记本电脑上的 postgresql 上,它可以工作......所以我更改了标题:如何使我的 Linux 服务器像 Windows Pg 服务器一样使用 AD 对用户进行身份验证?

/编辑

我需要使用我们的活动目录服务器对postgresql db用户进行身份验证。我已经测试了很多配置,但到目前为止,我找不到为什么 postgresql 用户无法使用这种身份验证方法进行身份验证。

LDAP : Active Directory/Postgresql

: Postgresql 9.4

这是我使用pg_hba规则:

host myDB myUser localhost ldap ldapserver="192.168.10.1" ldapbasedn="DC=companygroup,DC=priv" ldapbinddn="cn=LDAP - Lecture,ou=Users,ou=Specials Objects,dc=companygroup,dc=priv" ldapbindpasswd="ldapPassWord" ldapsearchattribute="sAMAccountName"

使用此用户的正确密码使用"myUser"登录时,我在 postgresql 日志文件中有以下日志:

2015-11-18 10:01:50 CET [25991-1] [unknown]@[unknown] LOG: 00000: connection received: host=127.0.0.1 port=39074
2015-11-18 10:01:50 CET [25991-2] [unknown]@[unknown] LOCATION: BackendInitialize, postmaster.c:4003
2015-11-18 10:01:50 CET [25991-3] myUser@myDB LOG: 00000: could not search LDAP for filter "(sAMAccountName=myUser)" on server "192.168.10.1": Operations error
2015-11-18 10:01:50 CET [25991-4] myUser@myDB LOCATION: CheckLDAPAuth, auth.c:2030
2015-11-18 10:01:50 CET [25991-5] myUser@myDB FATAL: 28000: LDAP authentication failed for user "myUser"
2015-11-18 10:01:50 CET [25991-6] myUser@myDB DETAIL: Connection matched pg_hba.conf line 104: "host myDB myUser localhost ldap ldapserver="192.168.10.1" ldapbasedn="DC=companygroup,DC=priv" ldapbinddn="cn=LDAP - Lecture,ou=Users,ou=Specials Objects,dc=companygroup,dc=priv" ldapbindpasswd="ldapPassWord" ldapsearchattribute="sAMAccountName"

我看到如果我以某种方式更改 ldapbinddn 或 ldapbindpasswd,我会遇到另一个错误,例如"无法为 ldapbinddn 执行初始 LDAP 绑定"..."。 所以这些参数应该没问题。

"操作错误"不是很详细,所以我tcpdump身份验证过程,这是我发现的。似乎Postgres执行了两个查询:

  • 首先通过搜索属性搜索用户。此操作似乎没问题,因为在Active Directory的响应中,我看到了与用户相关的信息。

  • 然后执行另一个查询。在这个问题上,来自LDAP活动目录服务器的真实消息是:

    LdapErr: DSID-0C0906E8,注释:要执行此操作,必须在连接上完成成功的绑定。, 数据 0 , v1db1

在第二个查询中,我看到 PG 似乎略微改变了基本搜索 "DC=ForestDnsZones,DC=companygroup,dc=priv"而不是"DC=companygroup,DC=priv"

(我在 tcp 跟踪中看到它:

LDAPMessage searchRequest(3) "DC=ForestDnsZones,DC=companygroup,dc=priv" wholeSubtree ...

当我尝试通过Windows软"ldapbrowser"进行研究时,我能够使用简单的过滤器(sAMAccountName=myUser)找到我的帐户,搜索DN DC=companygroup,DC=priv

我的理解正确吗? 是否有可能仅仅因为可能更改的基数而搜索不成功? 还是我错过了别的东西?

根据您的日志,ldapsearchattribute="sAMAccountName"的配置不起作用。

您可以使用 LDAP 工具(如 LDAPAdmin 或 OpenLDAP)来测试过滤器。确保上述返回结果时过滤以下属性

(sAMAccountName=myUser)

最新更新