|
9 | 9 |
|
10 | 10 | import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; |
11 | 11 | import org.elasticsearch.bootstrap.JavaVersion; |
| 12 | +import org.elasticsearch.common.Strings; |
12 | 13 | import org.elasticsearch.common.settings.Setting; |
13 | 14 | import org.elasticsearch.common.settings.Setting.Property; |
14 | 15 | import org.elasticsearch.common.settings.Settings; |
15 | 16 | import org.elasticsearch.common.util.concurrent.EsExecutors; |
| 17 | +import org.elasticsearch.common.util.set.Sets; |
16 | 18 | import org.elasticsearch.env.Environment; |
17 | 19 | import org.elasticsearch.node.Node; |
18 | 20 | import org.elasticsearch.script.ScriptService; |
19 | 21 | import org.elasticsearch.threadpool.FixedExecutorBuilder; |
20 | 22 | import org.elasticsearch.transport.RemoteClusterService; |
21 | 23 | import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; |
| 24 | +import org.elasticsearch.xpack.core.security.authc.RealmConfig; |
22 | 25 | import org.elasticsearch.xpack.core.security.authc.RealmSettings; |
| 26 | +import org.elasticsearch.xpack.core.security.authc.esnative.NativeRealmSettings; |
| 27 | +import org.elasticsearch.xpack.core.security.authc.file.FileRealmSettings; |
23 | 28 |
|
| 29 | +import java.util.HashSet; |
24 | 30 | import java.util.List; |
25 | 31 | import java.util.Locale; |
26 | 32 | import java.util.Map; |
@@ -52,6 +58,7 @@ static DeprecationIssue checkMissingRealmOrders(final Settings settings, final P |
52 | 58 | final Set<String> orderNotConfiguredRealms = RealmSettings.getRealmSettings(settings).entrySet() |
53 | 59 | .stream() |
54 | 60 | .filter(e -> false == e.getValue().hasValue(RealmSettings.ORDER_SETTING_KEY)) |
| 61 | + .filter(e -> e.getValue().getAsBoolean(RealmSettings.ENABLED_SETTING_KEY, true)) |
55 | 62 | .map(e -> RealmSettings.realmSettingPrefix(e.getKey()) + RealmSettings.ORDER_SETTING_KEY) |
56 | 63 | .collect(Collectors.toSet()); |
57 | 64 |
|
@@ -104,6 +111,57 @@ static DeprecationIssue checkUniqueRealmOrders(final Settings settings, final Pl |
104 | 111 | ); |
105 | 112 | } |
106 | 113 |
|
| 114 | + static DeprecationIssue checkImplicitlyDisabledBasicRealms(final Settings settings, final PluginsAndModules pluginsAndModules) { |
| 115 | + final Map<RealmConfig.RealmIdentifier, Settings> realmSettings = RealmSettings.getRealmSettings(settings); |
| 116 | + if (realmSettings.isEmpty()) { |
| 117 | + return null; |
| 118 | + } |
| 119 | + |
| 120 | + boolean anyRealmEnabled = false; |
| 121 | + final Set<String> unconfiguredBasicRealms = |
| 122 | + new HashSet<>(org.elasticsearch.common.collect.Set.of(FileRealmSettings.TYPE, NativeRealmSettings.TYPE)); |
| 123 | + for (Map.Entry<RealmConfig.RealmIdentifier, Settings> realmSetting: realmSettings.entrySet()) { |
| 124 | + anyRealmEnabled = anyRealmEnabled || realmSetting.getValue().getAsBoolean(RealmSettings.ENABLED_SETTING_KEY, true); |
| 125 | + unconfiguredBasicRealms.remove(realmSetting.getKey().getType()); |
| 126 | + } |
| 127 | + |
| 128 | + final String details; |
| 129 | + if (false == anyRealmEnabled) { |
| 130 | + final List<String> explicitlyDisabledBasicRealms = |
| 131 | + Sets.difference(org.elasticsearch.common.collect.Set.of(FileRealmSettings.TYPE, NativeRealmSettings.TYPE), |
| 132 | + unconfiguredBasicRealms).stream().sorted().collect(Collectors.toList()); |
| 133 | + if (explicitlyDisabledBasicRealms.isEmpty()) { |
| 134 | + return null; |
| 135 | + } |
| 136 | + details = String.format( |
| 137 | + Locale.ROOT, |
| 138 | + "Found explicitly disabled basic %s: [%s]. But %s will be enabled because no other realms are configured or enabled. " + |
| 139 | + "In next major release, explicitly disabled basic realms will remain disabled.", |
| 140 | + explicitlyDisabledBasicRealms.size() == 1 ? "realm" : "realms", |
| 141 | + Strings.collectionToDelimitedString(explicitlyDisabledBasicRealms, ","), |
| 142 | + explicitlyDisabledBasicRealms.size() == 1 ? "it" : "they" |
| 143 | + ); |
| 144 | + } else { |
| 145 | + if (unconfiguredBasicRealms.isEmpty()) { |
| 146 | + return null; |
| 147 | + } |
| 148 | + details = String.format( |
| 149 | + Locale.ROOT, |
| 150 | + "Found implicitly disabled basic %s: [%s]. %s disabled because there are other explicitly configured realms." + |
| 151 | + "In next major release, basic realms will always be enabled unless explicitly disabled.", |
| 152 | + unconfiguredBasicRealms.size() == 1 ? "realm" : "realms", |
| 153 | + Strings.collectionToDelimitedString(unconfiguredBasicRealms, ","), |
| 154 | + unconfiguredBasicRealms.size() == 1 ? "It is" : "They are"); |
| 155 | + } |
| 156 | + return new DeprecationIssue( |
| 157 | + DeprecationIssue.Level.WARNING, |
| 158 | + "File and/or native realms are enabled by default in next major release.", |
| 159 | + "https://www.elastic.co/guide/en/elasticsearch/reference/7.13/deprecated-7.13.html#implicitly-disabled-basic-realms", |
| 160 | + details |
| 161 | + ); |
| 162 | + |
| 163 | + } |
| 164 | + |
107 | 165 | static DeprecationIssue checkThreadPoolListenerQueueSize(final Settings settings) { |
108 | 166 | return checkThreadPoolListenerSetting("thread_pool.listener.queue_size", settings); |
109 | 167 | } |
|
0 commit comments