让 JupyterHub 支持 LDAP 非加密端口
2024-03-21
问题
JupyterHub 的 LDAP 认证默认只支持 LDAPS(加密端口),对于使用非加密 LDAP 端口的场景无法正常工作。
原因
jupyterhub-ldapauthenticator
包中的 use_ssl
参数逻辑有问题,导致非加密连接时使用了错误的绑定模式。
解决方案
通过 Dockerfile 修改认证器源码,修复 use_ssl
逻辑:
1 2 3 4 5 6 7 8
| FROM jupyterhub/k8s-hub:latest
USER root
RUN FILEPATH=`python -c "import pkg_resources; import os; print(os.path.join(pkg_resources.get_distribution('jupyterhub-ldapauthenticator').location, 'ldapauthenticator', 'ldapauthenticator.py'))"` && \ sed -i 's/ldap3.AUTO_BIND_NO_TLS if self.use_ssl else ldap3.AUTO_BIND_TLS_BEFORE_BIND/ldap3.AUTO_BIND_NO_TLS if not self.use_ssl else ldap3.AUTO_BIND_TLS_BEFORE_BIND/g' ${FILEPATH}
USER jovyan
|
说明
这个修复将原来的 if self.use_ssl
改为 if not self.use_ssl
,确保:
- 非加密连接时使用
AUTO_BIND_NO_TLS
- 加密连接时使用
AUTO_BIND_TLS_BEFORE_BIND