在 Linux 上部署的 GitLab 集成 LDAP 主要用于统一账号登录(认证),常见场景是接入 OpenLDAP / Active Directory。下面按通用做法 + 示例配置 + 常见问题来说明。
GitLab 支持:
GitLab CE / EE 都支持 LDAP
EE 还支持 LDAP 群组同步(Group Sync)
GitLab 的 LDAP 配置在:
/etc/gitlab/gitlab.rb
sudo vim /etc/gitlab/gitlab.rb
| 项目 | 值 |
|---|---|
| LDAP 服务器 | ldap://192.168.1.10 |
| 端口 | 389 |
| Base DN | dc=example,dc=com |
| Bind DN | cn=admin,dc=example,dc=com |
| 用户登录属性 | uid |
| 用户 DN | ou=people,dc=example,dc=com |
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main:
label: 'LDAP'
host: '192.168.1.10'
port: 389
uid: 'uid'
bind_dn: 'cn=admin,dc=example,dc=com'
password: 'ldap_admin_password'
encryption: 'plain'
base: 'dc=example,dc=com'
user_filter: ''
EOS
sudo gitlab-ctl reconfigure
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main:
label: 'AD'
host: 'ad.example.com'
port: 389
uid: 'sAMAccountName'
bind_dn: 'cn=gitlab,ou=service,dc=example,dc=com'
password: 'password'
encryption: 'plain'
base: 'dc=example,dc=com'
user_filter: ''
EOS
✅ AD 常用 uid:
sAMAccountName(推荐)userPrincipalName port: 636
encryption: 'simple_tls'
或 StartTLS:
port: 389
encryption: 'start_tls'
sudo gitlab-rake gitlab:ldap:check
输出示例:
Checking LDAP ...
Server: ldapmain
LDAP authentication... Success
LDAP users with access to your GitLab server (only showing first 100 results)
访问 GitLab:
http://gitlab.example.com
登录界面会出现 LDAP 登录选项
使用 LDAP 中的用户名和密码登录
| 行为 | 说明 |
|---|---|
| 首次登录 | 自动创建 GitLab 用户 |
| 用户名 | 来自 LDAP uid |
| 邮箱 | 来自 LDAP mail |
| 密码 | 始终由 LDAP 验证 |
✅ GitLab 不会存储 LDAP 密码
只允许某个组:
user_filter: '(memberOf=cn=gitlab-users,ou=groups,dc=example,dc=com)'
gitlab_rails['gitlab_signin_enabled'] = false
ldap_servers:
main:
group_base: 'ou=groups,dc=example,dc=com'
admin_group: 'gitlab-admins'
sudo gitlab-ctl tail | grep ldap
检查:
确认 LDAP 中存在:
mailcnsn安装 GitLab
↓
配置 /etc/gitlab/gitlab.rb
↓
gitlab-ctl reconfigure
↓
gitlab-rake gitlab:ldap:check
↓
Web 登录测试
如果你愿意,我可以帮你:
✅ 针对 OpenLDAP / AD / FreeIPA 写完整配置
✅ 排查你当前的 gitlab.rb
✅ 配置 LDAP + 群组同步 + 权限控制
只要把你的 LDAP 类型 + 示例结构发我即可。