@@ -929,6 +929,37 @@ public void hasExplicitIndexPrivilege_errors() throws Exception {
929
929
.startsWith ("Exceptions encountered during privilege evaluation:\n " + "Error while evaluating role role_with_errors" )
930
930
);
931
931
}
932
+
933
+ @ Test
934
+ public void aliasesOnDataStreamBackingIndices () throws Exception {
935
+ // We create a meta data object with a data stream ds_a. Implicitly, the utility method will create
936
+ // the backing indices ".ds-ds_a-000001", ".ds-ds_a-000002" and ".ds-ds_a-000003".
937
+ // Additionally, we create an alias which only contains ".ds-ds_a-000001", but not the other backing indices.
938
+ Map <String , IndexAbstraction > metadata = dataStreams ("ds_a" ).alias ("alias_a" ).of (".ds-ds_a-000001" ).build ().getIndicesLookup ();
939
+ SecurityDynamicConfiguration <RoleV7 > roles = SecurityDynamicConfiguration .fromYaml (
940
+ "role:\n "
941
+ + " index_permissions:\n "
942
+ + " - index_patterns: ['alias_a']\n "
943
+ + " allowed_actions: ['indices:data/write/index']" ,
944
+ CType .ROLES
945
+ );
946
+ ActionPrivileges subject = new ActionPrivileges (roles , FlattenedActionGroups .EMPTY , () -> metadata , Settings .EMPTY );
947
+ subject .updateStatefulIndexPrivileges (metadata , 2 );
948
+
949
+ PrivilegesEvaluatorResponse resultForIndexCoveredByAlias = subject .hasIndexPrivilege (
950
+ ctx ("role" ),
951
+ Set .of ("indices:data/write/index" ),
952
+ IndexResolverReplacer .Resolved .ofIndex (".ds-ds_a-000001" )
953
+ );
954
+ assertThat (resultForIndexCoveredByAlias , isAllowed ());
955
+
956
+ PrivilegesEvaluatorResponse resultForIndexNotCoveredByAlias = subject .hasIndexPrivilege (
957
+ ctx ("role" ),
958
+ Set .of ("indices:data/write/index" ),
959
+ IndexResolverReplacer .Resolved .ofIndex (".ds-ds_a-000002" )
960
+ );
961
+ assertThat (resultForIndexNotCoveredByAlias , isForbidden ());
962
+ }
932
963
}
933
964
934
965
/**
0 commit comments