|
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) |
@@ -271,16 +260,71 @@ public void testIsNetNewSystemIndexVisible() { |
271 | 260 | List.of(new SystemIndices.Feature("name", "description", List.of(fooDescriptor, barDescriptor))) |
272 | 261 | ); |
273 | 262 |
|
274 | | - final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
275 | | - threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false"); |
276 | | - indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices); |
277 | | - indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver); |
278 | | - |
279 | 263 | metadata = Metadata.builder().put(foo, true).put(barReindexed, true).put(other, true).build(); |
280 | 264 |
|
281 | | - assertThat(isIndexVisible("other", "*"), is(true)); |
282 | | - assertThat(isIndexVisible(".foo", "*"), is(false)); |
283 | | - assertThat(isIndexVisible(".bar", "*"), is(false)); |
| 265 | + // these indices options are for the GET _data_streams case |
| 266 | + final IndicesOptions noHiddenNoAliases = IndicesOptions.builder() |
| 267 | + .wildcardOptions( |
| 268 | + IndicesOptions.WildcardOptions.builder() |
| 269 | + .matchOpen(true) |
| 270 | + .matchClosed(true) |
| 271 | + .includeHidden(false) |
| 272 | + .resolveAliases(false) |
| 273 | + .build() |
| 274 | + ) |
| 275 | + .build(); |
| 276 | + |
| 277 | + { |
| 278 | + final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 279 | + threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "true"); |
| 280 | + indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices); |
| 281 | + indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver); |
| 282 | + |
| 283 | + // this covers the GET * case -- with system access, you can see everything |
| 284 | + assertThat(isIndexVisible("other", "*"), is(true)); |
| 285 | + assertThat(isIndexVisible(".foo", "*"), is(true)); |
| 286 | + assertThat(isIndexVisible(".bar", "*"), is(true)); |
| 287 | + |
| 288 | + // but if you don't ask for hidden and aliases, you won't see hidden indices or aliases, naturally |
| 289 | + assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true)); |
| 290 | + assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false)); |
| 291 | + assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false)); |
| 292 | + } |
| 293 | + |
| 294 | + { |
| 295 | + final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 296 | + threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "false"); |
| 297 | + indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices); |
| 298 | + indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver); |
| 299 | + |
| 300 | + // this covers the GET * case -- without system access, you can't see everything |
| 301 | + assertThat(isIndexVisible("other", "*"), is(true)); |
| 302 | + assertThat(isIndexVisible(".foo", "*"), is(false)); |
| 303 | + assertThat(isIndexVisible(".bar", "*"), is(false)); |
| 304 | + |
| 305 | + // no difference here in the datastream case, you can't see these then, either |
| 306 | + assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true)); |
| 307 | + assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false)); |
| 308 | + assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false)); |
| 309 | + } |
| 310 | + |
| 311 | + { |
| 312 | + final ThreadContext threadContext = new ThreadContext(Settings.EMPTY); |
| 313 | + threadContext.putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "true"); |
| 314 | + threadContext.putHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, "some-elastic-product"); |
| 315 | + indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices); |
| 316 | + indexAbstractionResolver = new IndexAbstractionResolver(indexNameExpressionResolver); |
| 317 | + |
| 318 | + // this covers the GET * case -- with product (only) access, you can't see everything |
| 319 | + assertThat(isIndexVisible("other", "*"), is(true)); |
| 320 | + assertThat(isIndexVisible(".foo", "*"), is(false)); |
| 321 | + assertThat(isIndexVisible(".bar", "*"), is(false)); |
| 322 | + |
| 323 | + // no difference here in the datastream case, you can't see these then, either |
| 324 | + assertThat(isIndexVisible("other", "*", noHiddenNoAliases), is(true)); |
| 325 | + assertThat(isIndexVisible(".foo", "*", noHiddenNoAliases), is(false)); |
| 326 | + assertThat(isIndexVisible(".bar", "*", noHiddenNoAliases), is(false)); |
| 327 | + } |
284 | 328 | } |
285 | 329 |
|
286 | 330 | private static XContentBuilder mappings() { |
@@ -308,4 +352,12 @@ private List<String> resolveAbstractionsSelectorAllowed(List<String> expressions |
308 | 352 | private List<String> resolveAbstractions(List<String> expressions, IndicesOptions indicesOptions, Supplier<Set<String>> mask) { |
309 | 353 | return indexAbstractionResolver.resolveIndexAbstractions(expressions, indicesOptions, metadata, mask, (idx) -> true, true); |
310 | 354 | } |
| 355 | + |
| 356 | + private boolean isIndexVisible(String index, String selector) { |
| 357 | + return isIndexVisible(index, selector, IndicesOptions.strictExpandHidden()); |
| 358 | + } |
| 359 | + |
| 360 | + private boolean isIndexVisible(String index, String selector, IndicesOptions indicesOptions) { |
| 361 | + return IndexAbstractionResolver.isIndexVisible("*", selector, index, indicesOptions, metadata, indexNameExpressionResolver, true); |
| 362 | + } |
311 | 363 | } |
0 commit comments