Kubesphere集成LDAP踩坑记录
之前在公司内部推广KubeSphere用于持续集成和部署,取得了不错的反馈,考虑到大规模使用的便利性以及之前已有LDAP整合其它系统的成熟经验,很自然的想将LDAP集成到KubeSphere中。原以为会很容易,一番折腾下来费了不好功夫(KubeSphere要求使用LDAP时必须设置管理员账号和密码),简单记录下。
公司内部的LDAP系统支持匿名登录,在给其它系统(如yapi)集成LDAP时,只需要输入对应的host、uid、searchDN即可,整合起来十分便捷,类似如下:
"ldapLogin":{
"enable":"true",
"server":"ldap://192.168.0.2:389",
"searchDn":"dc=lucumt,dc=info",
"searchStandard":"uid",
"usernameKey":"uid"
}
公司内部的KubeSphere版本为v3.1.1,在集成LDAP之前先去官网查看了相关说明,在LDAP身份提供者中有如下说明:
spec:
authentication:
jwtSecret: ''
maximumClockSkew: 10s
multipleLogin: true
oauthOptions:
accessTokenMaxAge: 1h
accessTokenInactivityTimeout: 30m
identityProviders:
- name: LDAP
type: LDAPIdentityProvider
mappingMethod: auto
provider:
host: 192.168.0.2:389
managerDN: uid=root,cn=users,dc=nas
managerPassword: ********
userSearchBase: cn=users,dc=nas
loginAttribute: uid
mailAttribute: mail
可以看出其默认多了managerDN和managerPassword这两个管理员属性,但由于公司的LDAP默认对外不提供管理员账号和密码,只能匿名登录认证,且自己之前在其它系统中匿名配置LDAP都很顺畅,于是通过匿名方式配置如下:
provider:
host: 192.168.1.22:389
#managerDN: uid=root,cn=users,dc=nas
#managerPassword: ********
userSearchBase: dc=lucumt,dc=info
loginAttribute: uid
mailAttribute: mail
将官方文档中要求的managerDN和managerPassword屏蔽掉,接着重启KubeSphere系统,登录过程出现如下提示:

错误信息提示说密码不能为空,但是我们登录的时候肯定有输入密码的,那只可能是managerPassword为空导致的。
查找KubeSphere官网相关说明发现其对于managerDN和managerPassword没有说明是选填项,结合前面的报错信息,可得出如下结论
KubeSphere不支持LDAP匿名登录

于是只能找公司相关部门申请LDAP具有只读账号的管理员权限,配置类似如下,之后重启KubeSphere可正常集成LDAP登录。
provider:
host: 192.168.1.22:389
managerDN: admin=cn,dc=lucumt,dc=info
managerPassword: ********
userSearchBase: dc=lucumt,dc=info
loginAttribute: uid
mailAttribute: mail
只能说KubeSphere在这方面做的不太好,已经在其官网反馈此问题!