mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-26 21:16:06 +10:00
Merge branch 'optimize_ldap' into 'master'
Optimize LDAP and add a search timeout Related to #4282 This merge request arranges some things in `access.rb` to facilitate some optimizations in EE (to come later). It also adds a 10 second timeout to all LDAP searches so the entire worker is not blocked if some query doesn't return in a reasonable amount of time. This timeout is configurable per LDAP server. See merge request !2267
This commit is contained in:
committed by
Robert Speicher
parent
56fed7f119
commit
76ec8a112e
@@ -5,7 +5,7 @@
|
||||
module Gitlab
|
||||
module LDAP
|
||||
class Access
|
||||
attr_reader :adapter, :provider, :user
|
||||
attr_reader :provider, :user
|
||||
|
||||
def self.open(user, &block)
|
||||
Gitlab::LDAP::Adapter.open(user.ldap_identity.provider) do |adapter|
|
||||
@@ -32,7 +32,7 @@ module Gitlab
|
||||
end
|
||||
|
||||
def allowed?
|
||||
if Gitlab::LDAP::Person.find_by_dn(user.ldap_identity.extern_uid, adapter)
|
||||
if ldap_user
|
||||
return true unless ldap_config.active_directory
|
||||
|
||||
# Block user in GitLab if he/she was blocked in AD
|
||||
@@ -59,6 +59,10 @@ module Gitlab
|
||||
def ldap_config
|
||||
Gitlab::LDAP::Config.new(provider)
|
||||
end
|
||||
|
||||
def ldap_user
|
||||
@ldap_user ||= Gitlab::LDAP::Person.find_by_dn(user.ldap_identity.extern_uid, adapter)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,19 +70,25 @@ module Gitlab
|
||||
end
|
||||
|
||||
def ldap_search(*args)
|
||||
results = ldap.search(*args)
|
||||
# Net::LDAP's `time` argument doesn't work. Use Ruby `Timeout` instead.
|
||||
Timeout.timeout(config.timeout) do
|
||||
results = ldap.search(*args)
|
||||
|
||||
if results.nil?
|
||||
response = ldap.get_operation_result
|
||||
if results.nil?
|
||||
response = ldap.get_operation_result
|
||||
|
||||
unless response.code.zero?
|
||||
Rails.logger.warn("LDAP search error: #{response.message}")
|
||||
unless response.code.zero?
|
||||
Rails.logger.warn("LDAP search error: #{response.message}")
|
||||
end
|
||||
|
||||
[]
|
||||
else
|
||||
results
|
||||
end
|
||||
|
||||
[]
|
||||
else
|
||||
results
|
||||
end
|
||||
rescue Timeout::Error
|
||||
Rails.logger.warn("LDAP search timed out after #{config.timeout} seconds")
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,6 +88,10 @@ module Gitlab
|
||||
options['attributes']
|
||||
end
|
||||
|
||||
def timeout
|
||||
options['timeout'].to_i
|
||||
end
|
||||
|
||||
protected
|
||||
def base_config
|
||||
Gitlab.config.ldap
|
||||
|
||||
Reference in New Issue
Block a user