无法对JupyterHub使用LDAP身份验证:管道中断错误

无法对JupyterHub使用LDAP身份验证:管道中断错误,ldap,jupyterhub,Ldap,Jupyterhub,我使用Docker()设置和安装LDAP服务器,并在同一台机器上安装Jupyterhub。不幸的是,LDAP服务器和JupyterHub之间的连接不起作用。以下是与jupyterhub_config.py中的LDAP身份验证对应的行: c.JupyterHub.authenticator_class = 'ldapauthenticator.LDAPAuthenticator' c.LDAPAuthenticator.server_address = '192.168.48.2' # Docke

我使用Docker()设置和安装LDAP服务器,并在同一台机器上安装Jupyterhub。不幸的是,LDAP服务器和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以外的
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
# 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=True
替换
ssl=False
时,它返回与JupyterHub相同的错误:

# 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
# 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
#检查连接
从ldap3导入服务器、连接、所有
服务器=服务器(ip添加,使用ssl=True,端口=636
conn=连接(服务器)
打印(conn.bind(读取服务器信息=True))
回溯(最近一次呼叫最后一次):
文件“test_connection.py”,第11行,在
打印(conn.bind(读取服务器信息=True))
文件“/opt/anaconda3/lib/python3.8/site packages/ldap3/core/connection.py”,第590行,在bind中
response=self.post\u send\u single\u response(self.send('bindRequest',request,controls))
文件“/opt/anaconda3/lib/python3.8/site packages/ldap3/strategy/base.py”,第330行,在send中
自我发送(ldap_消息)
文件“/opt/anaconda3/lib/python3.8/site packages/ldap3/strategy/base.py”,第882行,发送
引发通信异常工厂(LDAPSocketSendError,类型(e)(str(e))(self.connection.last_错误)
ldap3.core.exceptions.LDAPSocketSendError:套接字发送错误[Errno 32]管道破裂
这似乎与SSL/TLS/StartTLS有关。如果我在
jupyterhub_config.py
中禁用
SSL
,验证器将(尝试)使用StartTLS升级

LDAPAuthenticator.use_ssl

布尔值,用于指定在联系时是否使用SSL加密 LDAP服务器。如果保留为False(默认值),则为ldaAuthenticator 将尝试升级与StartTLS的连接。将此设置为True以 启动SSL连接。 (网址:)

尝试替换:

  c.LDAPAuthenticator.server_address= 'ldaps://192.168.48.2:636' or 'ladp://192.168.48.2:389'

636和389是ldap和ldap的默认端口

谢谢您的回答。不幸的是,这也不起作用。我将ldap移到了本地安装,而不是docker,现在一切正常。