-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Improve error handling during index expressions resolving #126018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error handling during index expressions resolving #126018
Conversation
The `InvalidIndexNameException` and `IllegalArgumentException` exceptions were wrapped in a `ElasticsearchSecurityException`, which returns HTTP `403` status. These exceptions can be raised during index expression resolving, due to an invalid user input, and should result in HTTP `400` response. This PR changes exception handling to avoid wrapping them in the `ElasticsearchSecurityException`.
...ugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java
Show resolved
Hide resolved
indicesAndAliasesResolver.resolve(action, request, projectMetadata, authorizedIndices) | ||
), | ||
e -> { | ||
if (e instanceof InvalidIndexNameException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another exception I've considered was InvalidArgumentException
but decided to skip it since it's not guaranteed that it's caused by the user's invalid input (sometimes it hides internal errors). I think we need clearer error handling overall or to be very specific which exceptions we consider client errors (e.g. analyze exception messages) .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, InvalidArgumentException
feels too broad to catch here...
WDYT about adding InvalidSelectorException
(extend InvalidArgumentException
) and throw that in getByKeyOrThrow
and also throw either InvalidSelectorException
or InvalidIndexNameException
inside ensureNoSelectorsProvided
? I think that would cover a decent amount of other cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good suggestion. Using a dedicated exception is a way to go. I'll adjust that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed 601d8f7, which introduces InvalidSelectorException
and UnsupportedSelectorException
. Let me know what you think.
…ve-error-handling # Conflicts: # x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/failurestore/FailureStoreSecurityRestIT.java
Pinging @elastic/es-security (Team:Security) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once CI passes 🚀
💔 Backport failed
You can use sqren/backport to manually backport by running |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
…6018) The `InvalidIndexNameException` exception was wrapped in a `ElasticsearchSecurityException`, which returns HTTP `403` status. This exception (along with newly introduced `InvalidSelectorException` and `UnsupportedSelectorException`) can be raised during index expression resolving due to an invalid user input and should result in HTTP `400` response instead. This PR changes exception handling to avoid wrapping them in the `ElasticsearchSecurityException`. (cherry picked from commit 0b09506) # Conflicts: # x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/failurestore/FailureStoreSecurityRestIT.java # x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java
) (#126373) * Improve error handling during index expressions resolving (#126018) The `InvalidIndexNameException` exception was wrapped in a `ElasticsearchSecurityException`, which returns HTTP `403` status. This exception (along with newly introduced `InvalidSelectorException` and `UnsupportedSelectorException`) can be raised during index expression resolving due to an invalid user input and should result in HTTP `400` response instead. This PR changes exception handling to avoid wrapping them in the `ElasticsearchSecurityException`. (cherry picked from commit 0b09506) # Conflicts: # x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/failurestore/FailureStoreSecurityRestIT.java # x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
The
InvalidIndexNameException
exception was wrapped in aElasticsearchSecurityException
, which returns HTTP403
status.This exception (along with newly introduced
InvalidSelectorException
andUnsupportedSelectorException
) can be raised during index expression resolving due to an invalid user input and should result in HTTP400
response instead.This PR changes exception handling to avoid wrapping them in the
ElasticsearchSecurityException
.