pam_ldap 和 ldaps 无法联系 ldap 服务器

lsz*_*zrh 3 ldap centos authentication pam

我正在尝试允许在 CentOS 主机系统上通过 LDAP 进行身份验证。但是我总是从 pam_ldap收到无法联系 LDAP 服务器的错误。

LDAP 服务器是可 ping 的,并且身份验证可以与 ldap:// 完美配合,但不能与 ldaps:// 配合使用。在 debian 操作系统上,它也可以与 ldaps:// 完美配合,但在 CentOS 上则不行。

我也遇到了$ ldapsearch无法联系错误...但我修复了它,在 /etc/openldap/ldap.conf 中设置了TLS_REQCERT 允许。但是为 /etc/pam_ldap.conf 设置这个没有帮助。

我做的步骤:

  • $ yum 安装 pam_ldap nss-pam-ldapd openldap-clients
  • $ authconfig-tui并激活 LDAP 进行身份验证
  • 修改/etc/pam_ldap
  • 修改/etc/nslcd.conf
  • 修改/etc/openldap/ldap.conf
  • 创建/etc/ldap/ldap.conf(在某处阅读它是后备配置文件路径)
  • 创建/etc/ldap.conf(内容与/etc/ldap/ldap.conf相同)
  • 重启服务 nscd 和 nslcd

更多信息:

  • 来自 LDAP-Server 的 CA-Cert 对每个人都是可读的。
  • iptables 被禁用

同样令人困惑的是/var/log/secure 中的 IP 。它说来自 10.1.1.1 的 testuser 密码失败,但 LDAP 服务器的配置 IP 是 10.1.1.42,主机 IP 是 10.1.1.27。无论如何,如果我使用 uri ldap://10.1.1.42 并评论身份验证行ssl就像一个魅力。

有任何想法吗?

.

尝试通过 pam、/var/log/secure进行身份验证

Sep 15 09:50:37 client-server unix_chkpwd[16146]: password check failed for user (testuser)
Sep 15 09:50:37 client-server sshd[16144]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=10.1.1.1  user=testuser
Sep 15 09:50:37 client-server sshd[16144]: pam_ldap: ldap_simple_bind Can't contact LDAP server
Sep 15 09:50:37 client-server sshd[16144]: pam_ldap: reconnecting to LDAP server...
Sep 15 09:50:37 client-server sshd[16144]: pam_ldap: ldap_simple_bind Can't contact LDAP server
Sep 15 09:50:40 client-server sshd[16144]: Failed password for testuser from 10.1.1.1 port 11339 ssh2
Sep 15 09:50:40 client-server sshd[16145]: Received disconnect from 10.1.1.1: 13: Unable to authenticate
Run Code Online (Sandbox Code Playgroud)

运行$ldapsearch -v -H ldaps://10.1.1.42/ -D cn=admin,dc=sub,dc=example,dc=org -W -x -b dc=sub,dc=example,dc=org - d1检查 ldaps// 是否正常工作。(是的,它有效)

ldap_url_parse_ext(ldaps://10.1.1.42/)
ldap_initialize( ldaps://10.1.1.42:636/??base )
ldap_create
ldap_url_parse_ext(ldaps://10.1.1.42:636/??base)
Enter LDAP Password:
ldap_sasl_bind
ldap_send_initial_request
ldap_new_connection 1 1 0
ldap_int_open_connection
ldap_connect_to_host: TCP 10.1.1.42:636
ldap_new_socket: 3
ldap_prepare_socket: 3
ldap_connect_to_host: Trying 10.1.1.42:636
ldap_pvt_connect: fd: 3 tm: -1 async: 0
TLS: certificate [CN=sub.example.org,OU=test-ou,O=test-o,ST=test-st,C=DE] is not valid - error -8172:Peer's certificate issuer has been marked as not trusted by the user..
TLS certificate verification: subject: CN=sub.example.org,OU=test-ou,O=test-o,ST=test-st,C=DE, issuer: CN=sub.example.org,OU=test-ou,O=test-o,ST=test-st,C=DE, cipher: AES-128, security level: high, secret key bits: 128, total key bits: 128, cache hits: 0, cache misses: 0, cache not reusable: 0
ldap_open_defconn: successful
ldap_send_server_request
...
Run Code Online (Sandbox Code Playgroud)

/etc/pam_ldap.conf 的内容

ldap_version 3
pam_password crypt
uri ldaps://10.1.1.42:636
base dc=sub,dc=example,dc=org
ssl on
tls_reqcert allow
tls_cacertfile /srv/ldap-cacert.pem
tls_checkpeer no
Run Code Online (Sandbox Code Playgroud)

/etc/openldap/ldap.conf 的内容

TLS_REQCERT allow
TLS_CACERTFILE /srv/ldap-cacert.pem
URI ldaps://10.1.1.42:636/
BASE dc=sub,dc=example,dc=org
Run Code Online (Sandbox Code Playgroud)

/etc/nslcd.conf 的内容

uid nslcd
gid ldap
ssl on
tls_reqcert allow
tls_cacertfile /srv/ldap-cacert.pem
uri ldaps://10.1.1.42:636/
base dc=sub,dc=example,dc=org
Run Code Online (Sandbox Code Playgroud)

/etc/ldap.conf/etc/ldap/ldap.conf 的内容:

tls_checkpeer no
tls_reqcert allow
tls_cacertfile /srv/ldap-cacert.pem
uri ldaps://10.1.1.42:636/
base dc=sub,dc=example,dc=org
Run Code Online (Sandbox Code Playgroud)

Mig*_*tor 6

线索在ldapsearch命令输出中:

TLS: certificate [CN=sub.example.org,OU=test-ou,O=test-o,ST=test-st,C=DE] is not valid - error -8172:Peer's certificate issuer has been marked as not trusted by the user..
TLS certificate verification: subject: CN=sub.example.org,OU=test-ou,O=test-o,ST=test-st,C=DE, issuer: CN=sub.example.org,OU=test-ou,O=test-o,ST=test-st,C=DE, cipher: AES-128, security level: high, secret key bits: 128, total key bits: 128, cache hits: 0, cache misses: 0, cache not reusable: 0
Run Code Online (Sandbox Code Playgroud)

它说:certificate ... is not valid... Peer's certificate issuer has been marked as not trusted by the user。这意味着用于颁发服务器证书的 CA 不受信任。在我看来,CACERTFILETLS_CACERTFILE /srv/ldap-cacert.pem不包含正确的 CA 证书。在您获得错误清除ldapsearch输出之前,它不会起作用。

一旦解决了这个问题,您可能会因证书的 CN 而出现错误。如果这样做,请尝试使用ldaps://sub.example.org/as URI 而不是ldaps://10.1.1.42/. 如果您的 DNS 无法解析该名称,只需将其放入您的/etc/hosts文件中(仅用于测试,您应该更新您的 DNS 记录)。