openLdap添加memberOf支持
# 摘要
OpenLdap默认用户组属性是Posixgroup, 在需要根据用户组来过滤用户的场景时,因Posixgroup的memberUid只记录了用户的uid值,所以无法满足实际的组过滤需求,因此引入了通过memberOf 属性进行查询的groupOfUniqueNames用户组,目前较流行的开源软件中都集成了通过memberof属性进行组过滤的配置。
# 文档环境
(opens new window)
(opens new window)
- 本文档中代码的测试环境
# 添加memberOf 模块
# 初始化module配置
创建ldif 文件,在openldap中加载memberof模块。创建module_config.ldif并导入。
cat >module_config.ldif<<EOF
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib64/openldap
EOF
# 导入ldif 文件
ldapadd -Q -Y EXTERNAL -H ldapi:/// -f module_config.ldif
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 添加memberof模块及配置
cat >memberof_module.ldif<<EOF
dn: cn=module{0},cn=config
add: olcmoduleload
olcmoduleload: memberof.so
EOF
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f memberof_module.ldif
cat >memberof_config.ldif<<EOF
dn: olcOverlay={0}memberof,olcDatabase={1}hdb,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcMemberOf
olcOverlay: {0}memberof
olcMemberOfDangling: ignore
olcMemberOfRefInt: TRUE
olcMemberOfGroupOC: groupOfUniqueNames # 用户组的objectClass
olcMemberOfMemberAD: uniqueMember # 用户的属性名
olcMemberOfMemberOfAD: memberOf
EOF
ldapadd -Q -Y EXTERNAL -H ldapi:/// -f memberof_config.ldif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- ldif文件中 "{X}" 需要根据实际情况修改
# 测试
ldapsearch -x -LLL -H ldap:/// -D cn=root,dc=nginxbar,dc=com -W -b ou=Employees,dc=nginxbar,dc=com memberOf
1
# gitlab 的 memberof 配置
gitlab_rails['ldap_enabled'] = true
###! **remember to close this block with 'EOS' below**
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'LDAP'
host: '192.17.0.14'
port: 389
uid: 'uid'
bind_dn: 'cn=root,dc=nginxbar,dc=com'
password: '********'
encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
verify_certificates: true
active_directory: true
allow_username_or_email_login: false
lowercase_usernames: false
block_auto_created_users: false
base: 'dc=nginxbar,dc=com'
user_filter: '(memberof=cn=gitlab,ou=Group,dc=nginxbar,dc=com)'
## EE only
group_base: ''
admin_group: ''
sync_ssh_keys: false
EOS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
上次更新: 2022/12/05, 22:29:05