下面给你一个在 Debian 上部署的 GitLab 集成 LDAP(以 OpenLDAP / Active Directory 为例)的实用指南,涵盖配置位置、常见参数、验证方法和排错。
Omnibus GitLab 主配置:
/etc/gitlab/gitlab.rb
修改后必须执行:
gitlab-ctl reconfigure
gitlab-ctl restart
编辑 /etc/gitlab/gitlab.rb:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'LDAP',
'host' => 'ldap.example.com',
'port' => 389,
'uid' => 'uid',
'method' => 'plain',
'bind_dn' => 'cn=admin,dc=example,dc=com',
'password' => 'ldap_admin_password',
'active_directory' => false,
'allow_username_or_email_login' => true,
'base' => 'ou=users,dc=example,dc=com',
'user_filter' => '',
'attributes' => {
'username' => ['uid'],
'email' => ['mail'],
'name' => ['cn'],
'first_name' => ['givenName'],
'last_name' => ['sn']
}
}
}
gitlab_rails['ldap_servers'] = {
'ad' => {
'label' => 'AD',
'host' => 'ad.example.com',
'port' => 389,
'uid' => 'sAMAccountName',
'method' => 'plain',
'bind_dn' => 'cn=gitlab,ou=service,dc=example,dc=com',
'password' => 'password',
'active_directory' => true,
'allow_username_or_email_login' => true,
'base' => 'dc=example,dc=com',
'user_filter' => '',
'attributes' => {
'username' => ['sAMAccountName'],
'email' => ['mail'],
'name' => ['displayName'],
'first_name' => ['givenName'],
'last_name' => ['sn']
}
}
}
'port' => 636,
'method' => 'ssl',
'ca_file' => '/etc/ssl/certs/ldap-ca.crt',
gitlab-rake gitlab:ldap:check
输出示例:
Checking LDAP...
LDAP users with access to your GitLab server (only showing first 100 results)
uid 设置错误(AD 用 sAMAccountName)base 范围不对user_filter 过滤'allow_username_or_email_login' => true
'user_filter' => '(memberOf=cn=gitlab-users,ou=groups,dc=example,dc=com)'
如果你愿意,可以告诉我:
我可以直接帮你写一份可用的 gitlab.rb 配置。