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