Skip to content

Commit 8bd9f81

Browse files
committed
Add asserts and comments about keeping BACKWARDS_COMPATIBLE_ONLY in only special cases
1 parent d1e7834 commit 8bd9f81

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,10 @@ boolean isPatternMatchingAllIndices(Metadata metadata, String[] indicesOrAliases
748748
}
749749

750750
public SystemIndexAccessLevel getSystemIndexAccessLevel() {
751-
return systemIndices.getSystemIndexAccessLevel(threadContext);
751+
final SystemIndexAccessLevel accessLevel = systemIndices.getSystemIndexAccessLevel(threadContext);
752+
assert accessLevel != SystemIndexAccessLevel.BACKWARDS_COMPATIBLE_ONLY
753+
: "BACKWARDS_COMPATIBLE_ONLY access level should never be used automatically, it should only be used in known special cases";
754+
return accessLevel;
752755
}
753756

754757
public Predicate<String> getSystemIndexAccessPredicate() {

server/src/main/java/org/elasticsearch/indices/SystemIndices.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public SystemDataStreamDescriptor validateDataStreamAccess(String dataStreamName
351351
.orElseThrow(() -> new IllegalStateException("system data stream descriptor not found for [" + dataStreamName + "]"));
352352
if (dataStreamDescriptor.isExternal()) {
353353
final SystemIndexAccessLevel accessLevel = getSystemIndexAccessLevel(threadContext);
354+
assert accessLevel != SystemIndexAccessLevel.BACKWARDS_COMPATIBLE_ONLY : "BACKWARDS_COMPATIBLE access level is leaking";
354355
if (accessLevel == SystemIndexAccessLevel.NONE) {
355356
throw dataStreamAccessException(null, dataStreamName);
356357
} else if (accessLevel == SystemIndexAccessLevel.RESTRICTED) {
@@ -409,6 +410,8 @@ IllegalArgumentException dataStreamAccessException(@Nullable String product, Str
409410
* {@link SystemIndexAccessLevel#NONE} if no system index access should be allowed.
410411
*/
411412
public SystemIndexAccessLevel getSystemIndexAccessLevel(ThreadContext threadContext) {
413+
// This method intentionally cannot return BACKWARDS_COMPATIBLE_ONLY - that access level should only be used manually
414+
// in known special cases.
412415
final String headerValue = threadContext.getHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY);
413416
final String productHeaderValue = threadContext.getHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY);
414417

0 commit comments

Comments
 (0)