Skip to content

Commit fe5da12

Browse files
Better fix - mark non-existing failure store as not visible
1 parent 8666da8 commit fe5da12

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,6 @@ private static void resolveSelectorsAndCollect(
259259
selectorString = IndexComponentSelector.DATA.getKey();
260260
}
261261

262-
// For the ::failures selector, only include the expression if the data stream actually has failure
263-
// backing indices. A data stream can have failure store enabled in metadata (partially initialized)
264-
// without any backing indices yet.
265-
if (IndexComponentSelector.FAILURES.getKey().equals(selectorString)
266-
&& abstraction.getFailureIndices(projectMetadata).isEmpty()) {
267-
return;
268-
}
269-
270262
// A selector is always passed along as-is, it's validity for this kind of abstraction is tested later
271263
collect.add(IndexNameExpressionResolver.combineSelectorExpression(indexAbstraction, selectorString));
272264
} else {
@@ -323,6 +315,7 @@ private static boolean isIndexVisible(
323315
|| isHidden == false
324316
|| indicesOptions.expandWildcardsHidden()
325317
|| isVisibleDueToImplicitHidden(expression, index);
318+
boolean isFailureStoreSelectorPresent = IndexComponentSelector.FAILURES.getKey().equals(selectorString);
326319
if (indexAbstraction.getType() == IndexAbstraction.Type.ALIAS) {
327320
// it's an alias, ignore expandWildcardsOpen and expandWildcardsClosed.
328321
// it's complicated to support those options with aliases pointing to multiple indices...
@@ -357,12 +350,9 @@ private static boolean isIndexVisible(
357350
}
358351
}
359352

360-
if (isVisible && selectorString != null) {
361-
// Check if a selector was present, and if it is, check if this alias is applicable to it
362-
IndexComponentSelector selector = IndexComponentSelector.getByKey(selectorString);
363-
if (IndexComponentSelector.FAILURES.equals(selector)) {
364-
isVisible = indexAbstraction.isDataStreamRelated();
365-
}
353+
// Check if a selector was present, and if it is, check if this alias is applicable to it
354+
if (isVisible && isFailureStoreSelectorPresent) {
355+
isVisible = indexAbstraction.isDataStreamRelated();
366356
}
367357
return isVisible;
368358
}
@@ -372,9 +362,13 @@ private static boolean isIndexVisible(
372362
}
373363
if (indexAbstraction.isSystem()) {
374364
return isSystemIndexVisible(resolver, indexAbstraction);
375-
} else {
376-
return isVisible;
377365
}
366+
// A data stream with the ::failures selector is not visible if it has no failure backing indices.
367+
// A failure store can be enabled in metadata without any indices yet.
368+
if (isFailureStoreSelectorPresent && indexAbstraction.getFailureIndices(projectMetadata).isEmpty()) {
369+
return false;
370+
}
371+
return isVisible;
378372
}
379373
assert indexAbstraction.getIndices().size() == 1 : "concrete index must point to a single index";
380374
if (isVisible == false) {
@@ -397,8 +391,7 @@ private static boolean isIndexVisible(
397391
}
398392
if (selectorString != null && Regex.isMatchAllPattern(selectorString) == false) {
399393
// Check if a selector was present, and if it is, check if this index is applicable to it
400-
IndexComponentSelector selector = IndexComponentSelector.getByKey(selectorString);
401-
if (IndexComponentSelector.FAILURES.equals(selector)) {
394+
if (isFailureStoreSelectorPresent) {
402395
return false;
403396
}
404397
}

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,10 +3180,11 @@ public void testCrossProjectSearchForAllIndicesAndSelector() {
31803180
)
31813181
);
31823182

3183-
// ::data is the default selector so that it is not attached to local index names
3184-
var expectedIndices = new String[] { "logs-foo", "logs-foobar" };
3183+
String[] expectedIndices;
31853184
if (selector.equals("failures")) {
3186-
expectedIndices = Arrays.stream(expectedIndices).map(name -> name + "::" + selector).toArray(String[]::new);
3185+
expectedIndices = new String[] { "logs-foobar::failures" };
3186+
} else {
3187+
expectedIndices = new String[] { "logs-foo", "logs-foobar" };
31873188
}
31883189

31893190
assertThat(resolvedIndices.getLocal(), containsInAnyOrder(expectedIndices));

0 commit comments

Comments
 (0)