@@ -483,10 +483,8 @@ public static void buildRoleFromDescriptors(
483483 final List <ConfigurableClusterPrivilege > configurableClusterPrivileges = new ArrayList <>();
484484 final Set <String > runAs = new HashSet <>();
485485
486- final Map <Set <String >, MergeableIndicesPrivilege > indicesPrivilegesDataMap = new HashMap <>();
487- final Map <Set <String >, MergeableIndicesPrivilege > indicesPrivilegesFailuresMap = new HashMap <>();
488- final Map <Set <String >, MergeableIndicesPrivilege > restrictedIndicesPrivilegesDataMap = new HashMap <>();
489- final Map <Set <String >, MergeableIndicesPrivilege > restrictedIndicesPrivilegesFailuresMap = new HashMap <>();
486+ final Map <Set <String >, MergeableIndicesPrivilege > indicesPrivilegesMap = new HashMap <>();
487+ final Map <Set <String >, MergeableIndicesPrivilege > restrictedIndicesPrivilegesMap = new HashMap <>();
490488
491489 final Map <Set <String >, Set <IndicesPrivileges >> remoteIndicesPrivilegesByCluster = new HashMap <>();
492490
@@ -507,30 +505,8 @@ public static void buildRoleFromDescriptors(
507505 runAs .addAll (Arrays .asList (descriptor .getRunAs ()));
508506 }
509507
510- MergeableIndicesPrivilege .collatePrivilegesByIndices (
511- descriptor .getIndicesPrivileges (),
512- true ,
513- IndexComponentSelector .DATA ,
514- restrictedIndicesPrivilegesDataMap
515- );
516- MergeableIndicesPrivilege .collatePrivilegesByIndices (
517- descriptor .getIndicesPrivileges (),
518- false ,
519- IndexComponentSelector .DATA ,
520- indicesPrivilegesDataMap
521- );
522- MergeableIndicesPrivilege .collatePrivilegesByIndices (
523- descriptor .getIndicesPrivileges (),
524- true ,
525- IndexComponentSelector .FAILURES ,
526- restrictedIndicesPrivilegesFailuresMap
527- );
528- MergeableIndicesPrivilege .collatePrivilegesByIndices (
529- descriptor .getIndicesPrivileges (),
530- false ,
531- IndexComponentSelector .FAILURES ,
532- indicesPrivilegesFailuresMap
533- );
508+ MergeableIndicesPrivilege .collatePrivilegesByIndices (descriptor .getIndicesPrivileges (), true , restrictedIndicesPrivilegesMap );
509+ MergeableIndicesPrivilege .collatePrivilegesByIndices (descriptor .getIndicesPrivileges (), false , indicesPrivilegesMap );
534510
535511 if (descriptor .hasRemoteIndicesPrivileges ()) {
536512 groupIndexPrivilegesByCluster (descriptor .getRemoteIndicesPrivileges (), remoteIndicesPrivilegesByCluster );
@@ -563,47 +539,57 @@ public static void buildRoleFromDescriptors(
563539 final Role .Builder builder = Role .builder (restrictedIndices , roleNames .toArray (Strings .EMPTY_ARRAY ))
564540 .cluster (clusterPrivileges , configurableClusterPrivileges )
565541 .runAs (runAsPrivilege );
566- indicesPrivilegesDataMap .forEach ((key , privilege ) -> {
567- builder .add (
568- fieldPermissionsCache .getFieldPermissions (privilege .fieldPermissionsDefinition ),
569- privilege .query ,
570- IndexPrivilege .get (privilege .privileges ),
571- false ,
572- IndexComponentSelector .DATA ,
573- privilege .indices .toArray (Strings .EMPTY_ARRAY )
574- );
575542
576- });
577- restrictedIndicesPrivilegesDataMap .forEach ((key , privilege ) -> {
578- // For a privilege with both failure and non-failure indices, we need to split them into two separate groups
579- builder .add (
580- fieldPermissionsCache .getFieldPermissions (privilege .fieldPermissionsDefinition ),
581- privilege .query ,
582- IndexPrivilege .get (privilege .privileges ),
583- true ,
584- IndexComponentSelector .DATA ,
585- privilege .indices .toArray (Strings .EMPTY_ARRAY )
586- );
587- });
588- indicesPrivilegesFailuresMap .forEach ((key , privilege ) -> {
543+ indicesPrivilegesMap .forEach ((key , privilege ) -> {
544+ if (privilege .privileges .contains ("read_failures" )) {
545+ builder .add (
546+ fieldPermissionsCache .getFieldPermissions (privilege .fieldPermissionsDefinition ),
547+ privilege .query ,
548+ IndexPrivilege .get (Set .of ("read_failures" )),
549+ false ,
550+ IndexComponentSelector .FAILURES ,
551+ privilege .indices .toArray (Strings .EMPTY_ARRAY )
552+ );
553+ }
554+ Set <String > privilegesWithoutReadFailures = filterOutReadFailures (privilege .privileges );
555+ if (privilegesWithoutReadFailures .isEmpty ()) {
556+ return ;
557+ }
589558 builder .add (
590559 fieldPermissionsCache .getFieldPermissions (privilege .fieldPermissionsDefinition ),
591560 privilege .query ,
592- IndexPrivilege .get (privilege . privileges ),
561+ IndexPrivilege .get (privilegesWithoutReadFailures ),
593562 false ,
594- IndexComponentSelector .FAILURES ,
563+ (privilege .privileges .contains ("all" ) || privilege .privileges .contains ("ALL" ))
564+ ? IndexComponentSelector .ALL_APPLICABLE
565+ : IndexComponentSelector .DATA ,
595566 privilege .indices .toArray (Strings .EMPTY_ARRAY )
596567 );
597568
598569 });
599- restrictedIndicesPrivilegesFailuresMap .forEach ((key , privilege ) -> {
600- // For a privilege with both failure and non-failure indices, we need to split them into two separate groups
570+ restrictedIndicesPrivilegesMap .forEach ((key , privilege ) -> {
571+ if (privilege .privileges .contains ("read_failures" )) {
572+ builder .add (
573+ fieldPermissionsCache .getFieldPermissions (privilege .fieldPermissionsDefinition ),
574+ privilege .query ,
575+ IndexPrivilege .get (Set .of ("read_failures" )),
576+ true ,
577+ IndexComponentSelector .FAILURES ,
578+ privilege .indices .toArray (Strings .EMPTY_ARRAY )
579+ );
580+ }
581+ Set <String > privilegesWithoutReadFailures = filterOutReadFailures (privilege .privileges );
582+ if (privilegesWithoutReadFailures .isEmpty ()) {
583+ return ;
584+ }
601585 builder .add (
602586 fieldPermissionsCache .getFieldPermissions (privilege .fieldPermissionsDefinition ),
603587 privilege .query ,
604588 IndexPrivilege .get (privilege .privileges ),
605589 true ,
606- IndexComponentSelector .FAILURES ,
590+ (privilege .privileges .contains ("all" ) || privilege .privileges .contains ("ALL" ))
591+ ? IndexComponentSelector .ALL_APPLICABLE
592+ : IndexComponentSelector .DATA ,
607593 privilege .indices .toArray (Strings .EMPTY_ARRAY )
608594 );
609595 });
@@ -656,6 +642,10 @@ public static void buildRoleFromDescriptors(
656642 }
657643 }
658644
645+ private static Set <String > filterOutReadFailures (Set <String > privileges ) {
646+ return privileges .stream ().filter (p -> p .equals ("read_failures" ) == false ).collect (Collectors .toSet ());
647+ }
648+
659649 public void invalidateAll () {
660650 numInvalidation .incrementAndGet ();
661651 negativeLookupCache .invalidateAll ();
@@ -766,7 +756,6 @@ void merge(MergeableIndicesPrivilege other) {
766756 private static void collatePrivilegesByIndices (
767757 final IndicesPrivileges [] indicesPrivileges ,
768758 final boolean allowsRestrictedIndices ,
769- final IndexComponentSelector selector ,
770759 final Map <Set <String >, MergeableIndicesPrivilege > indicesPrivilegesMap
771760 ) {
772761 // if an index privilege is an explicit denial, then we treat it as non-existent since we skipped these in the past when
@@ -780,9 +769,6 @@ private static void collatePrivilegesByIndices(
780769 if (indicesPrivilege .allowRestrictedIndices () != allowsRestrictedIndices ) {
781770 continue ;
782771 }
783- if (false == indicesPrivilege .matchesSelector (selector )) {
784- continue ;
785- }
786772 final Set <String > key = newHashSet (indicesPrivilege .getIndices ());
787773 indicesPrivilegesMap .compute (key , (k , value ) -> {
788774 if (value == null ) {
0 commit comments