gitlab 接入 openldap、AD

===============================================html

20171009_第2次修改                       ccb_warlockgit

===============================================服務器

 

今天調試gitlab接入AD域控,找了不少資料才解決了問題,在此處作記錄。ide

gitlab有本身的用戶機制,但其也兼容ldap的用戶驗證機制(本質上openldap和AD域控都是基於ldap機制),因爲公司內部的統一帳戶機制正在調整,故須要將gitlab進行配置,試驗下來社區版的gitlab通過修改配置文件後可使用openldap和微軟ad域控做爲其用戶機制。gitlab

 

版本:gitlab 社區版 9.3.4(漢化)ui

gitlab目錄:/etc/gitlabthis

gitlab配置文件:/etc/gitlab/gitlab.rb(社區版初始該文件內容爲空)url


 1、接入openldapspa

1.1 修改配置文件gitlab.rb.net

 在gitlab.rb文件中添加下面配置,其中:

1.host,是搭建的openldap的ip,根據實際狀況修改;

2.uid,能夠配置cn,也能夠配置uid,都能識別(具體爲何沒深刻研究);

3.bind_dn,openldap的管理員帳號,根據實際狀況修改;

4.password,openldap的管理員,根據實際狀況修改;

5.active_directory,彷佛是針對鏈接是不是ad域控的標示,由於這部分是openldap的配置,故爲false;

6.allow_username_or_email_login,用戶登陸是否用戶名和郵箱均可以,方便用戶故配置true;

7.base,用戶列表所在的目錄,由於新增的用戶都在openldap的People下,故這麼配置,根據實際狀況修改;

 1 # 指明服務的地址
 2 external_url = 'http://localhost'
 3 
 4 # 開啓ldap
 5 gitlab_rails['ldap_enabled'] = true
 6 gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' ###! **remember to close this block with 'EOS' below**
 7 main: # 'main' is the GitLab 'provider ID' of this LDAP server
 8      label: 'LDAP'
 9      host: '192.168.6.4'
10      port: 389
11      uid: 'uid'
12      method: 'plain' # "tls" or "ssl" or "plain"
13      bind_dn: 'cn=Manager,dc=abc,dc=cn'
14      password: '123456' 
15      active_directory: false
16      allow_username_or_email_login: true
17      block_auto_created_users: false
18      base: 'ou=People,dc=abc,dc=cn'
19      user_filter: ''
20 EOS

 

1.2 從新加載新配置

# gitlab-ctl reconfigure

運行後最後一行爲「gitlab Reconfigured!」才說明是加載新配置成功,不然就是根據報錯信息找錯誤。

 

1.3 查看是否能正常獲取用戶列表

# gitlab-rake gitlab:ldap:check

正常鏈接的狀況下執行以後能看到用戶的列表

 

1.4 重啓gitlab

# gitlab-ctl restart

 

重啓成功後,gitlab的界面就會變成下面這樣。

 

 openldap的用戶經過「LDAP」頁進入,管理員root經過「標準」頁進入。

 


 

2、接入AD

2.1 修改配置文件gitlab.rb

在gitlab.rb文件中添加下面配置,其中:

1.host,是搭建的微軟域服務器的ip,根據實際狀況修改;

2.uid,必須配sAMAccountName才能識別

3.bind_dn,域服務器的管理員帳號,根據實際狀況修改;

4.password,域服務器的管理員,根據實際狀況修改;

5.active_directory,彷佛是針對鏈接是不是ad域控的標示,由於這部分是域服務器的配置,故爲true;

6.allow_username_or_email_login,用戶登陸是否用戶名和郵箱均可以,方便用戶故配置true;

7.base,用戶列表所在的目錄,由於新增的用戶都在People下(試驗了用戶放在User時gitlab檢測不到用戶,故新建了一個目錄People,並將新建的用戶移入了該目錄下),故這麼配置,根據實際狀況修改;

external_url = 'http://localhost'

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' ###! **remember to close this block with 'EOS' below**
main: # 'main' is the GitLab 'provider ID' of this LDAP server
  label: 'LDAP'
  host: '192.168.6.1'
  port: 389
  uid: 'sAMAccountName'
  method: 'plain' # "tls" or "ssl" or "plain"
  bind_dn: 'cn=Administrator,cn=users,dc=myad,dc=cn'
  password: '123456'
  active_directory: true
  allow_username_or_email_login: true
  block_auto_created_users: false
  base: 'ou=People,dc=myad,dc=cn'
  user_filter: ''
EOS

 

2.2 從新加載新配置

# gitlab-ctl reconfigure

運行後最後一行爲「gitlab Reconfigured!」才說明是加載新配置成功,不然就是根據報錯信息找錯誤。

 

2.3 查看是否能正常獲取用戶列表

# gitlab-rake gitlab:ldap:check

正常鏈接的狀況下執行以後能看到用戶的列表

 

2.4 重啓gitlab

# gitlab-ctl restart

 

重啓成功後,gitlab的界面就會變成下面這樣。

 

 openldap的用戶經過「LDAP」頁進入,管理員root經過「標準」頁進入。

 

2.5 確認該用戶不處於特殊狀態

1.不處於「禁用帳戶」的狀態;

2.不處於「須要首次登陸修改密碼」的狀態;

(處於上面任意一種狀態的帳戶在登陸gitlab時都會報「Cloud not authenticate you from Ldapmain because "Invalid creadentials".」)

 

參考資料:

1.https://my.oschina.net/firxiao/blog/357559

2.https://ssorc.tw/6358

3.https://docs.gitlab.com/ee/administration/auth/ldap.html

相關文章
相關標籤/搜索