前言
通常,公司都会有自己的域控/单点登录,域控/单点登录有利于账号登录权限的把控,多个系统可以连接一套域控/单点登录,用户就比较好管理。像jenkins、gitlab、hubor、rancher等应用都可以对接域控。
LDAP统一授权登录
(1)在/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: '<IP或者域名/>'
port: 389
uid: '<账号>'
bind_dn: 'cn=ran,cn=users,dc=testmf,dc=com'
password: '<密码>'
encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
verify_certificates: true
active_directory: true
allow_username_or_email_login: true
block_auto_created_users: false
base: 'OU=<授权域>,DC=testmf,DC=com'
user_filter: <用户过滤,可选择>
EOS
(2)重启Gitlab
gitlab-ctl restart
(3)测试
访问GitLab登录页,可以发现登录框出现LDAP和Standard页签,在LDAP页签下用ldap账号密码登录.
Gitlab对接单点登录
(1)基于openid_connect的单点登录,在/etc/gitlab/gitlab.rb文本中加入如下内容
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['openid_connect']
gitlab_rails['omniauth_auto_link_user'] = ["openid_connect", "ldap"]
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_providers'] = [
{
name: "openid_connect",
label: "sso", # optional label for login button, defaults to "Openid Connect"
args: {
name: "openid_connect",
scope: ["openid", "profile", "email"],
response_type: "code",
issuer: "<域名>",
client_auth_method: "basic",
discovery: false,
uid_field: "sub",
send_scope_to_token_endpoint: true,
client_options: {
identifier: '<>',
secret: '<>',
jwks_uri: "<域名>/.well-known/jwks.json",
redirect_uri: "<域名>/auth/openid_connect/callback",
authorization_endpoint: "<域名>/authorize",
token_endpoint: "<域名>/token",
userinfo_endpoint: "<域名>/userinfo",
end_session_endpoint: "<域名>/logout"
}
}
}
]
(2)配置自动登录跳转
gitlab_rails['omniauth_auto_sign_in_with_provider‘] = true
(3)配置自动登出
root账号登录–》设置–》通用–》登录限制,找到退出页面URL选项,输入url:<域名>/logout ,点击保存
注:
(1)开启单点登录后,不允许使用账号密码推拉代码,需要改用访问令牌的方式拉取。
(2)一定要保护email字段
常见的故障
(1)Gitlab集成Ldap/单点登录认证登录报错问题
分析:1. 登录时,账号密码先去匹配ldap中的账号密码,账号密码不正确会报这种错;2. 可能是ldap用户邮箱与gitlab用户邮箱不一致导致。3. 身份标识(DN)有问题,该用户不在ldap设置的用户范围内。
参考:
- 官方文档:https://docs.gitlab.com/ee/integration/cas.html