我想用我们公司的LDAP作为演示来设置Gitlab.但不幸的是,我必须在gitlab.yml中输入一个管理员密码,以使gitlab访问LDAP服务.问题实际上是管理,因为他们不想仅为Gitlab设置另一个帐户.有没有办法在不填写我自己的密码的情况下绕过这个?有没有办法让Gitlab只使用提供的用户凭证建立LDAP连接?
除了以匿名方式登录之外的任何想法?
已经发布在这里.
我还没有尝试过,但从我迄今为止构建的对LDAP和来自配置文件的信息进行身份验证的事情,当LDAP不支持匿名绑定和搜索时,似乎只需要这个用户帐户.
所以我会留下两个条目bind_dn并password注释掉并尝试它是否有效.
UPDATE
我在Gitlab中实现了LDAP-Autehntication,这很容易.
在gitlab.yml-file中有一个名为的部分ldap.
在那里,您必须提供连接到LDAP的信息.似乎所有领域都必须给出,似乎没有后备默认!如果要使用匿名绑定来检索用户DN,请为bind_dn 和提供空字符串password.评论他们似乎不起作用!至少我收到了501错误消息.
有关更多信息,请访问https://github.com/patthoyts/gitlabhq/wiki/Setting-up-ldap-auth和(更过时但仍然有用)https://github.com/intridea/omniauth-ldap
我已修补gitlab以这种方式工作,并在https://foivos.zakkak.net/tutorials/gitlab_ldap_auth_without_querying_account/中记录了该过程
为了实现自我完整性,我在这里毫不客气地复制了说明。
注意:本教程最后一次使用从源代码安装的gitlab 8.2进行了测试。
本教程旨在描述如何修改Gitlab安装,以使用用户凭据对LDAP服务器进行身份验证。默认情况下,Gitlab依靠匿名绑定或特殊的查询用户在用自己的凭据对用户进行身份验证之前询问LDAP服务器是否存在用户。但是,出于安全原因,许多管理员禁用匿名绑定,并禁止创建特殊的查询 LDAP用户。
在本教程中,我们假设我们在gitlab.example.com一个gitlab设置和运行ldap.example.com LDAP服务器,并且用户有以下形式的DN:
CN=username,OU=Users,OU=division,OU=department,DC=example,DC=com。
为了使Gitlab在这种情况下工作,我们需要部分修改其关于LDAP的身份验证机制。
首先,我们用此派生替换omniauth-ldap模块。为此,我们将以下补丁应用到gitlab/Gemfile:
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"
Run Code Online (Sandbox Code Playgroud)
现在,我们需要执行以下操作:
sudo -u git -H bundle install --without development test mysql --path vendor/bundle --no-deploymentsudo -u git -H bundle install --deployment --without development test mysql aws这些命令将在中获取修改后的omniauth-ldap模块
gitlab/vendor/bundle/ruby/2.x.x/bundler/gems。现在已经获取了模块,我们需要对其进行修改以使用LDAP服务器期望的DN。我们通过修补实现这一目标lib/omniauth/strategies/ldap.rb中
gitlab/vendor/bundle/ruby/2.x.x/bundler/gems/omniauth-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
Run Code Online (Sandbox Code Playgroud)
通过此模块,gitlab使用用户的凭据绑定到LDAP服务器并对其进行查询,以及对用户自己进行身份验证。
但是,这仅在用户不使用ssh-key来向Gitlab进行身份验证时才有效。通过ssh-key进行身份验证时,默认情况下,Gitlab会查询LDAP服务器以找出相应的用户是否(仍然)是有效用户。此时,我们无法使用用户凭证来查询LDAP服务器,因为用户未将其提供给我们。结果,我们禁用了该机制,从本质上允许具有已注册ssh-key但已从LDAP服务器中删除的用户继续使用我们的Gitlab设置。为了防止此类用户仍然可以使用您的Gitlab设置,您将必须从设置中的任何帐户中手动删除其ssh密钥。
要禁用此机制,我们gitlab/lib/gitlab/ldap/access.rb
使用以下方法进行修补:
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
Run Code Online (Sandbox Code Playgroud)
在gitlab.yml使用类似于下面的东西(修改您的需要):
#
# 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 'jane.doe@example.com' and 'p@ssw0rd' as LDAP credentials;
# - GitLab queries the LDAP server with 'jane.doe' and 'p@ssw0rd'.
#
# 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))'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34818 次 |
| 最近记录: |