| 
29 | 29 | import java.util.function.Supplier;  | 
30 | 30 | 
 
  | 
31 | 31 | import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;  | 
 | 32 | +import static org.elasticsearch.indices.SystemIndices.EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY;  | 
32 | 33 | import static org.elasticsearch.indices.SystemIndices.SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY;  | 
33 | 34 | import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;  | 
34 | 35 | import static org.hamcrest.Matchers.contains;  | 
@@ -218,18 +219,6 @@ public void testIsIndexVisible() {  | 
218 | 219 |         assertThat(isIndexVisible("data-stream1", "failures"), is(true));  | 
219 | 220 |     }  | 
220 | 221 | 
 
  | 
221 |  | -    private boolean isIndexVisible(String index, String selector) {  | 
222 |  | -        return IndexAbstractionResolver.isIndexVisible(  | 
223 |  | -            "*",  | 
224 |  | -            selector,  | 
225 |  | -            index,  | 
226 |  | -            IndicesOptions.strictExpandHidden(),  | 
227 |  | -            metadata,  | 
228 |  | -            indexNameExpressionResolver,  | 
229 |  | -            true  | 
230 |  | -        );  | 
231 |  | -    }  | 
232 |  | - | 
233 | 222 |     public void testIsNetNewSystemIndexVisible() {  | 
234 | 223 |         final Settings settings = Settings.builder()  | 
235 | 224 |             .put("index.number_of_replicas", 0)  | 
@@ -269,16 +258,71 @@ public void testIsNetNewSystemIndexVisible() {  | 
269 | 258 |             List.of(new SystemIndices.Feature("name", "description", List.of(fooDescriptor, barDescriptor)))  | 
270 | 259 |         );  | 
271 | 260 | 
 
  | 
272 |  | -        final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);  | 
273 |  | -        threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false");  | 
274 |  | -        indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);  | 
275 |  | -        indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);  | 
276 |  | - | 
277 | 261 |         metadata = Metadata.builder().put(foo, true).put(barReindexed, true).put(other, true).build();  | 
278 | 262 | 
 
  | 
279 |  | -        assertThat(isIndexVisible("other", "*"), is(true));  | 
280 |  | -        assertThat(isIndexVisible(".foo", "*"), is(false));  | 
281 |  | -        assertThat(isIndexVisible(".bar", "*"), is(false));  | 
 | 263 | +        // these indices options are for the GET _data_streams case  | 
 | 264 | +        final IndicesOptions noHiddenNoAliases = IndicesOptions.builder()  | 
 | 265 | +            .wildcardOptions(  | 
 | 266 | +                IndicesOptions.WildcardOptions.builder()  | 
 | 267 | +                    .matchOpen(true)  | 
 | 268 | +                    .matchClosed(true)  | 
 | 269 | +                    .includeHidden(false)  | 
 | 270 | +                    .resolveAliases(false)  | 
 | 271 | +                    .build()  | 
 | 272 | +            )  | 
 | 273 | +            .build();  | 
 | 274 | + | 
 | 275 | +        {  | 
 | 276 | +            final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);  | 
 | 277 | +            threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "true");  | 
 | 278 | +            indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);  | 
 | 279 | +            indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);  | 
 | 280 | + | 
 | 281 | +            // this covers the GET * case -- with system access, you can see everything  | 
 | 282 | +            assertThat(isIndexVisible("other", "*"), is(true));  | 
 | 283 | +            assertThat(isIndexVisible(".foo", "*"), is(true));  | 
 | 284 | +            assertThat(isIndexVisible(".bar", "*"), is(true));  | 
 | 285 | + | 
 | 286 | +            // but if you don't ask for hidden and aliases, you won't see hidden indices or aliases, naturally  | 
 | 287 | +            assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true));  | 
 | 288 | +            assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false));  | 
 | 289 | +            assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false));  | 
 | 290 | +        }  | 
 | 291 | + | 
 | 292 | +        {  | 
 | 293 | +            final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);  | 
 | 294 | +            threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false");  | 
 | 295 | +            indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);  | 
 | 296 | +            indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);  | 
 | 297 | + | 
 | 298 | +            // this covers the GET * case -- without system access, you can't see everything  | 
 | 299 | +            assertThat(isIndexVisible("other", "*"), is(true));  | 
 | 300 | +            assertThat(isIndexVisible(".foo", "*"), is(false));  | 
 | 301 | +            assertThat(isIndexVisible(".bar", "*"), is(false));  | 
 | 302 | + | 
 | 303 | +            // no difference here in the datastream case, you can't see these then, either  | 
 | 304 | +            assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true));  | 
 | 305 | +            assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false));  | 
 | 306 | +            assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false));  | 
 | 307 | +        }  | 
 | 308 | + | 
 | 309 | +        {  | 
 | 310 | +            final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);  | 
 | 311 | +            threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "true");  | 
 | 312 | +            threadContext.putHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "some-elastic-product");  | 
 | 313 | +            indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);  | 
 | 314 | +            indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);  | 
 | 315 | + | 
 | 316 | +            // this covers the GET * case -- with product (only) access, you can't see everything  | 
 | 317 | +            assertThat(isIndexVisible("other", "*"), is(true));  | 
 | 318 | +            assertThat(isIndexVisible(".foo", "*"), is(false));  | 
 | 319 | +            assertThat(isIndexVisible(".bar", "*"), is(false));  | 
 | 320 | + | 
 | 321 | +            // no difference here in the datastream case, you can't see these then, either  | 
 | 322 | +            assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true));  | 
 | 323 | +            assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false));  | 
 | 324 | +            assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false));  | 
 | 325 | +        }  | 
282 | 326 |     }  | 
283 | 327 | 
 
  | 
284 | 328 |     private static XContentBuilder mappings() {  | 
@@ -306,4 +350,12 @@ private List<String> resolveAbstractionsSelectorAllowed(List<String> expressions  | 
306 | 350 |     private List<String> resolveAbstractions(List<String> expressions, IndicesOptions indicesOptions, Supplier<Set<String>> mask) {  | 
307 | 351 |         return indexAbstractionResolver.resolveIndexAbstractions(expressions, indicesOptions, metadata, mask, (idx) -> true, true);  | 
308 | 352 |     }  | 
 | 353 | + | 
 | 354 | +    private boolean isIndexVisible(String index, String selector) {  | 
 | 355 | +        return isIndexVisible(index, selector, IndicesOptions.strictExpandHidden());  | 
 | 356 | +    }  | 
 | 357 | + | 
 | 358 | +    private boolean isIndexVisible(String index, String selector, IndicesOptions indicesOptions) {  | 
 | 359 | +        return IndexAbstractionResolver.isIndexVisible("*", selector, index, indicesOptions, metadata, indexNameExpressionResolver, true);  | 
 | 360 | +    }  | 
309 | 361 | }  | 
0 commit comments