【发布时间】:2020-10-27 22:01:44
【问题描述】:
我使用 Docker (https://github.com/osixia/docker-openldap) 设置和 LDAP 服务器,并在同一台机器上安装了 Jupyterhub。不幸的是,LDAP-Server 和 JupyterHub 之间的连接不起作用。这些是与jupyterhub_config.py 中的 LDAP 身份验证对应的行:
c.JupyterHub.authenticator_class = 'ldapauthenticator.LDAPAuthenticator'
c.LDAPAuthenticator.server_address = '192.168.48.2' # Docker Container IP of openldap
c.LDAPAuthenticator.lookup_dn = True
c.LDAPAuthenticator.use_ssl = False
# c.LDAPAuthenticator.bind_dn_template = ["cn={username},dc=example,dc=com"]
(在最后两行之间切换没有区别。)
当我尝试在 JupyterHub 登录页面登录时,弹出以下错误:
ldap3.core.exceptions.LDAPSocketSendError: socket sending error[Errno 32] Broken pipe
我可以使用 ldapsearch 从命令行“访问”LDAP 数据库:
ldapsearch -x -H ldap://192.168.48.2 -b dc=example,dc=com -D "cn=admin,dc=example,dc=com" -w password
禁用防火墙也没有什么区别(正在考虑 Docker(openldap) 和 jupyterhub 之间的一些网络问题)。
jupyterhub==1.1.0
jupyterhub-ldapauthenticator==1.3.2
我能够在 JupyterHub 之外使用 ldap3 重现此问题:
# Get IP of dockerized OpenLDAP
import docker
client = docker.DockerClient()
container = client.containers.get("openldap")
ip_add = container.attrs['NetworkSettings']['Networks']['ldap_default']['IPAddress']
# Check Connection
from ldap3 import Server, Connection, ALL
server = Server(ip_add,use_ssl=False,port=389)
conn = Connection(server)
print(conn.bind(read_server_info=True))
> True
当我现在将 ssl=False 替换为 ssl=True 时,它会返回与 JupyterHub 相同的错误:
# Check Connection
from ldap3 import Server, Connection, ALL
server = Server(ip_add,use_ssl=True,port=636
conn = Connection(server)
print(conn.bind(read_server_info=True))
Traceback (most recent call last):
File "test_connection.py", line 11, in <module>
print(conn.bind(read_server_info=True))
File "/opt/anaconda3/lib/python3.8/site-packages/ldap3/core/connection.py", line 590, in bind
response = self.post_send_single_response(self.send('bindRequest', request, controls))
File "/opt/anaconda3/lib/python3.8/site-packages/ldap3/strategy/base.py", line 330, in send
self.sending(ldap_message)
File "/opt/anaconda3/lib/python3.8/site-packages/ldap3/strategy/base.py", line 882, in sending
raise communication_exception_factory(LDAPSocketSendError, type(e)(str(e)))(self.connection.last_error)
ldap3.core.exceptions.LDAPSocketSendError: socket sending error[Errno 32] Broken pipe
这似乎与 SSL/TLS/StartTLS 有关。如果我在jupyterhub_config.py 中禁用ssl,则身份验证器将(尝试)使用 StartTLS 进行升级。
LDAPAuthenticator.use_ssl
布尔值,用于指定联系时是否使用 SSL 加密 LDAP 服务器。如果保留为 False(默认)LDAPAuthenticator 将尝试使用 StartTLS 升级连接。将此设置为 True 启动 SSL 连接。 (网址:https://github.com/jupyterhub/ldapauthenticator :)
【问题讨论】:
标签: ldap jupyterhub