Skip to content

Commit 1e4732e

Browse files
authored
Deprecate the behaviour of implicitly disabling file/native realm (elastic#69320)
As a precursor for elastic#50892, this PR deprecate the behaviour of file and/or native realm being implicitly disabled when there are other explicitly configured realms. With this change, the recommend way of disabling file/native realm is to explicitly set enabled to false, e.g.: xpack.security.authc.realms.file.default_file.enabled: false This PR ensures that a warning is generated whenever file and/or native realm is implicitly disabled. This change also brings a question about the order parameter. Currently, the order parameter is mandatory in 8.0 and gets a warning message if it is missing in 7.x. However, it makes sense to not specify the order parameter if the realm is disabled. So I also updated the order parameter related code to do just that.
1 parent 669f058 commit 1e4732e

File tree

8 files changed

+426
-16
lines changed

8 files changed

+426
-16
lines changed

docs/reference/migration/index.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ For more information about {minor-version},
2828
see the <<release-highlights>> and <<es-release-notes>>.
2929
For information about how to upgrade your cluster, see <<setup-upgrade>>.
3030

31+
* <<breaking-changes-7.13,Migrating to 7.13>>
3132
* <<breaking-changes-7.12,Migrating to 7.12>>
3233
* <<breaking-changes-7.11,Migrating to 7.11>>
3334
* <<breaking-changes-7.10,Migrating to 7.10>>
@@ -44,6 +45,7 @@ For information about how to upgrade your cluster, see <<setup-upgrade>>.
4445

4546
--
4647

48+
include::migrate_7_13.asciidoc[]
4749
include::migrate_7_12.asciidoc[]
4850
include::migrate_7_11.asciidoc[]
4951
include::migrate_7_10.asciidoc[]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[[migrating-7.13]]
2+
== Migrating to 7.13
3+
++++
4+
<titleabbrev>7.13</titleabbrev>
5+
++++
6+
7+
This section discusses the changes that you need to be aware of when migrating
8+
your application to {es} 7.13.
9+
10+
See also <<release-highlights>> and <<es-release-notes>>.
11+
12+
// * <<breaking_713_blah_changes>>
13+
// * <<breaking_713_blah_changes>>
14+
15+
//NOTE: The notable-breaking-changes tagged regions are re-used in the
16+
//Installation and Upgrade Guide
17+
18+
//tag::notable-breaking-changes[]
19+
20+
[discrete]
21+
[[breaking-changes-7.13]]
22+
=== Breaking changes
23+
24+
The following changes in {es} 7.13 might affect your applications
25+
and prevent them from operating normally.
26+
Before upgrading to 7.13, review these changes and take the described steps
27+
to mitigate the impact.
28+
29+
NOTE: Breaking changes introduced in minor versions are
30+
normally limited to security and bug fixes.
31+
Significant changes in behavior are deprecated in a minor release and
32+
the old behavior is supported until the next major release.
33+
To find out if you are using any deprecated functionality,
34+
enable <<deprecation-logging, deprecation logging>>.
35+
36+
37+
[discrete]
38+
[[deprecated-7.13]]
39+
=== Deprecations
40+
41+
The following functionality has been deprecated in {es} 7.13
42+
and will be removed in 8.0
43+
While this won't have an immediate impact on your applications,
44+
we strongly encourage you take the described steps to update your code
45+
after upgrading to 7.13.
46+
47+
NOTE: Significant changes in behavior are deprecated in a minor release and
48+
the old behavior is supported until the next major release.
49+
To find out if you are using any deprecated functionality,
50+
enable <<deprecation-logging, deprecation logging>>.
51+
52+
[discrete]
53+
[[breaking_713_security_changes]]
54+
==== Security deprecations
55+
56+
[[implicitly-disabled-basic-realms]]
57+
Currently, the file and native realms have following implicit behaviours:
58+
59+
* If file and native realms are not configured, they are implicitly disabled
60+
if there are other explicitly configured realms.
61+
* If no realm is available due to either unconfigured, explicitly disabled
62+
or disallowed by the license, the file and native realms are always enabled
63+
even when they are explicitly disabled.
64+
65+
Both of the above behaviours are deprecated. In version 8.0.0, the file and
66+
native realms will always be enabled unless explicitly disabled. If they are
67+
explicitly disabled, they remain disabled at all times.

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/RealmSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
public class RealmSettings {
3131

3232
public static final String PREFIX = "xpack.security.authc.realms.";
33+
public static final String ENABLED_SETTING_KEY = "enabled";
3334
public static final String ORDER_SETTING_KEY = "order";
3435

35-
public static final Function<String, Setting.AffixSetting<Boolean>> ENABLED_SETTING = affixSetting("enabled",
36+
public static final Function<String, Setting.AffixSetting<Boolean>> ENABLED_SETTING = affixSetting(ENABLED_SETTING_KEY,
3637
key -> Setting.boolSetting(key, true, Setting.Property.NodeScope));
3738
public static final Function<String, Setting.AffixSetting<Integer>> ORDER_SETTING = affixSetting(ORDER_SETTING_KEY,
3839
key -> Setting.intSetting(key, Integer.MAX_VALUE, Setting.Property.NodeScope));

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private DeprecationChecks() {
4747
NodeDeprecationChecks::checkProcessors,
4848
NodeDeprecationChecks::checkMissingRealmOrders,
4949
NodeDeprecationChecks::checkUniqueRealmOrders,
50+
NodeDeprecationChecks::checkImplicitlyDisabledBasicRealms,
5051
(settings, pluginsAndModules) -> NodeDeprecationChecks.checkThreadPoolListenerQueueSize(settings),
5152
(settings, pluginsAndModules) -> NodeDeprecationChecks.checkThreadPoolListenerSize(settings),
5253
NodeDeprecationChecks::checkClusterRemoteConnectSetting,

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99

1010
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
1111
import org.elasticsearch.bootstrap.JavaVersion;
12+
import org.elasticsearch.common.Strings;
1213
import org.elasticsearch.common.settings.Setting;
1314
import org.elasticsearch.common.settings.Setting.Property;
1415
import org.elasticsearch.common.settings.Settings;
1516
import org.elasticsearch.common.util.concurrent.EsExecutors;
17+
import org.elasticsearch.common.util.set.Sets;
1618
import org.elasticsearch.env.Environment;
1719
import org.elasticsearch.node.Node;
1820
import org.elasticsearch.script.ScriptService;
1921
import org.elasticsearch.threadpool.FixedExecutorBuilder;
2022
import org.elasticsearch.transport.RemoteClusterService;
2123
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
24+
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
2225
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;
2328

29+
import java.util.HashSet;
2430
import java.util.List;
2531
import java.util.Locale;
2632
import java.util.Map;
@@ -52,6 +58,7 @@ static DeprecationIssue checkMissingRealmOrders(final Settings settings, final P
5258
final Set<String> orderNotConfiguredRealms = RealmSettings.getRealmSettings(settings).entrySet()
5359
.stream()
5460
.filter(e -> false == e.getValue().hasValue(RealmSettings.ORDER_SETTING_KEY))
61+
.filter(e -> e.getValue().getAsBoolean(RealmSettings.ENABLED_SETTING_KEY, true))
5562
.map(e -> RealmSettings.realmSettingPrefix(e.getKey()) + RealmSettings.ORDER_SETTING_KEY)
5663
.collect(Collectors.toSet());
5764

@@ -104,6 +111,57 @@ static DeprecationIssue checkUniqueRealmOrders(final Settings settings, final Pl
104111
);
105112
}
106113

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+
107165
static DeprecationIssue checkThreadPoolListenerQueueSize(final Settings settings) {
108166
return checkThreadPoolListenerSetting("thread_pool.listener.queue_size", settings);
109167
}

0 commit comments

Comments
 (0)