@@ -872,53 +872,44 @@ static AuthorizedIndices resolveAuthorizedIndicesFromRole(
872872 final boolean includeDataStreams = (request instanceof IndicesRequest ) && ((IndicesRequest ) request ).includeDataStreams ();
873873 return new AuthorizedIndices (() -> {
874874 Consumer <Collection <String >> timeChecker = timerSupplier .get ();
875- Map <String , String > indicesAndAliasesWithSelectors = new HashMap <>();
875+ Set <String > indicesAndAliases = new HashSet <>();
876876 // TODO: can this be done smarter? I think there are usually more indices/aliases in the cluster then indices defined a roles?
877877 if (includeDataStreams ) {
878878 for (IndexAbstraction indexAbstraction : lookup .values ()) {
879879 // TODO this can be cleaned up and optimized to avoid two full predicate checks
880880 final boolean dataAccess = predicate .test (indexAbstraction , IndexComponentSelector .DATA .getKey ());
881- final boolean failureAccess = predicate .test (indexAbstraction , IndexComponentSelector .FAILURES .getKey ());
882- if (indexAbstraction .getType () == IndexAbstraction .Type .DATA_STREAM ) {
883- // add data stream and its backing indices for any authorized data streams
884- if (dataAccess ) {
885- for (Index index : indexAbstraction .getIndices ()) {
886- indicesAndAliasesWithSelectors .put (index .getName (), IndexComponentSelector .DATA .getKey ());
881+ // TODO should we still add data stream if it only has failure access?
882+ final boolean failureAccess = indexAbstraction .getType () == IndexAbstraction .Type .DATA_STREAM
883+ && predicate .test (indexAbstraction , IndexComponentSelector .FAILURES .getKey ());
884+ if (dataAccess || failureAccess ) {
885+ indicesAndAliases .add (indexAbstraction .getName ());
886+ if (indexAbstraction .getType () == IndexAbstraction .Type .DATA_STREAM ) {
887+ if (dataAccess ) {
888+ for (Index index : indexAbstraction .getIndices ()) {
889+ indicesAndAliases .add (index .getName ());
890+ }
887891 }
888- }
889- if ( failureAccess ) {
890- for ( Index index : (( DataStream ) indexAbstraction ). getFailureIndices ()) {
891- // failure indices are still accessed as "data"
892- indicesAndAliasesWithSelectors . put ( index . getName (), IndexComponentSelector . DATA . getKey ());
892+ if ( failureAccess ) {
893+ for ( Index index : (( DataStream ) indexAbstraction ). getFailureIndices () ) {
894+ // failure indices are still accessed as "data"
895+ indicesAndAliases . add ( index . getName ());
896+ }
893897 }
894898 }
899+
895900 }
896- if (dataAccess || failureAccess ) {
897- if (dataAccess && failureAccess ) {
898- indicesAndAliasesWithSelectors .put (indexAbstraction .getName (), IndexComponentSelector .ALL_APPLICABLE .getKey ());
899- } else if (dataAccess ) {
900- indicesAndAliasesWithSelectors .put (indexAbstraction .getName (), IndexComponentSelector .DATA .getKey ());
901- } else {
902- indicesAndAliasesWithSelectors .put (indexAbstraction .getName (), IndexComponentSelector .FAILURES .getKey ());
903- }
904- }
905- // TODO do we need this?
906- // else if (indexAbstraction.isConcreteFailureIndexOfDataStream()
907- // && predicate.test(indexAbstraction.getParentDataStream(), IndexComponentSelector.FAILURES.getKey())) {
908- // indicesAndAliasesWithSelectors.put(indexAbstraction.getName(), IndexComponentSelector.DATA.getKey());
909- // }
910901 }
911902 } else {
912903 // TODO do we still need to handle failure indices here?
913904 for (IndexAbstraction indexAbstraction : lookup .values ()) {
914905 if (indexAbstraction .getType () != IndexAbstraction .Type .DATA_STREAM
915906 && predicate .test (indexAbstraction , IndexComponentSelector .DATA .getKey ())) {
916- indicesAndAliasesWithSelectors . put (indexAbstraction .getName (), IndexComponentSelector . DATA . getKey ());
907+ indicesAndAliases . add (indexAbstraction .getName ());
917908 }
918909 }
919910 }
920- timeChecker .accept (indicesAndAliasesWithSelectors . keySet () );
921- return indicesAndAliasesWithSelectors ;
911+ timeChecker .accept (indicesAndAliases );
912+ return indicesAndAliases ;
922913 }, (name , selector ) -> {
923914 final IndexAbstraction indexAbstraction = lookup .get (name );
924915 if (indexAbstraction == null ) {
@@ -930,6 +921,10 @@ static AuthorizedIndices resolveAuthorizedIndicesFromRole(
930921 // We check the parent data stream first if there is one. For testing requested indices, this is most likely
931922 // more efficient than checking the index name first because we recommend grant privileges over data stream
932923 // instead of backing indices.
924+ if (indexAbstraction .isConcreteFailureIndexOfDataStream ()
925+ && predicate .test (indexAbstraction .getParentDataStream (), IndexComponentSelector .FAILURES .getKey ())) {
926+ return true ;
927+ }
933928 return (indexAbstraction .getParentDataStream () != null && predicate .test (indexAbstraction .getParentDataStream (), selector ))
934929 || predicate .test (indexAbstraction , selector );
935930 }
@@ -1058,25 +1053,16 @@ private static boolean isAsyncRelatedAction(String action) {
10581053
10591054 static final class AuthorizedIndices implements AuthorizationEngine .AuthorizedIndices {
10601055
1061- private final CachedSupplier <Map < String , String >> allAuthorizedAndAvailableWithSelectors ;
1056+ private final CachedSupplier <Set < String >> allAuthorizedAndAvailableWithSelectors ;
10621057 private final BiPredicate <String , String > isAuthorizedPredicate ;
10631058
1064- AuthorizedIndices (
1065- Supplier <Map <String , String >> allAuthorizedAndAvailableWithSelectors ,
1066- BiPredicate <String , String > isAuthorizedPredicate
1067- ) {
1068- this .allAuthorizedAndAvailableWithSelectors = CachedSupplier .wrap (allAuthorizedAndAvailableWithSelectors );
1059+ AuthorizedIndices (Supplier <Set <String >> allAuthorizedAndAvailable , BiPredicate <String , String > isAuthorizedPredicate ) {
1060+ this .allAuthorizedAndAvailableWithSelectors = CachedSupplier .wrap (allAuthorizedAndAvailable );
10691061 this .isAuthorizedPredicate = Objects .requireNonNull (isAuthorizedPredicate );
10701062 }
10711063
1072- // TODO remove me
1073- @ Override
1074- public Supplier <Set <String >> allLegacy () {
1075- return () -> allAuthorizedAndAvailableWithSelectors .get ().keySet ();
1076- }
1077-
10781064 @ Override
1079- public Supplier <Map < String , String >> all () {
1065+ public Supplier <Set < String >> all () {
10801066 return allAuthorizedAndAvailableWithSelectors ;
10811067 }
10821068
0 commit comments