Skip to content

Commit

Permalink
[8.15] Default enable cluster state role mapper (#114337) (#114421)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
n1v0lg authored Oct 9, 2024
1 parent 89c6684 commit 26fcc89
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/114337.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 114337
summary: "Enables cluster state role mapper, to include ECK operator-defined role mappings in role resolution"
area: Authentication
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,6 @@ public class RoleMappingFileSettingsIT extends NativeRealmIntegTestCase {
}
}""";

@Override
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
Settings.Builder builder = Settings.builder()
.put(super.nodeSettings(nodeOrdinal, otherSettings))
// some tests make use of cluster-state based role mappings
.put("xpack.security.authc.cluster_state_role_mappings.enabled", true);
return builder.build();
}

@After
public void cleanUp() {
updateClusterSettings(Settings.builder().putNull("indices.recovery.max_bytes_per_sec"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ private void clearRoleMappings() throws InterruptedException {
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
Settings.Builder builder = Settings.builder()
.put(super.nodeSettings(nodeOrdinal, otherSettings))
// some tests make use of cluster-state based role mappings
.put("xpack.security.authc.cluster_state_role_mappings.enabled", true)
.put(XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey(), randomBoolean())
// 1st JWT realm
.put("xpack.security.authc.realms.jwt.jwt0.order", 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
public final class ClusterStateRoleMapper extends AbstractRoleMapperClearRealmCache implements ClusterStateListener {

/**
* This setting is never registered by the xpack security plugin - in order to enable the
* This setting is never registered by the xpack security plugin - in order to disable the
* cluster-state based role mapper another plugin must register it as a boolean setting
* and set it to `true`.
* and set it to `false`.
* If this setting is set to <code>true</code> then:
* <ul>
* <li>Realms that make use role mappings (all realms but file and native) will,
Expand All @@ -54,8 +54,8 @@ public final class ClusterStateRoleMapper extends AbstractRoleMapperClearRealmCa
public ClusterStateRoleMapper(Settings settings, ScriptService scriptService, ClusterService clusterService) {
this.scriptService = scriptService;
this.clusterService = clusterService;
// this role mapper is disabled by default and only code in other plugins can enable it
this.enabled = settings.getAsBoolean(CLUSTER_STATE_ROLE_MAPPINGS_ENABLED, false);
// this role mapper is enabled by default and only code in other plugins can disable it
this.enabled = settings.getAsBoolean(CLUSTER_STATE_ROLE_MAPPINGS_ENABLED, true);
if (this.enabled) {
clusterService.addListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public static class UnregisteredSecuritySettingsPlugin extends Plugin {
);
public static final Setting<Boolean> CLUSTER_STATE_ROLE_MAPPINGS_ENABLED = Setting.boolSetting(
"xpack.security.authc.cluster_state_role_mappings.enabled",
false,
true,
Setting.Property.NodeScope
);
public static final Setting<Boolean> NATIVE_ROLES_ENABLED = Setting.boolSetting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public void setup() {
() -> 1L
);
clusterService = mock(ClusterService.class);
enabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", true).build();
disabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", false).build();
if (randomBoolean()) {
disabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", false).build();
enabledSettings = Settings.builder().put("xpack.security.authc.cluster_state_role_mappings.enabled", true).build();
} else {
// the cluster state role mapper is disabled by default
disabledSettings = Settings.EMPTY;
// the cluster state role mapper is enabled by default
enabledSettings = Settings.EMPTY;
}
}

Expand Down

0 comments on commit 26fcc89

Please sign in to comment.