diff options
author | Simon Knox <simon@gitlab.com> | 2017-07-27 07:12:09 +0000 |
---|---|---|
committer | Simon Knox <simon@gitlab.com> | 2017-07-27 07:12:09 +0000 |
commit | e2adbea3f3f5c46f0f25377efe558d05ad0b0c74 (patch) | |
tree | 836c6cb04c823c9177fdd25e4ea1c5f19405e3dd /lib | |
parent | f9817808eb5948bf8701eb27ce34eefedb9a2720 (diff) | |
parent | 5e93a42b5d3bfda8de54de7b703f52e8dab39ed8 (diff) | |
download | gitlab-ce-e2adbea3f3f5c46f0f25377efe558d05ad0b0c74.tar.gz |
Merge branch 'add-ldap-ssl-certificate-verification-9-4' into '9-4-stable-patch-2'
Add LDAP SSL certificate verification [9.4]
See merge request !13107
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ldap/config.rb | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/lib/gitlab/ldap/config.rb b/lib/gitlab/ldap/config.rb index 6fdf68641e2..8eda3ea03f9 100644 --- a/lib/gitlab/ldap/config.rb +++ b/lib/gitlab/ldap/config.rb @@ -2,6 +2,12 @@ module Gitlab module LDAP class Config + NET_LDAP_ENCRYPTION_METHOD = { + simple_tls: :simple_tls, + start_tls: :start_tls, + plain: nil + }.freeze + attr_accessor :provider, :options def self.enabled? @@ -39,7 +45,7 @@ module Gitlab def adapter_options opts = base_options.merge( - encryption: encryption + encryption: encryption_options ) opts.merge!(auth_options) if has_auth? @@ -50,9 +56,10 @@ module Gitlab def omniauth_options opts = base_options.merge( base: base, - method: options['method'], + encryption: options['encryption'], filter: omniauth_user_filter, - name_proc: name_proc + name_proc: name_proc, + disable_verify_certificates: !options['verify_certificates'] ) if has_auth? @@ -62,6 +69,9 @@ module Gitlab ) end + opts[:ca_file] = options['ca_file'] if options['ca_file'].present? + opts[:ssl_version] = options['ssl_version'] if options['ssl_version'].present? + opts end @@ -157,15 +167,37 @@ module Gitlab base_config.servers.values.find { |server| server['provider_name'] == provider } end - def encryption - case options['method'].to_s - when 'ssl' - :simple_tls - when 'tls' - :start_tls - else - nil - end + def encryption_options + method = translate_method(options['encryption']) + return nil unless method + + { + method: method, + tls_options: tls_options(method) + } + end + + def translate_method(method_from_config) + NET_LDAP_ENCRYPTION_METHOD[method_from_config.to_sym] + end + + def tls_options(method) + return { verify_mode: OpenSSL::SSL::VERIFY_NONE } unless method + + opts = if options['verify_certificates'] + OpenSSL::SSL::SSLContext::DEFAULT_PARAMS + else + # It is important to explicitly set verify_mode for two reasons: + # 1. The behavior of OpenSSL is undefined when verify_mode is not set. + # 2. The net-ldap gem implementation verifies the certificate hostname + # unless verify_mode is set to VERIFY_NONE. + { verify_mode: OpenSSL::SSL::VERIFY_NONE } + end + + opts[:ca_file] = options['ca_file'] if options['ca_file'].present? + opts[:ssl_version] = options['ssl_version'] if options['ssl_version'].present? + + opts end def auth_options |