[系統部署] 使用 AD 帳號登入 Gitlab

紀錄如何使用 AD 帳號來登入 Gitlab Server
>CN屬性
屬性名稱 全名 說明
CN Common Name 用戶名稱、單位名稱
DN Distinguished Name 識別名稱,絕對位置
OU Organizational Unit Name 組織單位名稱
DC Domain Componet 網域元件

設定方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
gitlab_rails['ldap_enabled'] = true

###! **remember to close this block with 'EOS' below**
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'LDAP'
host: 'IP'
port: 389 #389 為非加密port 636為(LDAPS)有加密port
uid: 'sAMAccountName'
bind_dn: 'CN=Administrator,CN=Users,DC=test,DC=com'
password: 'password'
encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
verify_certificates: true
smartcard_auth: false
active_directory: true
allow_username_or_email_login: false #可以讓使用者使用 名稱 或 email 帳號登入
lowercase_usernames: true
block_auto_created_users: true # 如果 true ,就會讓第一次登入的
# 使用者看到 Your account is blocked.
# Retry when an admin has unblocked it.
# 它需要管理者解除才行
base: 'OU=PRD,OU=TW,DC=test,DC=com '
EOS

ps:設定的帳號只需要一般的user權限,不需要很高的權限

設定與LDAP同步時間 預設為早上1點30分

1
2
3
4
5
/etc/gitlab/gitlab.rb  
.
.
.
gitlab_rails['ldap_sync_worker_cron'] = "0 */12(2) * * *"
1
2
3
4
5
6
7
8
config/gitlab.yaml
.
.
.
.
cron_jobs:
ldap_sync_worker_cron
: "0 */12(30) * * *"

參考資料
https://docs.gitlab.com/ee/administration/auth/ldap/