gitlab同步AD中的组

2,513 阅读2分钟

简介

网上的gitlab集成ad域控的教程基本上都是只集成了ad中的用户,而依然需要把用户拉到对应群组,查看了gitlab官网的说明是ultimate版本是支持group sync的,即把ad的安全组同步到gitlab的群组,本文在同步用户的基础上进一步同步了组。

1 部署说明

1.1 环境准备

前提:已搭建gitlab-ee(必须是Premium或Ultimate计划)和内部AD域

IP地址操作系统软件版本AD域主机地址
192.168.1.2Centos 7.8gitlab-ee-13.12.1192.168.1.5

1.2 AD中创建用户组

该实例中把用户创建在Coding组织目录下,用户组创建在Groups组织目录下。

将权限分成guest和developer两种,每个Gitlab中的xx群组所对应的AD用户组名称为xx_guest和xx_developer两个组。(实际使用中根据需求创建)

image-20210615163410710.png

1.3 Gitlab配置群组同步

1.3.1 修改配置文件

配置文件/etc/gitlab/gitlab.rb,在集成LDAP登录的基础上再加上group_base和gitlab_rails['ldap_group_sync_worker_cron']两项。

gitlab_rails['ldap_group_sync_worker_cron'] = "*/2 * * * *" # 修改群组同步时间为2分钟
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'AD 认证'
host: '192.168.1.5'
port: 389
uid: 'sAMAccountName'
encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
bind_dn: 'cn=binduser,cn=Users,dc=example,dc=com'        
password: '1qaz@WSX'
verify_certificates: true
active_directory: true
allow_username_or_email_login: true                       
block_auto_created_users: false
base: 'ou=Coding,dc=example,dc=com'          # 用户根组织单元
user_filter: ''				 # 用户筛选		
group_base: 'ou=Groups,dc=example,dc=com'   # 用户组的根目录
EOS

1.3.2 配置生效

[root@mq01 ~]# gitlab-ctl reconfigure

[root@mq01 ~]# gitlab-ctl restart

1.3.3 同步AD中的组到gitlab中的群组

  1. 使用管理员账号登录gitlab,创建一个群组(如java组)后,进入到群组的编辑界面。

  2. 点击设置-LDAP Synchronization。

  3. Sync method项选择LDAP Group cn,LDAP User filter项中可搜索到配置文件中group_base目录下的组,LDAP Access项为所要授予的权限。

image-20210615163423265.png

本例子将AD域中的java_guest和java_developer组同步到Java群组中。

image-20210615163427589.png

2 AD操作说明

2.1 在AD中把用户根据实际需求加入到组中

新建一个用户Developer01,将其加入到Java_Developer组中。

image-20210615163438471.png

image-20210615163441517.png

2.2 测试可用性

该新建用户登录到gitlab中,查看“你的群组“中是否自动加入了指定的群组。

image-20210615163445593.png

2.3 后续使用

如需修改用户权限,如guest修改为developer,直接在AD域中将用户从xx_guest组中删除,加入到xx_developer中即可。

参考文章:docs.gitlab.com/ee/administ…

about.gitlab.com/blog/2014/0…