Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove the definition for LDAP tls options

Oliver Güntherc29279d99b1f
diff --git a/app/models/setting.rb b/app/models/setting.rb
index a72883ab72f..749ce4dfbf4 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -336,8 +336,7 @@ class Setting < ApplicationRecord
definition = Settings::Definition[name]
if definition.serialized? && value.is_a?(String)
- YAML::safe_load(value, permitted_classes: [Symbol, ActiveSupport::HashWithIndifferentAccess, Date, Time, URI::Generic])
- .tap { |maybe_hash| normalize_hash!(maybe_hash) if maybe_hash.is_a?(Hash) }
+ deserialize_hash(value)
elsif value != ''.freeze && !value.nil?
read_formatted_setting(value, definition.format)
else
@@ -345,6 +344,11 @@ class Setting < ApplicationRecord
end
end
+ def self.deserialize_hash(value)
+ YAML::safe_load(value, permitted_classes: [Symbol, ActiveSupport::HashWithIndifferentAccess, Date, Time, URI::Generic])
+ .tap { |maybe_hash| normalize_hash!(maybe_hash) if maybe_hash.is_a?(Hash) }
+ end
+
def self.normalize_hash!(hash)
hash.deep_stringify_keys!
hash.deep_transform_values! { |v| v.is_a?(URI::Generic) ? v.to_s : v }
diff --git a/config/configuration.yml.example b/config/configuration.yml.example
index b6120bc37c3..750bc18982f 100644
--- a/config/configuration.yml.example
+++ b/config/configuration.yml.example
@@ -383,16 +383,6 @@ default:
# user: admin
# password: admin
- # Overriding LDAP TLS configuration
- # You can set other TLS options for the LDAP auth source connection
- # They are passed as the `tls_options` to the Net::LDAP gem
- # see the following resources for more information
- # https://github.com/ruby-ldap/ruby-net-ldap/blob/master/lib/net/ldap.rb
- # https://ruby.github.io/openssl/OpenSSL/SSL/SSLContext.html
- # For example, to specify a CA file
- # ldap_tls_options:
- # ca_file: "/path/to/the/root-ca.crt"
-
# By default, the APIv3 allows authentication through basic auth.
# Uncomment the following line to restrict APIv3 access to session.
# apiv3_enable_basic_auth: false
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index 306827d022d..14d3b4566df 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -592,11 +592,6 @@ module Settings
format: :boolean,
default: false
},
- ldap_tls_options: {
- format: :hash,
- default: {},
- writable: true
- },
log_level: {
description: "Set the OpenProject logger level",
default: Rails.env.development? ? "debug" : "info",
diff --git a/db/migrate/20221115082403_add_ldap_tls_options.rb b/db/migrate/20221115082403_add_ldap_tls_options.rb
index eda3d679f5e..ef5dbb5d6c2 100644
--- a/db/migrate/20221115082403_add_ldap_tls_options.rb
+++ b/db/migrate/20221115082403_add_ldap_tls_options.rb
@@ -41,10 +41,25 @@ class AddLdapTlsOptions < ActiveRecord::Migration[7.0]
dir.up do
# Current LDAP library default is to not verify the certificate
MigratingAuthSource.reset_column_information
- ldap_settings = (Setting.ldap_tls_options || {}).with_indifferent_access
- verify_peer = ldap_settings[:verify_mode] == OpenSSL::SSL::VERIFY_PEER
- MigratingAuthSource.update_all(verify_peer:)
+
+ ldap_settings = Setting.find_by(name: 'ldap_tls_options')&.value
+ migrate_ldap_settings(ldap_settings)
end
end
end
+
+ private
+
+ def migrate_ldap_settings(ldap_settings)
+ return if ldap_settings.blank?
+
+ parsed = Setting.deserialize_hash(ldap_settings)
+ verify_peer = parsed['verify_mode'] == OpenSSL::SSL::VERIFY_PEER
+
+ MigratingAuthSource.update_all(verify_peer:)
+ rescue StandardError => e
+ Rails.logger.error do
+ "Failed to set LDAP verify_mode from settings: #{e.message}. Please double check your LDAP configuration."
+ end
+ end
end
diff --git a/db/migrate/20240402065214_remove_ldap_tls_setting.rb b/db/migrate/20240402065214_remove_ldap_tls_setting.rb
new file mode 100644
index 00000000000..98a77feca5a
--- /dev/null
+++ b/db/migrate/20240402065214_remove_ldap_tls_setting.rb
@@ -0,0 +1,9 @@
+class RemoveLdapTlsSetting < ActiveRecord::Migration[7.1]
+ def up
+ execute "DELETE FROM settings WHERE name = 'ldap_tls_options'"
+ end
+
+ def down
+ # Nothing to do
+ end
+end
diff --git a/spec/migrations/restore_defaults_on_empty_settings_spec.rb b/spec/migrations/restore_defaults_on_empty_settings_spec.rb
index 90cf1e90453..0a1352f9291 100644
--- a/spec/migrations/restore_defaults_on_empty_settings_spec.rb
+++ b/spec/migrations/restore_defaults_on_empty_settings_spec.rb
@@ -61,13 +61,6 @@ RSpec.describe RestoreDefaultsOnEmptySettings, type: :model do
end
end
- context "with an empty setting which must be a hash" do
- it_behaves_like "a successful migration of an empty setting" do
- let(:setting_name) { "ldap_tls_options" }
- let(:expected_value) { {} }
- end
- end
-
context "with an empty setting which must be a string" do
it_behaves_like "a successful migration of an empty setting" do
let(:setting_name) { "default_language" }