3636import org .elasticsearch .xpack .core .security .authz .RoleDescriptor ;
3737import org .elasticsearch .xpack .core .security .support .MetadataUtils ;
3838
39+ import java .util .Arrays ;
3940import java .util .Collection ;
4041import java .util .Collections ;
4142import java .util .Map ;
43+ import java .util .Objects ;
4244import java .util .function .Function ;
4345import java .util .stream .Collectors ;
4446import 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}
0 commit comments