我々は、部分的にLDAPに関するその 認証メカニズムを変更する必要があるような場合にGitlab作業を行うために
へのパッチ適用
。
まず、omniauth-ldapモジュールをthis派生に置き換えます。
sudo -u git -H bundle install --without development test mysql --path vendor/bundle --no-deployment
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-ldap
でlib/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))'
これは私の会社では機能しません。匿名バインドや検索の権限が設定されていないからです。 gitlabはバインドできず、提供されたユーザーの存在を確認できません(gitlabがこのプログラムステップで完全なbind_dnを取得しようとしている限り)。 – Bubu
次に、ログインしようとしているユーザーのBind-DNを検索するためにLDAPにバインドする特権を持つユーザーが必要です。匿名検索が有効になっていない場合は回避できません。ごめんなさい。 – heiglandreas
しかし、もし私が既にそれを知っていれば、バインドDNを検索したいのですが?例えば。ユーザー[email protected]がログインしようとしています。私は、バインドDNは "uid = test.example.com、ou = people、dc = example、dc = com"のようなものであることを知っています - Gitlabはこれをデフォルトで任意に悪用し、最初のバインド。なぜこれがデフォルトのLDAP認証戦略ではないのかわかりません。 – Bubu