Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-06-09 02:30:54 +0300
committerMichael Kozono <mkozono@gmail.com>2017-07-26 12:43:33 +0300
commitb67c007842ba42d2ed1cf1d8879a220a1b9906f9 (patch)
treeaa8e335aab42cd81d2ea770500b9992965ed6b6e /lib
parent94b4c9f34f576bbeddc2a22098f33c6ae656d7ab (diff)
Set `Net::LDAP` encryption properly
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ldap/config.rb34
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/gitlab/ldap/config.rb b/lib/gitlab/ldap/config.rb
index c531100fbc4..383e0a09e42 100644
--- a/lib/gitlab/ldap/config.rb
+++ b/lib/gitlab/ldap/config.rb
@@ -2,6 +2,16 @@
module Gitlab
module LDAP
class Config
+ NET_LDAP_ENCRYPTION_METHOD = {
+ :simple_tls => :simple_tls,
+ :start_tls => :start_tls,
+ :plain => nil,
+
+ # Deprecated. Better to pass-through the actual `Net::LDAP` encryption type.
+ :ssl => :simple_tls,
+ :tls => :start_tls,
+ }
+
attr_accessor :provider, :options
def self.enabled?
@@ -39,7 +49,7 @@ module Gitlab
def adapter_options
opts = base_options.merge(
- encryption: encryption
+ encryption: encryption_options
)
opts.merge!(auth_options) if has_auth?
@@ -157,14 +167,22 @@ module Gitlab
base_config.servers.values.find { |server| server['provider_name'] == provider }
end
- def encryption
- case options['encryption'].to_s
- when 'ssl'
- :simple_tls
- when 'tls'
- :start_tls
+ def encryption_options
+ method = translate_method(options['encryption'])
+ options = { method: method }
+ options.merge!(tls_options: tls_options(method)) if method
+ options
+ end
+
+ def translate_method(method_from_config)
+ NET_LDAP_ENCRYPTION_METHOD[method_from_config.to_sym]
+ end
+
+ def tls_options(method)
+ if method && options['verify_certificates']
+ OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
else
- nil
+ { verify_mode: OpenSSL::SSL::VERIFY_NONE }
end
end