oyx
#1
1. 极狐GitLab集成LDAP背景介绍
1.1 使用场景
- 将现有的LDAP用户同步到GitLab中
- 支持快速将LDAP服务器管理的用户同步到GitLab中
- 支持通过规则限定特定分类的LDAP用户同步到GitLab中
- 使用LDAP服务管理极狐GitLab用户
1.2 LDAP安全性检查
- 集成LDAP前需要对您的系统做以下检查,以确保使用的安全性
- 您的LDAP用户无法修改服务器中的
mail
,email
,userPrincipalName
字段
- 您的LDAP用户不能分享同一个email地址,否则这些用户可以访问同一个GitLab用户的资源
1.3 其他说明
- 社区用户可以使用LDAP集成的基础功能,部分高级功能仅开放给订阅用户
2. 配置LDAP集成
2.1 参考极狐官网安装GitLab
2.2 修改配置并重新配置GitLab实例
- 修改主配置文件
/etc/gitlab/gitlab.rb
添加以下内容:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['prevent_ldap_sign_in'] = false
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'LDAP',
'host' => 'ldap.mydomain.com',
'port' => 389,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'verify_certificates' => true,
'bind_dn' => '_the_full_dn_of_the_user_you_will_bind_with',
'password' => '_the_password_of_the_bind_user',
'tls_options' => {
'ca_file' => '',
'ssl_version' => '',
'ciphers' => '',
'cert' => '',
'key' => ''
},
'timeout' => 10,
'active_directory' => true,
'allow_username_or_email_login' => true,
'block_auto_created_users' => false,
'base' => 'dc=example,dc=com',
'user_filter' => '',
'attributes' => {
'username' => ['uid', 'userid', 'sAMAccountName'],
'email' => ['mail', 'email', 'userPrincipalName'],
'name' => 'cn',
'first_name' => 'givenName',
'last_name' => 'sn'
},
'lowercase_usernames' => false,
}
'label' => 'LDAP' # 该字段为LDAP服务名称,该名称会展示在GitLab Portal的登陆界面
'host' => 'ldap.mydomain.com' # 该字段为LDAP服务器的地址
'bind_dn' => '_the_full_dn_of_the_user_you_will_bind_with' # 该字段为LDAP管理员用户的DN
'password' => '_the_password_of_the_bind_user' # 该字段为LDAP管理员用户的password
# 例如,您可以通过配置user_filter将部分ldap用户同步到GitLab中
'(employeeType=developer)'
'(&(objectclass=user)(|(samaccountname=momo)(samaccountname=toto)))'
- 执行
sudo gitlab-ctl reconfigure
使得上述配置生效
2.3 使用Rake Task检查同步情况
- 配置完成后,可使用LDAP相关的Rake Task检查用户同步情况
gitlab-rake gitlab:ldap:check[100]
该命令检查前100个LDAP用户
3. 其他LDAP配置
3.1 LDAP用户同步周期
- GitLab默认每日执行LDAP用户同步,如果您需要修改LDAP的同步周期,可以通过修改
/etc/gitlab/gitlab.rb
中配置实现
gitlab_rails['ldap_sync_worker_cron'] = "0 */12 * * *"
1 个赞