使用 Nginx 作为反向代理的 LDAP 上的 TLS

问题描述

我已设置要在其上运行的 LDAP 服务器:

SLAPD_SERVICES="ldap://192.168.56.104:3389/"

我可以使用 ps aux 来检查:

root@ldap-client:/etc/Nginx# ps aux | grep slapd
openldap    8931  0.0  0.2 1339368 8852 ?        Ssl  20:41   0:00 /usr/sbin/slapd -h ldap://192.168.56.104:3389/ -g openldap -u openldap -F /etc/ldap/slapd.d
root       10963  0.0  0.0   9124   840 pts/1    S+   21:15   0:00 grep --color=auto slapd

然后我将 Nginx 配置为 OpenLDAP 服务器和 TLS 上的反向代理。配置如下:

root@ldap-client:/etc/Nginx# cat /etc/Nginx/conf.stream.d/ldap.conf
stream {

    upstream backend {
        server 192.168.56.104:3389;
   }

    server {
        listen     192.168.56.104:3388 ssl;
        proxy_pass backend;

        ssl_certificate     /etc/Nginx/conf.stream.d/ldap-certs/192.168.56.104.pem;
        ssl_certificate_key     /etc/Nginx/conf.stream.d/ldap-certs/192.168.56.104-key.pem;
    }
}

Nginx 也能正常工作:

root@ldap-client:/etc/Nginx# ps aux | grep Nginx
root       10713  0.0  0.0  56736  1628 ?        Ss   20:57   0:00 Nginx: master process /usr/sbin/Nginx -g daemon on; master_process on;
www-data   10714  0.0  0.2  57436  7176 ?        S    20:57   0:00 Nginx: worker process
root       10997  0.0  0.0   8992   912 pts/1    S+   21:17   0:00 grep --color=auto Nginx

root@ldap-client:/etc/Nginx# netstat -antp | grep LISTEN
# redundant info removed
tcp        0      0 192.168.56.104:3388     0.0.0.0:*               LISTEN      10713/Nginx: master
tcp        0      0 192.168.56.104:3389     0.0.0.0:*               LISTEN      8931/slapd

然后我也可以使用 ldapsearch 进行搜索

  • 没有 -Z 标志:
root@ldap-client:/etc/Nginx# ldapsearch -x -H ldaps://192.168.56.104:3388 -D "cn=ldapadmin,dc=code,dc=com" -W -b "dc=code,dc=com"  '(memberuid=alice)'
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <dc=code,dc=com> with scope subtree
# filter: (memberuid=alice)
# requesting: ALL
#

# codeadmin,Groups,code.com
dn: cn=codeadmin,ou=Groups,dc=com
objectClass: posixGroup
cn: codedmin
gidNumber: 5001
memberUid: alice

# search result
search: 3
result: 0 Success

# numResponses: 2
# numEntries: 1
  • 带有 -Z 标志:
root@ldap-client:/etc/Nginx# ldapsearch -x -Z  -H ldaps://192.168.56.104:3388 -D "cn=ldapadmin,dc=com"  '(memberuid=alice)'
ldap_start_tls: Protocol error (2)
        additional info: unsupported extended operation
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <dc=code,dc=com
objectClass: posixGroup
cn: codeadmin
gidNumber: 5001
memberUid: alice

# search result
search: 3
result: 0 Success

# numResponses: 2
# numEntries: 1

我不确定它为什么会起作用,因为我没有将 CA CERT 传递给任何 ldapsearch 执行。这是客户端不验证 CA 的不安全 TLS 吗?

还有,带有 -Z 标志的错误消息背后的原因是什么?

ldap_start_tls: Protocol error (2)
        additional info: unsupported extended operation

在网上搜索时,我看到所有响应都使用 TLS 证书本身配置了 OpenLDAP 服务器,而 Nginx 没有发挥作用,所以我在那里没有得到任何帮助。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)