我试图在CentOS主机系统上通过LDAP进行身份validation。 但是我总是得到一个无法联系来自pam_ldap的LDAP服务器错误。
LDAP服务器是可ping通的,身份validation与ldap://完美协同工作,但不能使用ldaps://。 它也可以在debian操作系统上使用ldaps://而不是在CentOS上。
我得到了无法与$ ldapsearch 联系错误…但我解决了它设置TLS_REQCERT允许在/etc/openldap/ldap.conf。 但是为/etc/pam_ldap.conf设置不起作用。
我做的步骤:
一些更多的信息:
另外令人困惑的是/ var / log / secure中的IP。 在那里它表示来自10.1.1.1的testuser的失败密码 ,但是configuration的用于LDAP服务器的IP是10.1.1.42并且主机IP是10.1.1.27。 无论如何,如果我使用uri ldap://10.1.1.42并且注释authentication行ssl就像一个魅力一样。
有任何想法吗?
。
尝试通过pam进行身份validation, / 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
运行$ 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 ...
/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
/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
/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
/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
线索在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
它说: certificate ... is not valid... Peer's certificate issuer has been marked as not trusted by the user 。 这意味着用于颁发服务器证书的CA不受信任。 在我看来,CACERTFILE TLS_CACERTFILE /srv/ldap-cacert.pem不包含正确的CA证书。 直到你得到一个错误的清洁ldapsearch输出它将无法正常工作。
一旦解决了问题,您可能会因为证书的CN而导致错误。 如果是这样,请尝试使用ldaps://sub.example.org/作为URI而不是ldaps://10.1.1.42/ 。 如果你的DNS没有parsing这个名字,只要把它放在你的/etc/hosts文件中(只是为了testing,你应该更新你的DNSlogging)。
Migtor把我推向正确的方向。 谢谢!
当我删除TLS_REQCERT并检查了ldapsearch错误时,我也得到了TLS: error: connect - force handshake failure: errno 2 - moznss error -8172 。
我的CA证书是正确的,但openldap默认使用Mozillanetworking安全服务(MozNSS)来检查权限。 所以我必须将我的自签名CA添加到此数据库。
编辑:正如Migtor在他的评论中指出的那样,这只适用于CentOS,RHEL和衍生品。
。
首先将您的CA证书复制到客户端(我的path:/etc/openldap/cacerts/ldap-cacert.pem)
在安装pam_ldap之后,MozNSS数据库位于/ etc / openldap / certs中:
# certutil -d /etc/openldap/certs -A -n "ldap CA" -t TCu,Cu,Tuw -a -i /etc/openldap/cacerts/ldap-cacert.pem
# certutil -L -d /etc/openldap/certs 我的/etc/pam_ldap.conf的新内容
ldap_version 3 pam_password crypt uri ldaps://[FQDN-of-my-ldap-server]:636 base dc=sub,dc=example,dc=org ssl on tls_cacertdir /etc/openldap/certs
。
这不再是必需的。 我清除它,/ etc / nslcd.conf不再可用。
。
资料来源: