2013-03-10 14 views
8

私たちの会社のLDAPをデモとしてGitlabを設定したいと思います。しかし残念ながらgitlab.ymlに管理者パスワードを入れてgitlabがLDAPサービスにアクセスするようにしなければなりません。 Gitlabのためだけに別のアカウントを設定したくないので、問題は管理です。自分のパスワードを入力せずにこれを回避する方法はありますか? Gitlabに提供されたユーザ証明書だけでLDAP接続を確立させる方法はありますか?gitlabを特別なgitlabユーザなしで設定する

匿名としてログインする以外のアイデアはありますか?

既に投稿されましたhere

答えて

9

まだ試したことはありませんが、LDAPと匿名バインドをサポートしていないLDAPの設定ファイルからの情報は、検索する。

だから、私はbind_dnpasswordの2つのエントリをコメントアウトして、動作するかどうかを試してみる。

UPDATE

私はGitlabにLDAP-Autehnticationを実装しましたし、それはかなり簡単です。

gitlab.yml-ファイルには、ldapというセクションがあります。

LDAPに接続するための情報を入力する必要があります。すべてのフィールドを指定する必要があるようだが、フォールバックのデフォルトはないようだ。ユーザーDNの取得に匿名バインドを使用する場合は、bind_dnpasswordの空の文字列を指定します。それらをコメントアウトすることはうまくいかないようです!少なくとも501エラーメッセージが表示されます。

詳しい情報はhttps://github.com/patthoyts/gitlabhq/wiki/Setting-up-ldap-authと(より時代遅れしかしまだ有用)で見つけることができますhttps://github.com/intridea/omniauth-ldap

+0

これは私の会社では機能しません。匿名バインドや検索の権限が設定されていないからです。 gitlabはバインドできず、提供されたユーザーの存在を確認できません(gitlabがこのプログラムステップで完全なbind_dnを取得しようとしている限り)。 – Bubu

+0

次に、ログインしようとしているユーザーのBind-DNを検索するためにLDAPにバインドする特権を持つユーザーが必要です。匿名検索が有効になっていない場合は回避できません。ごめんなさい。 – heiglandreas

+0

しかし、もし私が既にそれを知っていれば、バインドDNを検索したいのですが?例えば。ユーザー[email protected]がログインしようとしています。私は、バインドDNは "uid = test.example.com、ou = people、dc = example、dc = com"のようなものであることを知っています - Gitlabはこれをデフォルトで任意に悪用し、最初のバインド。なぜこれがデフォルトのLDAP認証戦略ではないのかわかりません。 – Bubu

1

GitLabは、複数のログインソース(LDAPを含む)を管理するために、omniauthを使用します。

LDAP接続を別の方法で管理するために何とかomniauthを拡張できれば、別のソースからパスワードを取得できます。
これは、上記のパスワードをldap section of the gitlab.yml config fileに保存しないようにします。

+0

私の最初をされている我々がgitlab/lib/gitlab/ldap/access.rb にパッチを適用、このメカニズムを無効にするには

アイデアはここからどこへ行くのですか?私は本当にルビーのものではありません。私は[this](https://gist.github.com/mgrobelin/3953472)を見つけました。最初のバインドを使用していないようだから、とても有望です。他のヒントがありますか?どこを掘るのですか? – Bubu

+0

@Bubu今は他のヒントはありません。あなたが見いだしたのは、オムニバスを拡張する素晴らしい例のようです。これはまさに私が示唆しているものです。 – VonC

+0

これはこれまでにこれを稼働させましたか?私は同じことをしようとしている。 – orodbhen

3

私はこのように動作するgitlabをパッチを適用してhttp://foivos.zakkak.net/tutorials/gitlab_ldap_auth_without_querying_account.html

にプロセスを文書化している私は臆面もなく自分のために、ここでの指示をコピー-完全。

注::このチュートリアルは、ソースからインストールされたgitlab 8.2で最後にテストされました。

このチュートリアルでは、Gitlabのインストールを に変更する方法を説明し、ユーザーの資格情報を使用してLDAPサーバーで認証する方法を説明します。 デフォルトGitlabは、 が自分の資格情報で彼女を認証する前に、匿名バインドまたはユーザー のユーザーにLDAPサーバーに問い合わせることを依頼します。ただし、セキュリティ上の理由から、 は、匿名バインドを無効にし、 LDAPユーザーを照会することを禁止しています。 CN=username,OU=Users,OU=division,OU=department,DC=example,DC=com:。私たちは でgitlab.example.comとldap.example.com上で実行されているLDAPサーバーをgitlabを設定している、と ユーザは、次の形式のDNを持っていることを前提とし、このチュートリアルで

我々は、部分的にLDAPに関するその 認証メカニズムを変更する必要があるような場合にGitlab作業を行うために

へのパッチ適用

まず、omniauth-ldapモジュールをthis派生に置き換えます。

  1. sudo -u git -H bundle install --without development test mysql --path vendor/bundle --no-deployment
  2. sudo -u git -H bundle install --deployment --without development test mysql aws

これらのコマンドは、フェッチします:

diff --git a/Gemfile b/Gemfile 
index 1171eeb..f25bc60 100644 
--- a/Gemfile 
+++ b/Gemfile 
@@ -44,4 +44,5 @@ gem 'gitlab-grack', '~> 2.0.2', require: 'grack' 
# LDAP Auth 
# GitLab fork with several improvements to original library. For full list of changes 
# see https://github.com/intridea/omniauth-ldap/compare/master...gitlabhq:master 
-gem 'gitlab_omniauth-ldap', '1.2.1', require: "omniauth-ldap" 
+#gem 'gitlab_omniauth-ldap', '1.2.1', require: "omniauth-ldap" 
+gem 'gitlab_omniauth-ldap', :git => 'https://github.com/zakkak/omniauth-ldap.git', require: 'net-ldap', require: "omniauth-ldap" 

今、私たちは次のアクションを実行する必要があります。 に我々はgitlab/Gemfileに以下のパッチを適用し、これを達成修正されたomniauth-ldapモジュールは gitlab/vendor/bundle/ruby/2.x.x/bundler/gemsです。モジュールが にフェッチされたので、LDAPサーバーが期待するDNを使用するようにモジュールを変更する必要があります。 gitlabはLDAP サーバーにバインドし、それを照会し、同様に、ユーザー自身を認証するためにユーザーの資格情報を使用して、このモジュールで

diff --git a/lib/omniauth/strategies/ldap.rb b/lib/omniauth/strategies/ldap.rb 
index 9ea62b4..da5e648 100644 
--- a/lib/omniauth/strategies/ldap.rb 
+++ b/lib/omniauth/strategies/ldap.rb 
@@ -39,7 +39,7 @@ module OmniAuth 
     return fail!(:missing_credentials) if missing_credentials? 

     # The HACK! FIXME: do it in a more generic/configurable way 
-  @options[:bind_dn] = "CN=#{request['username']},OU=Test,DC=my,DC=example,DC=com" 
+  @options[:bind_dn] = "CN=#{request['username']},OU=Users,OU=division,OU=department,DC=example,DC=com" 
     @options[:password] = request['password'] 
     @adaptor = OmniAuth::LDAP::Adaptor.new @options 

:私たちは、と gitlab/vendor/bundle/ruby/2.x.x/bundler/gems/omniauth-ldaplib/omniauth/strategies/ldap.rbにパッチを適用することによって、これを達成 。

これは、で の認証にユーザーがsshキーを使用しない限り機能します。 デフォルトでGitlabによってsshキーを介して認証する場合、 対応ユーザーが有効なユーザーであるかどうかを調べるためにLDAPサーバーに照会します。この時点で、 は、ユーザー がLDAPサーバーを照会するためにユーザー資格情報を使用できませんでした。その結果、 は本質的に登録されたsshキーを持つユーザーを許可しますが、 LDAPサーバーからはまだGitlabセットアップを使用することができません。 のユーザーがGitlab設定を引き続き使用できないようにするには、設定の任意のアカウントから手動で のsshキーを削除する必要があります。gitlab.yml使用で

diff --git a/lib/gitlab/ldap/access.rb b/lib/gitlab/ldap/access.rb 
index 16ff03c..9ebaeb6 100644 
--- a/lib/gitlab/ldap/access.rb 
+++ b/lib/gitlab/ldap/access.rb 
@@ -14,15 +14,16 @@ module Gitlab 
     end 

     def self.allowed?(user) 
-  self.open(user) do |access| 
-   if access.allowed? 
-   user.last_credential_check_at = Time.now 
-   user.save 
-   true 
-   else 
-   false 
-   end 
-  end 
+  true 
+  # self.open(user) do |access| 
+  # if access.allowed? 
+  #  user.last_credential_check_at = Time.now 
+  #  user.save 
+  #  true 
+  # else 
+  #  false 
+  # end 
+  # end 
     end 

     def initialize(user, adapter=nil) 
@@ -32,20 +33,21 @@ module Gitlab 
     end 

def allowed? 
-  if Gitlab::LDAP::Person.find_by_dn(user.ldap_identity.extern_uid, adapter) 
-   return true unless ldap_config.active_directory 
+  true 
+  # if Gitlab::LDAP::Person.find_by_dn(user.ldap_identity.extern_uid, adapter) 
+  # return true unless ldap_config.active_directory 

-   # Block user in GitLab if he/she was blocked in AD 
-   if Gitlab::LDAP::Person.disabled_via_active_directory?(user.ldap_identity.extern_uid, adapter) 
-   user.block unless user.blocked? 
-   false 
-   else 
-   user.activate if user.blocked? && !ldap_config.block_auto_created_users 
-   true 
-   end 
-  else 
-   false 
-  end 
+  # # Block user in GitLab if he/she was blocked in AD 
+  # if Gitlab::LDAP::Person.disabled_via_active_directory?(user.ldap_identity.extern_uid, adapter) 
+  #  user.block unless user.blocked? 
+  #  false 
+  # else 
+  #  user.activate if user.blocked? && !ldap_config.block_auto_created_users 
+  #  true 
+  # end 
+  # else 
+  # false 
+  # end 
rescue 
false 
end 

設定

次のようなもの(あなたのニーズに変更):

# 
# 2. Auth settings 
# ========================== 

## LDAP settings 
# You can inspect a sample of the LDAP users with login access by running: 
# bundle exec rake gitlab:ldap:check RAILS_ENV=production 
ldap: 
    enabled: true 
    servers: 
    ########################################################################## 
    # 
    # Since GitLab 7.4, LDAP servers get ID's (below the ID is 'main'). GitLab 
    # Enterprise Edition now supports connecting to multiple LDAP servers. 
    # 
    # If you are updating from the old (pre-7.4) syntax, you MUST give your 
    # old server the ID 'main'. 
    # 
    ########################################################################## 
    main: # 'main' is the GitLab 'provider ID' of this LDAP server 
     ## label 
     # 
     # A human-friendly name for your LDAP server. It is OK to change the label later, 
     # for instance if you find out it is too large to fit on the web page. 
     # 
     # Example: 'Paris' or 'Acme, Ltd.' 
     label: 'LDAP_EXAMPLE_COM' 

     host: ldap.example.com 
     port: 636 
     uid: 'sAMAccountName' 
     method: 'ssl' # "tls" or "ssl" or "plain" 
     bind_dn: '' 
     password: '' 

     # This setting specifies if LDAP server is Active Directory LDAP server. 
     # For non AD servers it skips the AD specific queries. 
     # If your LDAP server is not AD, set this to false. 
     active_directory: true 

     # If allow_username_or_email_login is enabled, GitLab will ignore everything 
     # after the first '@' in the LDAP username submitted by the user on login. 
     # 
     # Example: 
     # - the user enters '[email protected]' and '[email protected]' as LDAP credentials; 
     # - GitLab queries the LDAP server with 'jane.doe' and '[email protected]'. 
     # 
     # If you are using "uid: 'userPrincipalName'" on ActiveDirectory you need to 
     # disable this setting, because the userPrincipalName contains an '@'. 
     allow_username_or_email_login: false 

     # To maintain tight control over the number of active users on your GitLab installation, 
     # enable this setting to keep new users blocked until they have been cleared by the admin 
     # (default: false). 
     block_auto_created_users: false 

     # Base where we can search for users 
     # 
     # Ex. ou=People,dc=gitlab,dc=example 
     # 
     base: 'OU=Users,OU=division,OU=department,DC=example,DC=com' 

     # Filter LDAP users 
     # 
     # Format: RFC 4515 http://tools.ietf.org/search/rfc4515 
     # Ex. (employeeType=developer) 
     # 
     # Note: GitLab does not support omniauth-ldap's custom filter syntax. 
     # 
     user_filter: '(&(objectclass=user)(objectclass=person))' 
関連する問題