Skip to content

Commit 34c24df

Browse files
[Failure Store] Access for internal users (#125660) (#125780)
This PR grants `manage_failure_store` to the internal user `_data_stream_lifecycle` to enable life-cycle management for the failure indices of data stream, which includes rollovers using the failures selector. I'm only unit testing this but we also need to add DLM tests for the failure store with security enabled. Relates: ES-11355 Co-authored-by: Slobodan Adamović <[email protected]>
1 parent fd7a4b4 commit 34c24df

File tree

2 files changed

+60
-35
lines changed

2 files changed

+60
-35
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/user/InternalUsers.java

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
3737
import org.elasticsearch.xpack.core.security.support.MetadataUtils;
3838

39+
import java.util.Arrays;
3940
import java.util.Collection;
4041
import java.util.Collections;
4142
import java.util.Map;
43+
import java.util.Objects;
4244
import java.util.function.Function;
4345
import java.util.stream.Collectors;
4446
import java.util.stream.Stream;
@@ -158,14 +160,18 @@ public class InternalUsers {
158160
RoleDescriptor.IndicesPrivileges.builder()
159161
.indices("*")
160162
.privileges(
161-
"delete_index",
162-
RolloverAction.NAME,
163-
ForceMergeAction.NAME + "*",
164-
// indices stats is used by rollover, so we need to grant it here
165-
IndicesStatsAction.NAME + "*",
166-
TransportUpdateSettingsAction.TYPE.name(),
167-
DownsampleAction.NAME,
168-
TransportAddIndexBlockAction.TYPE.name()
163+
filterNonNull(
164+
// needed to rollover failure store
165+
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
166+
"delete_index",
167+
RolloverAction.NAME,
168+
ForceMergeAction.NAME + "*",
169+
// indices stats is used by rollover, so we need to grant it here
170+
IndicesStatsAction.NAME + "*",
171+
TransportUpdateSettingsAction.TYPE.name(),
172+
DownsampleAction.NAME,
173+
TransportAddIndexBlockAction.TYPE.name()
174+
)
169175
)
170176
.allowRestrictedIndices(false)
171177
.build(),
@@ -177,14 +183,18 @@ public class InternalUsers {
177183
".fleet-fileds*"
178184
)
179185
.privileges(
180-
"delete_index",
181-
RolloverAction.NAME,
182-
ForceMergeAction.NAME + "*",
183-
// indices stats is used by rollover, so we need to grant it here
184-
IndicesStatsAction.NAME + "*",
185-
TransportUpdateSettingsAction.TYPE.name(),
186-
DownsampleAction.NAME,
187-
TransportAddIndexBlockAction.TYPE.name()
186+
filterNonNull(
187+
// needed to rollover failure store
188+
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
189+
"delete_index",
190+
RolloverAction.NAME,
191+
ForceMergeAction.NAME + "*",
192+
// indices stats is used by rollover, so we need to grant it here
193+
IndicesStatsAction.NAME + "*",
194+
TransportUpdateSettingsAction.TYPE.name(),
195+
DownsampleAction.NAME,
196+
TransportAddIndexBlockAction.TYPE.name()
197+
)
188198
)
189199
.allowRestrictedIndices(true)
190200
.build() },
@@ -248,25 +258,18 @@ public class InternalUsers {
248258
new RoleDescriptor(
249259
UsernamesField.LAZY_ROLLOVER_ROLE,
250260
new String[] {},
251-
DataStream.isFailureStoreFeatureFlagEnabled()
252-
? new RoleDescriptor.IndicesPrivileges[] {
253-
RoleDescriptor.IndicesPrivileges.builder()
254-
.indices("*")
255-
.privileges(LazyRolloverAction.NAME)
256-
.allowRestrictedIndices(true)
257-
.build(),
258-
RoleDescriptor.IndicesPrivileges.builder()
259-
.indices("*")
260-
// needed to rollover failure store
261-
.privileges("manage_failure_store")
262-
.allowRestrictedIndices(true)
263-
.build() }
264-
: new RoleDescriptor.IndicesPrivileges[] {
265-
RoleDescriptor.IndicesPrivileges.builder()
266-
.indices("*")
267-
.privileges(LazyRolloverAction.NAME)
268-
.allowRestrictedIndices(true)
269-
.build(), },
261+
new RoleDescriptor.IndicesPrivileges[] {
262+
RoleDescriptor.IndicesPrivileges.builder()
263+
.indices("*")
264+
.privileges(
265+
filterNonNull(
266+
// needed to rollover failure store
267+
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
268+
LazyRolloverAction.NAME
269+
)
270+
)
271+
.allowRestrictedIndices(true)
272+
.build() },
270273
null,
271274
null,
272275
new String[] {},
@@ -324,4 +327,8 @@ public static InternalUser getUser(String username) {
324327
}
325328
return instance;
326329
}
330+
331+
private static String[] filterNonNull(String... privileges) {
332+
return Arrays.stream(privileges).filter(Objects::nonNull).toArray(String[]::new);
333+
}
327334
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/user/InternalUsersTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ public void testDataStreamLifecycleUser() {
271271
TransportAddIndexBlockAction.TYPE.name()
272272
);
273273
final String dataStream = randomAlphaOfLengthBetween(3, 12);
274+
274275
checkIndexAccess(role, randomFrom(sampleIndexActions), dataStream, true);
275276
// Also check backing index access
276277
checkIndexAccess(
@@ -280,6 +281,15 @@ public void testDataStreamLifecycleUser() {
280281
true
281282
);
282283

284+
checkIndexAccess(role, randomFrom(sampleIndexActions), dataStream + "::failures", true);
285+
// Also check failure index access
286+
checkIndexAccess(
287+
role,
288+
randomFrom(sampleIndexActions),
289+
DataStream.FAILURE_STORE_PREFIX + dataStream + randomAlphaOfLengthBetween(4, 8),
290+
true
291+
);
292+
283293
allowedSystemDataStreams.forEach(allowedSystemDataStream -> {
284294
checkIndexAccess(role, randomFrom(sampleSystemDataStreamActions), allowedSystemDataStream, true);
285295
checkIndexAccess(
@@ -288,6 +298,14 @@ public void testDataStreamLifecycleUser() {
288298
DataStream.BACKING_INDEX_PREFIX + allowedSystemDataStream + randomAlphaOfLengthBetween(4, 8),
289299
true
290300
);
301+
302+
checkIndexAccess(role, randomFrom(sampleSystemDataStreamActions), allowedSystemDataStream + "::failures", true);
303+
checkIndexAccess(
304+
role,
305+
randomFrom(sampleSystemDataStreamActions),
306+
DataStream.FAILURE_STORE_PREFIX + allowedSystemDataStream + randomAlphaOfLengthBetween(4, 8),
307+
true
308+
);
291309
});
292310

293311
checkIndexAccess(role, randomFrom(sampleSystemDataStreamActions), randomFrom(TestRestrictedIndices.SAMPLE_RESTRICTED_NAMES), false);

0 commit comments

Comments
 (0)