3030import org .opensearch .test .framework .TestSecurityConfig ;
3131import org .opensearch .test .framework .cluster .LocalCluster ;
3232import org .opensearch .test .framework .cluster .TestRestClient ;
33+ import org .opensearch .test .framework .matcher .RestIndexMatchers ;
3334
3435import static org .hamcrest .MatcherAssert .assertThat ;
3536import static org .opensearch .test .framework .TestSecurityConfig .AuthcDomain .AUTHC_HTTPBASIC_INTERNAL ;
3637import static org .opensearch .test .framework .cluster .TestRestClient .json ;
37- import static org .opensearch .test .framework .matcher .IndexApiResponseMatchers .OnResponseIndexMatcher .containsExactly ;
38- import static org .opensearch .test .framework .matcher .IndexApiResponseMatchers .OnUserIndexMatcher .limitedTo ;
39- import static org .opensearch .test .framework .matcher .IndexApiResponseMatchers .OnUserIndexMatcher .limitedToNone ;
40- import static org .opensearch .test .framework .matcher .IndexApiResponseMatchers .OnUserIndexMatcher .unlimitedIncludingOpenSearchSecurityIndex ;
38+ import static org .opensearch .test .framework .matcher .RestIndexMatchers .OnResponseIndexMatcher .containsExactly ;
39+ import static org .opensearch .test .framework .matcher .RestIndexMatchers .OnUserIndexMatcher .limitedTo ;
40+ import static org .opensearch .test .framework .matcher .RestIndexMatchers .OnUserIndexMatcher .limitedToNone ;
41+ import static org .opensearch .test .framework .matcher .RestIndexMatchers .OnUserIndexMatcher .unlimitedIncludingOpenSearchSecurityIndex ;
4142import static org .opensearch .test .framework .matcher .RestMatchers .isForbidden ;
4243import static org .opensearch .test .framework .matcher .RestMatchers .isOk ;
4344
@@ -65,6 +66,23 @@ public class SnapshotAuthorizationIntTests {
6566 static final TestIndex index_bwx1 = TestIndex .name ("index_bwx1" ).documentCount (10 ).seed (13 ).build (); // not initially created
6667 static final TestIndex index_bwx2 = TestIndex .name ("index_bwx2" ).documentCount (10 ).seed (14 ).build (); // not initially created
6768
69+ /**
70+ * This key identifies assertion reference data for index search/read permissions of individual users.
71+ */
72+ static final TestSecurityConfig .User .MetadataKey <RestIndexMatchers .IndexMatcher > READ = new TestSecurityConfig .User .MetadataKey <>(
73+ "read" ,
74+ RestIndexMatchers .IndexMatcher .class
75+ );
76+
77+ /**
78+ * This key identifies assertion reference data for index write permissions of individual users. This does
79+ * not include index creation permissions.
80+ */
81+ static final TestSecurityConfig .User .MetadataKey <RestIndexMatchers .IndexMatcher > WRITE = new TestSecurityConfig .User .MetadataKey <>(
82+ "write" ,
83+ RestIndexMatchers .IndexMatcher .class
84+ );
85+
6886 static TestSecurityConfig .User LIMITED_USER_A = new TestSecurityConfig .User ("limited_user_A" )//
6987 .description ("index_a*" )//
7088 .roles (
@@ -75,8 +93,8 @@ public class SnapshotAuthorizationIntTests {
7593 .indexPermissions ("write" , "manage" )
7694 .on ("index_aw*" )
7795 )//
78- .indexMatcher ( "read" , limitedTo (index_a1 , index_a2 , index_awx1 , index_awx2 ))//
79- .indexMatcher ( "write" , limitedTo (index_awx1 , index_awx2 ));
96+ .reference ( READ , limitedTo (index_a1 , index_a2 , index_awx1 , index_awx2 ))//
97+ .reference ( WRITE , limitedTo (index_awx1 , index_awx2 ));
8098
8199 static TestSecurityConfig .User LIMITED_USER_B = new TestSecurityConfig .User ("limited_user_B" )//
82100 .description ("index_b*" )//
@@ -88,8 +106,8 @@ public class SnapshotAuthorizationIntTests {
88106 .indexPermissions ("write" , "manage" )
89107 .on ("index_bw*" )
90108 )//
91- .indexMatcher ( "read" , limitedTo (index_b1 , index_b2 , index_bwx1 , index_bwx2 ))//
92- .indexMatcher ( "write" , limitedTo (index_bwx1 , index_bwx2 ));
109+ .reference ( READ , limitedTo (index_b1 , index_b2 , index_bwx1 , index_bwx2 ))//
110+ .reference ( WRITE , limitedTo (index_bwx1 , index_bwx2 ));
93111
94112 static TestSecurityConfig .User LIMITED_USER_B_SYSTEM_INDEX = new TestSecurityConfig .User ("limited_user_B_system_index" )//
95113 .description ("index_b*, .system_index_plugin" )//
@@ -106,8 +124,8 @@ public class SnapshotAuthorizationIntTests {
106124 .on (".system_index_plugin_not_existing" )
107125
108126 )//
109- .indexMatcher ( "read" , limitedTo (index_b1 , index_b2 , index_bwx1 , index_bwx2 ))//
110- .indexMatcher ( "write" , limitedTo (index_bwx1 , index_bwx2 , system_index_plugin_not_existing ));
127+ .reference ( READ , limitedTo (index_b1 , index_b2 , index_bwx1 , index_bwx2 ))//
128+ .reference ( WRITE , limitedTo (index_bwx1 , index_bwx2 , system_index_plugin_not_existing ));
111129
112130 static TestSecurityConfig .User LIMITED_USER_AB = new TestSecurityConfig .User ("limited_user_AB" )//
113131 .description ("index_a*, index_b*" )//
@@ -119,17 +137,17 @@ public class SnapshotAuthorizationIntTests {
119137 .indexPermissions ("write" , "manage" )
120138 .on ("index_aw*" , "index_bw*" )
121139 )//
122- .indexMatcher ( "read" , limitedTo (index_a1 , index_a2 , index_awx1 , index_awx2 , index_b1 , index_b2 , index_bwx1 , index_bwx2 ))//
123- .indexMatcher ( "write" , limitedTo (index_awx1 , index_awx2 , index_bwx1 , index_bwx2 ));
140+ .reference ( READ , limitedTo (index_a1 , index_a2 , index_awx1 , index_awx2 , index_b1 , index_b2 , index_bwx1 , index_bwx2 ))//
141+ .reference ( WRITE , limitedTo (index_awx1 , index_awx2 , index_bwx1 , index_bwx2 ));
124142
125143 static final TestSecurityConfig .User LIMITED_USER_NONE = new TestSecurityConfig .User ("limited_user_none" )//
126144 .description ("no index privileges" )//
127145 .roles (
128146 new TestSecurityConfig .Role ("r1" )//
129147 .clusterPermissions ("cluster_composite_ops_ro" , "cluster_monitor" )
130148 )//
131- .indexMatcher ( "read" , limitedToNone ())//
132- .indexMatcher ( "write" , limitedToNone ());
149+ .reference ( READ , limitedToNone ())//
150+ .reference ( WRITE , limitedToNone ());
133151
134152 static final TestSecurityConfig .User UNLIMITED_USER = new TestSecurityConfig .User ("unlimited_user" )//
135153 .description ("unlimited" )//
@@ -140,12 +158,12 @@ public class SnapshotAuthorizationIntTests {
140158 .on ("*" )//
141159
142160 )//
143- .indexMatcher (
144- "read" ,
161+ .reference (
162+ READ ,
145163 limitedTo (index_a1 , index_a2 , index_a3 , index_awx1 , index_awx2 , index_b1 , index_b2 , index_b3 , index_bwx1 , index_bwx2 )
146164 )//
147- .indexMatcher (
148- "write" ,
165+ .reference (
166+ WRITE ,
149167 limitedTo (index_a1 , index_a2 , index_a3 , index_awx1 , index_awx2 , index_b1 , index_b2 , index_b3 , index_bwx1 , index_bwx2 )
150168 );
151169
@@ -156,8 +174,8 @@ public class SnapshotAuthorizationIntTests {
156174 static final TestSecurityConfig .User SUPER_UNLIMITED_USER = new TestSecurityConfig .User ("super_unlimited_user" )//
157175 .description ("super unlimited (admin cert)" )//
158176 .adminCertUser ()//
159- .indexMatcher ( "read" , unlimitedIncludingOpenSearchSecurityIndex ())//
160- .indexMatcher ( "write" , unlimitedIncludingOpenSearchSecurityIndex ());
177+ .reference ( READ , unlimitedIncludingOpenSearchSecurityIndex ())//
178+ .reference ( WRITE , unlimitedIncludingOpenSearchSecurityIndex ());
161179
162180 static final List <TestSecurityConfig .User > USERS = ImmutableList .of (
163181 LIMITED_USER_A ,
@@ -201,10 +219,7 @@ public void restore_singleIndex() throws Exception {
201219 "_snapshot/test_repository/single_index_snapshot/_restore?wait_for_completion=true"
202220 );
203221
204- assertThat (
205- httpResponse ,
206- containsExactly (index_awx1 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .indexMatcher ("write" ))
207- );
222+ assertThat (httpResponse , containsExactly (index_awx1 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .reference (WRITE )));
208223
209224 } finally {
210225 delete ("_snapshot/test_repository/single_index_snapshot" );
@@ -223,10 +238,7 @@ public void restore_singleIndex_rename1() throws Exception {
223238 json ("rename_pattern" , "index_(.+)x1" , "rename_replacement" , "index_$1x2" )
224239 );
225240
226- assertThat (
227- httpResponse ,
228- containsExactly (index_awx2 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .indexMatcher ("write" ))
229- );
241+ assertThat (httpResponse , containsExactly (index_awx2 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .reference (WRITE )));
230242
231243 } finally {
232244 delete ("_snapshot/test_repository/single_index_snapshot" );
@@ -245,10 +257,7 @@ public void restore_singleIndex_rename2() throws Exception {
245257 json ("rename_pattern" , "index_a(.*)" , "rename_replacement" , "index_b$1" )
246258 );
247259
248- assertThat (
249- httpResponse ,
250- containsExactly (index_bwx1 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .indexMatcher ("write" ))
251- );
260+ assertThat (httpResponse , containsExactly (index_bwx1 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .reference (WRITE )));
252261
253262 } finally {
254263 delete ("_snapshot/test_repository/single_index_snapshot" );
@@ -270,8 +279,7 @@ public void restore_singleIndex_renameToSystemIndex() throws Exception {
270279 if (clusterConfig .systemIndexPrivilegeEnabled || user == SUPER_UNLIMITED_USER ) {
271280 assertThat (
272281 httpResponse ,
273- containsExactly (system_index_plugin_not_existing ).at ("snapshot.indices" )
274- .butForbiddenIfIncomplete (user .indexMatcher ("write" ))
282+ containsExactly (system_index_plugin_not_existing ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .reference (WRITE ))
275283 );
276284 } else {
277285 assertThat (httpResponse , isForbidden ());
@@ -295,10 +303,7 @@ public void restore_singleIndexFromAllIndices() throws Exception {
295303 json ("indices" , "index_awx1" )
296304 );
297305
298- assertThat (
299- httpResponse ,
300- containsExactly (index_awx1 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .indexMatcher ("write" ))
301- );
306+ assertThat (httpResponse , containsExactly (index_awx1 ).at ("snapshot.indices" ).butForbiddenIfIncomplete (user .reference (WRITE )));
302307
303308 } finally {
304309 delete ("_snapshot/test_repository/all_index_snapshot" );
0 commit comments