Skip to content

Commit 26fcc89

Browse files
authored
[8.15] Default enable cluster state role mapper (#114337) (#114421)
This (backport) PR default-enables cluster-state role mappings as the first part of the mitigation for a regression in ECK introduced by #107410. Prior to this PR, cluster-state role mappings were written to cluster-state, but not read from it. With this PR, cluster-state role mappings will be read and used to assign roles to users, i.e. in user role resolution. However, they will not be included in the output of the [Get role mappings API](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role-mapping.html) yet. Exposing them via API is a target for a follow-up fix. Relates: ES-9628 Supersedes: #113900
1 parent 89c6684 commit 26fcc89

File tree

6 files changed

+14
-20
lines changed

6 files changed

+14
-20
lines changed

docs/changelog/114337.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 114337
2+
summary: "Enables cluster state role mapper, to include ECK operator-defined role mappings in role resolution"
3+
area: Authentication
4+
type: bug
5+
issues: []

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/RoleMappingFileSettingsIT.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,6 @@ public class RoleMappingFileSettingsIT extends NativeRealmIntegTestCase {
148148
}
149149
}""";
150150

151-
@Override
152-
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
153-
Settings.Builder builder = Settings.builder()
154-
.put(super.nodeSettings(nodeOrdinal, otherSettings))
155-
// some tests make use of cluster-state based role mappings
156-
.put("xpack.security.authc.cluster_state_role_mappings.enabled", true);
157-
return builder.build();
158-
}
159-
160151
@After
161152
public void cleanUp() {
162153
updateClusterSettings(Settings.builder().putNull("indices.recovery.max_bytes_per_sec"));

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/authc/jwt/JwtRoleMappingsIntegTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ private void clearRoleMappings() throws InterruptedException {
7878
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
7979
Settings.Builder builder = Settings.builder()
8080
.put(super.nodeSettings(nodeOrdinal, otherSettings))
81-
// some tests make use of cluster-state based role mappings
82-
.put("xpack.security.authc.cluster_state_role_mappings.enabled", true)
8381
.put(XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey(), randomBoolean())
8482
// 1st JWT realm
8583
.put("xpack.security.authc.realms.jwt.jwt0.order", 10)

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/support/mapper/ClusterStateRoleMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
public final class ClusterStateRoleMapper extends AbstractRoleMapperClearRealmCache implements ClusterStateListener {
3232

3333
/**
34-
* This setting is never registered by the xpack security plugin - in order to enable the
34+
* This setting is never registered by the xpack security plugin - in order to disable the
3535
* cluster-state based role mapper another plugin must register it as a boolean setting
36-
* and set it to `true`.
36+
* and set it to `false`.
3737
* If this setting is set to <code>true</code> then:
3838
* <ul>
3939
* <li>Realms that make use role mappings (all realms but file and native) will,
@@ -54,8 +54,8 @@ public final class ClusterStateRoleMapper extends AbstractRoleMapperClearRealmCa
5454
public ClusterStateRoleMapper(Settings settings, ScriptService scriptService, ClusterService clusterService) {
5555
this.scriptService = scriptService;
5656
this.clusterService = clusterService;
57-
// this role mapper is disabled by default and only code in other plugins can enable it
58-
this.enabled = settings.getAsBoolean(CLUSTER_STATE_ROLE_MAPPINGS_ENABLED, false);
57+
// this role mapper is enabled by default and only code in other plugins can disable it
58+
this.enabled = settings.getAsBoolean(CLUSTER_STATE_ROLE_MAPPINGS_ENABLED, true);
5959
if (this.enabled) {
6060
clusterService.addListener(this);
6161
}

x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySettingsSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public static class UnregisteredSecuritySettingsPlugin extends Plugin {
403403
);
404404
public static final Setting<Boolean> CLUSTER_STATE_ROLE_MAPPINGS_ENABLED = Setting.boolSetting(
405405
"xpack.security.authc.cluster_state_role_mappings.enabled",
406-
false,
406+
true,
407407
Setting.Property.NodeScope
408408
);
409409
public static final Setting<Boolean> NATIVE_ROLES_ENABLED = Setting.boolSetting(

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/mapper/ClusterStateRoleMapperTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public void setup() {
5656
() -> 1L
5757
);
5858
clusterService = mock(ClusterService.class);
59-
enabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", true).build();
59+
disabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", false).build();
6060
if (randomBoolean()) {
61-
disabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", false).build();
61+
enabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", true).build();
6262
} else {
63-
// the cluster state role mapper is disabled by default
64-
disabledSettings = Settings.EMPTY;
63+
// the cluster state role mapper is enabled by default
64+
enabledSettings = Settings.EMPTY;
6565
}
6666
}
6767

0 commit comments

Comments
 (0)