Skip to content

Commit fa46aab

Browse files
authored
[Failure Store] Access for internal users (#125660)
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
1 parent d84eb1f commit fa46aab

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
@@ -35,9 +35,11 @@
3535
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
3636
import org.elasticsearch.xpack.core.security.support.MetadataUtils;
3737

38+
import java.util.Arrays;
3839
import java.util.Collection;
3940
import java.util.Collections;
4041
import java.util.Map;
42+
import java.util.Objects;
4143
import java.util.function.Function;
4244
import java.util.stream.Collectors;
4345
import java.util.stream.Stream;
@@ -157,14 +159,18 @@ public class InternalUsers {
157159
RoleDescriptor.IndicesPrivileges.builder()
158160
.indices("*")
159161
.privileges(
160-
"delete_index",
161-
RolloverAction.NAME,
162-
ForceMergeAction.NAME + "*",
163-
// indices stats is used by rollover, so we need to grant it here
164-
IndicesStatsAction.NAME + "*",
165-
TransportUpdateSettingsAction.TYPE.name(),
166-
DownsampleAction.NAME,
167-
TransportAddIndexBlockAction.TYPE.name()
162+
filterNonNull(
163+
// needed to rollover failure store
164+
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
165+
"delete_index",
166+
RolloverAction.NAME,
167+
ForceMergeAction.NAME + "*",
168+
// indices stats is used by rollover, so we need to grant it here
169+
IndicesStatsAction.NAME + "*",
170+
TransportUpdateSettingsAction.TYPE.name(),
171+
DownsampleAction.NAME,
172+
TransportAddIndexBlockAction.TYPE.name()
173+
)
168174
)
169175
.allowRestrictedIndices(false)
170176
.build(),
@@ -176,14 +182,18 @@ public class InternalUsers {
176182
".fleet-fileds*"
177183
)
178184
.privileges(
179-
"delete_index",
180-
RolloverAction.NAME,
181-
ForceMergeAction.NAME + "*",
182-
// indices stats is used by rollover, so we need to grant it here
183-
IndicesStatsAction.NAME + "*",
184-
TransportUpdateSettingsAction.TYPE.name(),
185-
DownsampleAction.NAME,
186-
TransportAddIndexBlockAction.TYPE.name()
185+
filterNonNull(
186+
// needed to rollover failure store
187+
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
188+
"delete_index",
189+
RolloverAction.NAME,
190+
ForceMergeAction.NAME + "*",
191+
// indices stats is used by rollover, so we need to grant it here
192+
IndicesStatsAction.NAME + "*",
193+
TransportUpdateSettingsAction.TYPE.name(),
194+
DownsampleAction.NAME,
195+
TransportAddIndexBlockAction.TYPE.name()
196+
)
187197
)
188198
.allowRestrictedIndices(true)
189199
.build() },
@@ -246,25 +256,18 @@ public class InternalUsers {
246256
new RoleDescriptor(
247257
UsernamesField.LAZY_ROLLOVER_ROLE,
248258
new String[] {},
249-
DataStream.isFailureStoreFeatureFlagEnabled()
250-
? new RoleDescriptor.IndicesPrivileges[] {
251-
RoleDescriptor.IndicesPrivileges.builder()
252-
.indices("*")
253-
.privileges(LazyRolloverAction.NAME)
254-
.allowRestrictedIndices(true)
255-
.build(),
256-
RoleDescriptor.IndicesPrivileges.builder()
257-
.indices("*")
258-
// needed to rollover failure store
259-
.privileges("manage_failure_store")
260-
.allowRestrictedIndices(true)
261-
.build() }
262-
: new RoleDescriptor.IndicesPrivileges[] {
263-
RoleDescriptor.IndicesPrivileges.builder()
264-
.indices("*")
265-
.privileges(LazyRolloverAction.NAME)
266-
.allowRestrictedIndices(true)
267-
.build(), },
259+
new RoleDescriptor.IndicesPrivileges[] {
260+
RoleDescriptor.IndicesPrivileges.builder()
261+
.indices("*")
262+
.privileges(
263+
filterNonNull(
264+
// needed to rollover failure store
265+
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
266+
LazyRolloverAction.NAME
267+
)
268+
)
269+
.allowRestrictedIndices(true)
270+
.build() },
268271
null,
269272
null,
270273
new String[] {},
@@ -322,4 +325,8 @@ public static InternalUser getUser(String username) {
322325
}
323326
return instance;
324327
}
328+
329+
private static String[] filterNonNull(String... privileges) {
330+
return Arrays.stream(privileges).filter(Objects::nonNull).toArray(String[]::new);
331+
}
325332
}

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)