本サイトでは、アフィリエイト広告およびGoogleアドセンスを利用しています。

Gitlab (7.13.1) でユーザー認証に LDAP を使う

タイトルの通りですが、認証に LDAP というか Active Directory を使えるかどうかを試してみました。Enterprise Edition だと間違いなく LDAP の機能を備えているのですが、 Community Edition でもこの機能が使えるかどうかがとても気になりました。

LDAPを使うように設定する

WebUI の画面からは設定することが不可能でした。
そこで、設定ファイルを編集して LDAP 認証を有効化します。

/etc/gitlab/gitlab.rb ファイルがあるのでこれを適当なエディタで開きます。すると以下のような行が見つかるので、この部分を編集していきます。

## For setting up LDAP
## see https://gitlab.com/gitlab-org/omnibus-gitlab/blob/629def0a7a26e7c2326566f0758d4a27857b52a3/README.md#setting-up-ldap-sign-in
## Be careful not to break the identation in the ldap_servers block. It is in
## yaml format and the spaces must be retained. Using tabs will not work.

# gitlab_rails['ldap_enabled'] = false
# 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: '_your_ldap_server'
#     port: 389
#     uid: 'sAMAccountName'
#     method: 'plain' # "tls" or "ssl" or "plain"
#     bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
#     password: '_the_password_of_the_bind_user'
#     active_directory: true
#     allow_username_or_email_login: false
#     block_auto_created_users: false
#     base: ''
#     user_filter: ''
#     ## EE only
#     group_base: ''
#     admin_group: ''
#     sync_ssh_keys: false

先頭の # がコメントの意味なので必要な部分をコメントから外します。このとき、後続の EOS の行もコメントになっているので外します。忘れがちなので注意します。この部分を見ると GitLab は2つめの LDAP サーバーを設定できるようですね。
コメントを外したら各項目を設定します。

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' 
  main: 
    label: 'LDAP'
    host: 'LDAPサーバーのIPアドレス'
    port: 389
    uid: 'sAMAccountName'
    method: 'plain' # "tls" or "ssl" or "plain"
    bind_dn: 'LDAP検索用のユーザー. user@mydomain.co.jp的なものを設定'
    password: 'LDAP検索用のユーザーのパスワード'
    active_directory: true
    allow_username_or_email_login: false
    block_auto_created_users: false
    base: 'dc=mydomain,dc=co,dc=jpのようなベース'
    user_filter: ''
#     ## EE only
#     group_base: ''
#     admin_group: ''
#     sync_ssh_keys: false
# (一部省略)
EOS

設定したら、 reconfigureを実行します。
# gitlab-ctl stop
# gitlab-ctl reconfigure
# gitlab-ctl start

Webブラウザでアクセスして、再びログイン画面を開いてみます。するとログイン入力する箇所で以下のように変更されているかと思います。つまりこの画面にならなかったら、まず LDAP が有効化されていないので、設定を見直す必要があります。

gitlab-signin-ldap-7_13_1

当たり前ですが、ログインユーザーの種別に応じたタブでサインインしないと認証が通らないようです。

まとめ

LDAP (Active Directory) が認証に使えることがわかり、やりたいことの1つがクリアできました。Enterprise版だけの機能かと内心思っていただけに使うことが出来てよかったです。

サーバー構築
すらりんをフォローする
すらりん日記

コメント

タイトルとURLをコピーしました