一. Gitlab LDAP
1.1 Gitlab配置
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'AD', # Gitlab AD認(rèn)證界面的標(biāo)簽
'host' => '192.168.10.10', # DC 服務(wù)器地址
'port' => 389,
'uid' => 'sAMAccountName', # Gitlab使用登錄域用戶屬性
'encryption' => 'plain', # AD DC 認(rèn)證傳輸?shù)募用芊椒?
'bind_dn' => 'CN=admin,CN=Users,DC=test,DC=io', #綁定管理員的dn
'password' => '12345678', # 管理員密碼
'allow_username_or_email_login': true, # 允許用戶使用@的方式登錄
'block_auto_created_users': true, # 新建用戶首次登錄Gitlab是否被鎖定
'active_directory' => true, # 此設(shè)置指定LDAP服務(wù)器是否為AD服務(wù)器
'base' => 'OU=test,DC=test,DC=io', # 搜索指定組織下的用戶
'user_filter' =>'memberOf=CN=GITLAB_USERS,CN=Users,DC=test,DC=io' # 過濾LDAP用戶
}
}
[root@localhost ~]# gitlab-ctl reconfigure
檢查測(cè)試ldap配置
[root@localhost ~]# gitlab-rake gitlab:ldap:check
如果從LDAP服務(wù)器中刪除了用戶蛋褥,則該用戶也會(huì)在GitLab中被阻止桨菜。用戶將立即被阻止登錄源哩。但是厘线,LDAP檢查緩存時(shí)間為一小時(shí)(請(qǐng)參閱注釋)鸳惯,這意味著已經(jīng)登錄或通過SSH使用Git的用戶仍然可以訪問GitLab最多一個(gè)小時(shí)商蕴。在GitLab管理區(qū)域中手動(dòng)阻止用戶以立即阻止所有訪問。
1.2 Gitlab EE
- GitLab每天運(yùn)行一次芝发,默認(rèn)情況下绪商,GitLab將在服務(wù)器時(shí)間上午01:30每天運(yùn)行一次worker,以根據(jù)LDAP檢查和更新GitLab用戶辅鲸。
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['ldap_sync_worker_cron'] = "30 1 * * *"
- 運(yùn)行群組同步
[root@localhost ~]# gitlab-rake gitlab:ldap:group_sync
1.3 Gitlab賬號(hào)與AD賬號(hào)
在集成AD后格郁,為了兼容前期Gitlab創(chuàng)建的用戶賬號(hào),在創(chuàng)建AD用戶賬號(hào)時(shí)只需保證sAMAccountName独悴,email屬性與Gitlab用戶的Username例书、電子郵箱的值一致即可(密碼可以不同),使用這種方式創(chuàng)建的AD賬戶登錄Gitlab時(shí)Gitlab不會(huì)創(chuàng)建新用戶刻炒。
二. JumpServer LDAP
-
后臺(tái)LDAP設(shè)置
LDAP地址
ldap://192.168.10.10:389
綁定DN
cn=admin,cn=Users,dc=test,dc=com
用戶OU
ou=jumpserver,dc=test,dc=com
用戶過濾器
(sAMAccountName=%(user)s)
LADP屬性映射
{"username": "sAMAccountName", "name": "sn", "email": "mail"}
啟動(dòng)LDAP認(rèn)證
? 修改配置文件
[root@localhost ~]# vim /opt/jumpserver/config.yml
# LDAP/AD settings
# LDAP 搜索分頁數(shù)量
#AUTH_LDAP_SEARCH_PAGED_SIZE: 1000
#
# 定時(shí)同步用戶
# 啟用 / 禁用
AUTH_LDAP_SYNC_IS_PERIODIC: True
# 同步間隔 (單位: 時(shí)) (優(yōu)先)
#AUTH_LDAP_SYNC_INTERVAL: 12
# Crontab 表達(dá)式决采,每隔半個(gè)小時(shí)同步一次
AUTH_LDAP_SYNC_CRONTAB: "*/30 * * * *"
#
# LDAP 用戶登錄時(shí)僅允許在用戶列表中的用戶執(zhí)行 LDAP Server 認(rèn)證
AUTH_LDAP_USER_LOGIN_ONLY_IN_USERS: True
#
# LDAP 認(rèn)證時(shí)如果日志中出現(xiàn)以下信息將參數(shù)設(shè)置為 0 (詳情參見:https://www.python-ldap.org/en/latest/faq.html)
# In order to perform this operation a successful bind must be completed on the connection
#AUTH_LDAP_OPTIONS_OPT_REFERRALS: -1
三. Nginx LDAP
3.1 編譯安裝Nginx
- 下載Nginx源碼包
[root@NGINX_LDAP home]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
- 安裝編譯nginx依賴包
[root@NGINX_LDAP home]# yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel openldap-devel
- 解壓nginx包
[root@NGINX_LDAP home]# tar zxvf nginx-1.18.0.tar.gz
- 克隆nginx第三方模塊
[root@NGINX_LDAP home]# git clone https://github.com/kvspb/nginx-auth-ldap.git
- 配置
[root@NGINX_LDAP nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --add-module=/home/nginx-auth-ldap
- 編譯安裝
[root@NGINX_LDAP nginx-1.18.0]# make && make install
- 修改nginx.conf
[root@NGINX_LDAP conf]# cat /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# define ldap server
ldap_server ad_1 {
# user search base.
url "ldap://192.168.10.10:3268/DC=test,DC=com?sAMAccountName?sub?(objectClass=person)";
# bind as
binddn "test\\admin";
# bind pw
binddn_passwd "12345678";
# group attribute name which contains member object
group_attribute member;
# search for full DN in member object
group_attribute_is_dn on;
# matching algorithm (any / all)
satisfy any;
# list of allowed groups
require group "CN=Nginx登錄,OU=權(quán)限組,DC=test,DC=com";
# list of allowed users
# require 'valid_user' cannot be used together with 'user' as valid user is a superset
# require valid_user;
#require user "CN=Batman,OU=Users,OU=New York Office,OU=Offices,DC=company,DC=com";
#require user "CN=Robocop,OU=Users,OU=New York Office,OU=Offices,DC=company,DC=com";
}
server {
listen 80;
server_name localhost;
location / {
# adding ldap authentication
auth_ldap "Closed content";
auth_ldap_servers ad_1;
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
四.Nginx-proxy-ldap-manager
Nginx Proxy Manager是一個(gè)基于MIT協(xié)議的開源項(xiàng)目,這個(gè)項(xiàng)目實(shí)現(xiàn)了通過web界面管理控制一些Nignx常用的功能坟奥,比如重定向树瞭、反向代理、404爱谁、甚至提供了免費(fèi)的SSL晒喷,Nginx-proxy-ldap-manager在Nginx Proxy Manager的基礎(chǔ)上添加了nginx-auth-ldap認(rèn)證模塊。
4.1 安裝
管理界面端口: 81
默認(rèn)管理員密碼:
Email: admin@example.com
Password: changeme
4.2 配置AD認(rèn)證
- 配置nginx.conf
####################################################
# Ldap group:Nginx1
ldap_server ad_1 {
url "ldap://172.16.10.10:3268/DC=test,DC=com?sAMAccountName?sub?(objectClass=person)";
binddn "test\\admin";
binddn_passwd "password";
group_attribute member;
group_attribute_is_dn on;
satisfy any;
require group "CN=Nginx1,OU=Nginx-proxy,DC=test,DC=com";
}
# Ldap group:Nginx2
ldap_server ad_2 {
url "ldap://172.16.10.10:3268/DC=test,DC=io?sAMAccountName?sub?(objectClass=person)";
binddn "test\\admin";
binddn_passwd "password";
group_attribute member;
group_attribute_is_dn on;
satisfy any;
require group "CN=Nginx2,OU=Nginx-proxy,DC=test,DC=com";
}
#####################################################
- 配置反向代理
使用AD認(rèn)證時(shí)才配置Advanced管行,auth_ldap_servers值與nginx.conf文件中的ldap_server值對(duì)應(yīng)
五. Rancher LDAP
六. Openvpn LDAP
六. 參考
【1】How to configure LDAP with GitLab CE
【2】General LDAP Setup
【3】nginx-auth-ldap
【4】LDAP 認(rèn)證
【5】nginx-proxy-ldap-manager