GitLab 集成 Linux LDAP(通常指 OpenLDAP)主要通过修改 GitLab 的配置文件来实现。以下是详细的集成步骤和配置说明。
389,加密 636)sudo vim /etc/gitlab/gitlab.rb
示例(OpenLDAP 常见配置):
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main:
label: 'LDAP'
host: 'ldap.example.com'
port: 389
uid: 'uid'
bind_dn: 'cn=admin,dc=example,dc=com'
password: 'ldap_admin_password'
encryption: 'plain' # 可选:start_tls / simple_tls
verify_certificates: true
smartcard_auth: false
active_directory: false
allow_username_or_email_login: true
lowercase_usernames: true
block_auto_created_users: false
base: 'ou=people,dc=example,dc=com'
user_filter: ''
attributes:
username: ['uid']
email: ['mail']
name: ['cn']
first_name: ['givenName']
last_name: ['sn']
EOS
| 参数 | 说明 |
|---|---|
| host | LDAP 服务器地址 |
| port | 389(普通) / 636(SSL) |
| uid | 登录使用的属性,OpenLDAP 通常是 uid |
| bind_dn | 用于查询 LDAP 的账号 |
| base | 用户搜索基准 |
| user_filter | 用户过滤条件(可选) |
| active_directory | OpenLDAP 设为 false |
sudo gitlab-ctl reconfigure
sudo gitlab-rake gitlab:ldap:check
正常输出示例:
Checking LDAP ...
Server: ldapmain
LDAP authentication... Success
LDAP users with access to your GitLab server (only showing the first 100 results)
port: 636
encryption: 'simple_tls'
如果 LDAP 使用自签名证书:
verify_certificates: false
或把 CA 证书放入:
/etc/gitlab/trusted-certs/
然后重新配置。
bind_dn 和密码base 是否正确sudo gitlab-ctl tail gitlab-rails
uid 唯一lowercase_usernames: trueuser_filterblock_auto_created_users 阻止如果你愿意,我可以:
只要把你的 LDAP 结构贴出来即可。