fe/fe-authentication/fe-authentication-plugins/fe-authentication-plugin-ldap/README.md
LDAP 认证插件,用于将用户身份验证委托给 LDAP 服务器。
Principal{username, externalGroups}CREATE AUTHENTICATION INTEGRATION corp_ldap
TYPE = 'ldap'
WITH (
'server' = 'ldap://ldap.example.com:389',
'base_dn' = 'dc=example,dc=com'
);
CREATE AUTHENTICATION INTEGRATION corp_ldap
TYPE = 'ldap'
WITH (
-- 必需配置
'server' = 'ldap://ldap.example.com:389',
'base_dn' = 'dc=example,dc=com',
-- 用户查找配置
'user_base_dn' = 'ou=users,dc=example,dc=com',
'user_filter' = '(uid={login})',
-- 组查找配置
'group_base_dn' = 'ou=groups,dc=example,dc=com',
'group_filter' = '', -- 可选,默认使用 member 属性
-- LDAP 绑定凭据(用于组查询)
'bind_dn' = 'cn=admin,dc=example,dc=com',
'bind_password' = 'admin_password'
);
| 参数 | 必需 | 默认值 | 说明 |
|---|---|---|---|
server | 是 | 无 | LDAP 服务器地址,格式:ldap://host:port |
base_dn | 是 | 无 | LDAP 基础 DN |
user_base_dn | 否 | ou=users,{base_dn} | 用户搜索基础 DN |
user_filter | 否 | (uid={login}) | 用户过滤器,{login} 会被替换为用户名 |
group_base_dn | 否 | ou=groups,{base_dn} | 组搜索基础 DN |
group_filter | 否 | 空(使用 member) | 组过滤器,支持 {login} 占位符 |
bind_dn | 否 | 无 | LDAP 管理员 DN(用于组查询) |
bind_password | 否 | 无 | LDAP 管理员密码 |
| 功能 | fe-core 实现 | 插件实现 | 状态 |
|---|---|---|---|
| 用户查找 | LdapClient.getUserDn() | LdapClient.getUserDn() | 已对齐 |
| 密码验证 | LdapClient.checkPassword() | LdapClient.checkPassword() | 已对齐 |
| 组提取 | LdapClient.getGroups() | LdapClient.getGroups() | 已对齐 |
| 组名解析 | 从 DN 提取 cn | 从 DN 提取 cn | 已对齐 |
CREATE AUTHENTICATION INTEGRATION corp_ldap
TYPE = 'ldap'
WITH (
'server' = 'ldap://ldap.corp.com:389',
'base_dn' = 'dc=corp,dc=com',
'bind_dn' = 'cn=admin,dc=corp,dc=com',
'bind_password' = 'admin_pass'
);
CREATE USER 'alice'@'%' IDENTIFIED WITH corp_ldap;
mysql -h doris-host -P 9030 -u alice -p
# 输入 LDAP 密码
1. 用户输入用户名和密码
↓
2. 插件查找用户 DN
- 使用 user_filter 在 user_base_dn 下搜索
↓
3. 插件验证密码
- 使用用户 DN 和密码尝试 LDAP 绑定
↓
4. 插件提取 LDAP 组
- 使用 bind_dn 在 group_base_dn 下搜索
- 从组 DN 提取组名(cn=group_name,... → group_name)
↓
5. 返回 Principal{username, groups}
↓
6. fe-core/Auth 执行 ROLE_MAPPING
- LDAP 组 → Doris 角色
↓
7. 权限检查
运行单元测试:
cd fe-authentication-plugins/fe-authentication-plugin-ldap
mvn test
注意:完整的集成测试需要运行 LDAP 服务器(如 Docker 中的 OpenLDAP)。