Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
import org.elasticsearch.xpack.core.security.support.MetadataUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -157,14 +159,18 @@ public class InternalUsers {
RoleDescriptor.IndicesPrivileges.builder()
.indices("*")
.privileges(
"delete_index",
RolloverAction.NAME,
ForceMergeAction.NAME + "*",
// indices stats is used by rollover, so we need to grant it here
IndicesStatsAction.NAME + "*",
TransportUpdateSettingsAction.TYPE.name(),
DownsampleAction.NAME,
TransportAddIndexBlockAction.TYPE.name()
filterNonNull(
// needed to rollover failure store
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
"delete_index",
RolloverAction.NAME,
ForceMergeAction.NAME + "*",
// indices stats is used by rollover, so we need to grant it here
IndicesStatsAction.NAME + "*",
TransportUpdateSettingsAction.TYPE.name(),
DownsampleAction.NAME,
TransportAddIndexBlockAction.TYPE.name()
)
)
.allowRestrictedIndices(false)
.build(),
Expand All @@ -176,14 +182,18 @@ public class InternalUsers {
".fleet-fileds*"
)
.privileges(
"delete_index",
RolloverAction.NAME,
ForceMergeAction.NAME + "*",
// indices stats is used by rollover, so we need to grant it here
IndicesStatsAction.NAME + "*",
TransportUpdateSettingsAction.TYPE.name(),
DownsampleAction.NAME,
TransportAddIndexBlockAction.TYPE.name()
filterNonNull(
// needed to rollover failure store
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
"delete_index",
RolloverAction.NAME,
ForceMergeAction.NAME + "*",
// indices stats is used by rollover, so we need to grant it here
IndicesStatsAction.NAME + "*",
TransportUpdateSettingsAction.TYPE.name(),
DownsampleAction.NAME,
TransportAddIndexBlockAction.TYPE.name()
)
)
.allowRestrictedIndices(true)
.build() },
Expand Down Expand Up @@ -246,25 +256,18 @@ public class InternalUsers {
new RoleDescriptor(
UsernamesField.LAZY_ROLLOVER_ROLE,
new String[] {},
DataStream.isFailureStoreFeatureFlagEnabled()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just refactoring, no actual changes for this user.

? new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder()
.indices("*")
.privileges(LazyRolloverAction.NAME)
.allowRestrictedIndices(true)
.build(),
RoleDescriptor.IndicesPrivileges.builder()
.indices("*")
// needed to rollover failure store
.privileges("manage_failure_store")
.allowRestrictedIndices(true)
.build() }
: new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder()
.indices("*")
.privileges(LazyRolloverAction.NAME)
.allowRestrictedIndices(true)
.build(), },
new RoleDescriptor.IndicesPrivileges[] {
RoleDescriptor.IndicesPrivileges.builder()
.indices("*")
.privileges(
filterNonNull(
// needed to rollover failure store
DataStream.isFailureStoreFeatureFlagEnabled() ? "manage_failure_store" : null,
LazyRolloverAction.NAME
)
)
.allowRestrictedIndices(true)
.build() },
null,
null,
new String[] {},
Expand Down Expand Up @@ -322,4 +325,8 @@ public static InternalUser getUser(String username) {
}
return instance;
}

private static String[] filterNonNull(String... privileges) {
return Arrays.stream(privileges).filter(Objects::nonNull).toArray(String[]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public void testDataStreamLifecycleUser() {
TransportAddIndexBlockAction.TYPE.name()
);
final String dataStream = randomAlphaOfLengthBetween(3, 12);

checkIndexAccess(role, randomFrom(sampleIndexActions), dataStream, true);
// Also check backing index access
checkIndexAccess(
Expand All @@ -280,6 +281,15 @@ public void testDataStreamLifecycleUser() {
true
);

checkIndexAccess(role, randomFrom(sampleIndexActions), dataStream + "::failures", true);
// Also check failure index access
checkIndexAccess(
role,
randomFrom(sampleIndexActions),
DataStream.FAILURE_STORE_PREFIX + dataStream + randomAlphaOfLengthBetween(4, 8),
true
);

allowedSystemDataStreams.forEach(allowedSystemDataStream -> {
checkIndexAccess(role, randomFrom(sampleSystemDataStreamActions), allowedSystemDataStream, true);
checkIndexAccess(
Expand All @@ -288,6 +298,14 @@ public void testDataStreamLifecycleUser() {
DataStream.BACKING_INDEX_PREFIX + allowedSystemDataStream + randomAlphaOfLengthBetween(4, 8),
true
);

checkIndexAccess(role, randomFrom(sampleSystemDataStreamActions), allowedSystemDataStream + "::failures", true);
checkIndexAccess(
role,
randomFrom(sampleSystemDataStreamActions),
DataStream.FAILURE_STORE_PREFIX + allowedSystemDataStream + randomAlphaOfLengthBetween(4, 8),
true
);
});

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