|
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
|
|
|
+import static org.elasticsearch.indices.SystemIndices.EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY;
|
|
|
import static org.elasticsearch.indices.SystemIndices.SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY;
|
|
|
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
|
|
|
import static org.hamcrest.Matchers.contains;
|
|
@@ -218,18 +219,6 @@ public class IndexAbstractionResolverTests extends ESTestCase {
|
|
|
assertThat(isIndexVisible("data-stream1", "failures"), is(true));
|
|
|
}
|
|
|
|
|
|
- private boolean isIndexVisible(String index, String selector) {
|
|
|
- return IndexAbstractionResolver.isIndexVisible(
|
|
|
- "*",
|
|
|
- selector,
|
|
|
- index,
|
|
|
- IndicesOptions.strictExpandHidden(),
|
|
|
- metadata,
|
|
|
- indexNameExpressionResolver,
|
|
|
- true
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
public void testIsNetNewSystemIndexVisible() {
|
|
|
final Settings settings = Settings.builder()
|
|
|
.put("index.number_of_replicas", 0)
|
|
@@ -269,16 +258,71 @@ public class IndexAbstractionResolverTests extends ESTestCase {
|
|
|
List.of(new SystemIndices.Feature("name", "description", List.of(fooDescriptor, barDescriptor)))
|
|
|
);
|
|
|
|
|
|
- final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
|
|
- threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false");
|
|
|
- indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);
|
|
|
- indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);
|
|
|
-
|
|
|
metadata = Metadata.builder().put(foo, true).put(barReindexed, true).put(other, true).build();
|
|
|
|
|
|
- assertThat(isIndexVisible("other", "*"), is(true));
|
|
|
- assertThat(isIndexVisible(".foo", "*"), is(false));
|
|
|
- assertThat(isIndexVisible(".bar", "*"), is(false));
|
|
|
+ // these indices options are for the GET _data_streams case
|
|
|
+ final IndicesOptions noHiddenNoAliases = IndicesOptions.builder()
|
|
|
+ .wildcardOptions(
|
|
|
+ IndicesOptions.WildcardOptions.builder()
|
|
|
+ .matchOpen(true)
|
|
|
+ .matchClosed(true)
|
|
|
+ .includeHidden(false)
|
|
|
+ .resolveAliases(false)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ .build();
|
|
|
+
|
|
|
+ {
|
|
|
+ final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
|
|
+ threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "true");
|
|
|
+ indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);
|
|
|
+ indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);
|
|
|
+
|
|
|
+ // this covers the GET * case -- with system access, you can see everything
|
|
|
+ assertThat(isIndexVisible("other", "*"), is(true));
|
|
|
+ assertThat(isIndexVisible(".foo", "*"), is(true));
|
|
|
+ assertThat(isIndexVisible(".bar", "*"), is(true));
|
|
|
+
|
|
|
+ // but if you don't ask for hidden and aliases, you won't see hidden indices or aliases, naturally
|
|
|
+ assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true));
|
|
|
+ assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false));
|
|
|
+ assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false));
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
|
|
+ threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false");
|
|
|
+ indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);
|
|
|
+ indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);
|
|
|
+
|
|
|
+ // this covers the GET * case -- without system access, you can't see everything
|
|
|
+ assertThat(isIndexVisible("other", "*"), is(true));
|
|
|
+ assertThat(isIndexVisible(".foo", "*"), is(false));
|
|
|
+ assertThat(isIndexVisible(".bar", "*"), is(false));
|
|
|
+
|
|
|
+ // no difference here in the datastream case, you can't see these then, either
|
|
|
+ assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true));
|
|
|
+ assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false));
|
|
|
+ assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false));
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
|
|
+ threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "true");
|
|
|
+ threadContext.putHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "some-elastic-product");
|
|
|
+ indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices);
|
|
|
+ indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver);
|
|
|
+
|
|
|
+ // this covers the GET * case -- with product (only) access, you can't see everything
|
|
|
+ assertThat(isIndexVisible("other", "*"), is(true));
|
|
|
+ assertThat(isIndexVisible(".foo", "*"), is(false));
|
|
|
+ assertThat(isIndexVisible(".bar", "*"), is(false));
|
|
|
+
|
|
|
+ // no difference here in the datastream case, you can't see these then, either
|
|
|
+ assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true));
|
|
|
+ assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false));
|
|
|
+ assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private static XContentBuilder mappings() {
|
|
@@ -306,4 +350,12 @@ public class IndexAbstractionResolverTests extends ESTestCase {
|
|
|
private List<String> resolveAbstractions(List<String> expressions, IndicesOptions indicesOptions, Supplier<Set<String>> mask) {
|
|
|
return indexAbstractionResolver.resolveIndexAbstractions(expressions, indicesOptions, metadata, mask, (idx) -> true, true);
|
|
|
}
|
|
|
+
|
|
|
+ private boolean isIndexVisible(String index, String selector) {
|
|
|
+ return isIndexVisible(index, selector, IndicesOptions.strictExpandHidden());
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isIndexVisible(String index, String selector, IndicesOptions indicesOptions) {
|
|
|
+ return IndexAbstractionResolver.isIndexVisible("*", selector, index, indicesOptions, metadata, indexNameExpressionResolver, true);
|
|
|
+ }
|
|
|
}
|