gitlab用户登录与AD域用户集成

---恢复内容开始---

编辑gitlab.rb文件

sudo vi /etc/gitlab/gitlab.rb

下图是我编辑的内容示例(仅供参考):

 

编辑以下内容:

gitlab_rails['ldap_enabled'] = true

gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'LDAP'
host: 'xxx.xxx.xxx.xxx'  #指定ldap服务器地址
port: 389        #默认情况下,LDAP服务在TCP和UDP端口389上侦听连接。LDAPS(基于SSL的LDAP)在端口636侦听。
uid: 'cn'        #默认SamAccountName 如果要使用中文登录时就使用默认配置SamAccountName,英文登录为cn
method: 'plain' # "tls" or "ssl" or "plain"
bind_dn: 'cn=administrator,cn=users,dc=xxx,dc=com' #指定ldap服务器的管理员信息即cn=账户,cn=组织单位
password: 'xxx'         #指定ldap服务器的管理员密码
active_directory: true
allow_username_or_email_login: true #是否允许用户名或者email登录,true即允许。如果此处用户要使用ldap中的mail进行登录,则mail地址必须为"用户名@xxx.com",否则无法登录。
block_auto_created_users: false
base: 'dc=xxx,dc=com' #指定ldap服务器的base域

user_filter: 'memberOf=CN=gituser,OU=Groups,OU=UsersAndGroups,DC=EXAMPLE,DC=com'  #用户登录权限控制,格式为LDAP查询条件,示例按用户组进行控制
attributes:
username: ['cn', 'uid']
email: ['mail', 'email']
EOS

常见的组合是encryption: 'plain'port: 389,或 encryption: 'simple_tls'port: 636

官网文档:https://docs.gitlab.com/ee/administration/auth/how_to_configure_ldap_gitlab_ce/#how-to-configure-ldap-with-gitlab-ce

内容编辑完成之后,需要使用命令配置重置

gitlab-ctl reconfigure

重启服务

gitlab-ctl restart

测试获取AD域用户列表:

sudo gitlab-rake gitlab:ldap:check

问题: 
其他集成的系统使用AD账号都无认证错误的问题,只有Gitlab认证时,提示报错:Invalid credentials

 注:

1、检查了一下这个配置文件和里边用的AD信息都正常,没有什么问题,为什么登录时,就是会报错呢,无意之间测试了一个英文账户(cn和SamaccountName)都是英文字母的,发现他能认证成功,这时候我就觉得这个集成没有问题,应该是哪里的么有配置正确。
通过在AD中查看一个中文账户和英文账户的却别,发现两者区别在于cn这个属性上,英文账户的cn属性和SamaccountName属性是一模一样的,但是中文的两个不一样,中文的cn是中文显示名,SamaccountName是登录账号。
于是用了一个中文名字去认证登录,发现通过了,能够正常通过。再返回去查看gitlab.rb配置文件,这时注意到 “uid: ‘cn’”这个配置,此命令式说调用AD中CN属性值作为Gitlab登录账户,当AD中都是英文账户时,这个命令是没有问题的,但是当存在中文账户时,需要改为uid:‘SamAccountName’,这样账户就改为了AD一样的登录账号。

2、还有一个就是bind_dn: 'cn=administrator,cn=users,dc=xxx,dc=com'这个属性没有加cn=users这个组织单位,导致报错

我搭建环境的时候没有配置邮箱,以下内容仅供参考

配置邮箱
配置文件/etc/gitlab/gitlab.rb,配置完成之后需要gitlab-ctl reconfigure 和 gitlab-ctl restart
QQ exmail (腾讯企业邮箱)配置如下,

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
gitlab_rails['smtp_domain'] = "exmail.qq.com"

 

更多邮箱配置示例:

https://docs.gitlab.com/omnibus/settings/smtp.html
posted @ 2019-04-15 15:21  幸运球与倒霉蛋  阅读(7304)  评论(0编辑  收藏  举报