Skip to content

Conversation

pawankartik-elastic
Copy link
Contributor

The authorisation code uses the pattern ["*", "-*"] whose semantics mean that it's alright to return an empty response. However, we don't seem to handle this scenario in most (if not all) endpoints and especially in groupIndices(). When such a pattern is not handled, groupIndices() associates both the indices with the local cluster and we unknowingly end up including the local cluster in the response. This is why the _resolve/cluster endpoint will include the local cluster in the response when you specify a pattern that does not match any remote. E.g.: _resolve/cluster/my_nonexistent_*:w*.

When you have security turned on and run an ES|QL query where the remote pattern does not match any clusters, you're fine and do not get back results from the local cluster (unsecured model was prone to this bug which mpeterson fixed in October last year). However, _resolve/cluster is affected under the same security model. There's discrepancy here: sometimes we fallback to the local cluster and sometimes we don't. IMO, ideally, we shouldn't and this is problematic.

There could be other endpoints that maybe affected in a similar way. The best way forward I see is to handle it in a place that's most likely to trip. Otherwise, we'll have to run a precheck everywhere to detect such a pattern before we call APIs like groupIndices(). This is cumbersome and we could easily forget to do so.

@smalyshev
Copy link
Contributor

LGTM

@smalyshev
Copy link
Contributor

smalyshev commented May 29, 2025

Should probably mention #115872, though it looks like it's different code path - this one with security, and #115872 is without security.

@pawankartik-elastic
Copy link
Contributor Author

pawankartik-elastic commented May 29, 2025

Yes, I'll mention the issue and yes, this is a different codepath. We need to handle this index pattern only when the security is turned on (as of now; I don't think we're using it elsewhere AFAIK).

@pawankartik-elastic
Copy link
Contributor Author

I've given it another thought: the issue you mentioned specifically talks about the unsecured model. Here, the issue is due to the pattern that's being injected by the auth-related code and to me, that seems like a different, yet tangential issue.

@pawankartik-elastic pawankartik-elastic marked this pull request as ready for review June 2, 2025 11:05
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@elasticsearchmachine
Copy link
Collaborator

Hi @pawankartik-elastic, I've created a changelog YAML for you.

@pawankartik-elastic pawankartik-elastic added the auto-backport Automatically create backport pull requests when merged label Jun 2, 2025
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a comment about possible longer term changes, LGTM

final Map<String, OriginalIndices> originalIndicesMap = new HashMap<>();
final Map<String, List<String>> groupedIndices = groupClusterIndices(remoteClusterNames, indices);
final Map<String, List<String>> groupedIndices;
if (returnLocalAll == false && IndexNameExpressionResolver.isNoneExpression(indices)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps add a comment here, that explains the semantics of returnLocalAll and where it's used set to false.

I wonder if in the longer run, we should consider making resolve cluster go through a specific method that resolves clusters instead of indices, and remove this flag that makes things a little difficult to read. What do you think? Do we ever consume the indices names (values in the map) or only the cluster aliases (keys in the map)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although we don't return the indices names directly, the _resolve/cluster call's response has a key matching_indices that tells if the specified cluster has the specified index.

@pawankartik-elastic pawankartik-elastic merged commit 3f1e1b3 into elastic:main Jun 3, 2025
18 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.19
9.0 Commit could not be cherrypicked due to conflicts
8.18 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 128610

pawankartik-elastic added a commit to pawankartik-elastic/elasticsearch that referenced this pull request Jun 3, 2025
…ster name (elastic#128610) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster.
elasticsearchmachine pushed a commit that referenced this pull request Jun 3, 2025
…ster name (#128610) (#128822) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster.
joshua-adams-1 pushed a commit to joshua-adams-1/elasticsearch that referenced this pull request Jun 3, 2025
…ster name (elastic#128610) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster.
@pawankartik-elastic
Copy link
Contributor Author

pawankartik-elastic commented Jun 3, 2025

Ugh, backport tool is broken. I'll manually do the porting tomorrow morning.
Edit: Used an older version of backport. Things looking good.

@pawankartik-elastic
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
9.0
8.18

Questions ?

Please refer to the Backport tool documentation

pawankartik-elastic added a commit to pawankartik-elastic/elasticsearch that referenced this pull request Jun 3, 2025
…ster name (elastic#128610) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster. (cherry picked from commit 3f1e1b3) # Conflicts: #	server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java
pawankartik-elastic added a commit to pawankartik-elastic/elasticsearch that referenced this pull request Jun 3, 2025
…ster name (elastic#128610) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster. (cherry picked from commit 3f1e1b3) # Conflicts: #	server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java
elasticsearchmachine pushed a commit that referenced this pull request Jun 3, 2025
…ster name (#128610) (#128843) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster. (cherry picked from commit 3f1e1b3) # Conflicts: #	server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java
pawankartik-elastic added a commit that referenced this pull request Jun 4, 2025
…ster name (#128610) (#128842) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster. (cherry picked from commit 3f1e1b3)
Samiul-TheSoccerFan pushed a commit to Samiul-TheSoccerFan/elasticsearch that referenced this pull request Jun 5, 2025
…ster name (elastic#128610) The auth code injects the pattern `["*", "-*"]` to specify that it's okay to return an empty response because user's patterns did not match any remote clusters. However, we fail to recognise this specific pattern and `groupIndices()` eventually associates it with the local cluster. This causes Elasticsearch to fallback to the local cluster unknowingly and return its details back to the user even though the user hasn't requested any info about the local cluster.
@pawankartik-elastic pawankartik-elastic deleted the pkar/detect-no-indices-aliases-pattern branch June 26, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged backport pending >bug :Search Foundations/CCS Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.18.3 v8.19.0 v9.0.3 v9.1.0

4 participants