LDAP」カテゴリーアーカイブ




GitLabにLDAP連携して認証方法を追加する手順




投稿日:

前回、GitLabをインストールしました。

【シンプル】CentOS6にGitLabを簡単にインストールして起動するまで | 田舎に住みたいエンジニアの日記

これから色々とやりたいことがあるので順にやっていきましょう。今回は認証連携としてLDAP連携を進めます。


LDAP連携のための設定

設定は簡単です。/etc/gitlab/gitlab.rbで設定します。

変更前
[html]
vi /etc/gitlab/gitlab.rb

# 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
# base: ”
# user_filter: ”
# ## EE only
# group_base: ”
# admin_group: ”
# sync_ssh_keys: false
[/html]


デフォルト設定を以下のように変更していきます。
[html]
vi /etc/gitlab/gitlab.rb

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: ‘LDAP-server’
port: 389
uid: ‘uid’
method: ‘plain’ # "tls" or "ssl" or "plain"
bind_dn: ‘cn=Manager,dc=xxxx,dc=xxx’
password: ‘xxxxxxxx’
# active_directory: true
# allow_username_or_email_login: false
base: ‘ou=Users,dc=xxxx,dc=xxx’

EOS
[/html]

これで、リロードすれば、LDAP認証のログイン画面が表示され、LDAPアカウトでも認証できるようになります。しかし、この状態ではメールアドレスがおかしくなる状態になりました。

参照 GitLab CE Omnibus のインストール – ダメ出し Blog

LDAP側でメール情報を持っていないと、メールアドレスが
LDAP のユーザーが初めてログインすると、ユーザーの LDAP エントリーのうち mail、email、userPrincipalName 属性のいずれかの値が E-mail アドレスとして利用されるが、いずれの属性も持たない場合は temp-email-for-oauth-<ユーザー名>@gitlab.localhost になってしまう。 また、この情報は管理者しか変更できない。

この状態になったので、参照先の対応を実施します。ありがとうございます。

[html]vi /opt/gitlab/embedded/service/gitlab-rails/config/initializers/local.rb

module Gitlab
module OAuth
class AuthHash
def generate_temporarily_email
"#{username}@yourdamain.jp"
end
end
end
end
[/html]

これでリロードして無事メールアドレスも表示されるようになりました。

[amazonjs asin=”4774165751″ locale=”JP” title=”15時間でわかるGit集中講座”]