编辑gitlab.rb文件

sudo vi /etc/gitlab/gitlab.rb

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

编辑以下内容:

 

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服务端口
uid: 'cn'        #默认sAMAccountName 这边配置为cn 如果要使用中文登录时就使用默认配置
method: 'plain' # "tls" or "ssl" or "plain"
bind_dn: 'cn=administrator,cn=users,dc=xxx,dc=com' #指定ldap服务器的管理员信息即bin_dn
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: ''  #用户登录权限控制,格式为LDAP查询条件,我这里是按用户组进行控制
attributes:
username: ['cn', 'uid']
email: ['mail', 'email']
EOS

  

 

内容添加完成之后,需要使用gitlab-ctl reconfigure进行配置重置,同时使用gitlab-ctl restart重启服务即可

检查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

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄