-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Handle Unauthenticated OPTIONS requests #96061
Handle Unauthenticated OPTIONS requests #96061
Conversation
if (httpPreRequest.method() != RestRequest.Method.OPTIONS) { | ||
authenticationService.authenticate( | ||
httpPreRequest, | ||
ActionListener.wrap(ignored -> listener.onResponse(null), listener::onFailure) | ||
); | ||
} else { | ||
// allow for unauthenticated OPTIONS request | ||
// this includes CORS preflight, and regular OPTIONS that return permitted methods for a given path | ||
listener.onResponse(null); | ||
} |
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.
This is the interesting part. Allow requests with OPTIONS method to bypass authentication.
// requests with the OPTIONS method should be handled elsewhere, and not by calling {@code RestHandler#handleRequest} | ||
// authn is bypassed for HTTP requests with the OPTIONS method, so this sanity check prevents dispatching unauthenticated requests | ||
if (request.method() == Method.OPTIONS) { | ||
// CORS - allow for preflight unauthenticated OPTIONS request | ||
restHandler.handleRequest(request, channel, client); | ||
handleException( | ||
request, | ||
channel, | ||
new ElasticsearchSecurityException("Cannot dispatch OPTIONS request, as they are not authenticated") | ||
); |
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.
This is the second most interesting part.
Because OPTIONS requests bypass authentication, this is a sanity check that unauthenticated OPTIONS requests are not dispatched.
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
Will loop this with @jakelandis post merge, as this is blocking some time-sensitive projects. ⚡ |
Resolves #157017 Resolves #157018 Unskips our Interactive Setup functional tests, which started failing after a recent ES snapshot promotion. This was caused by a regression in Elasticsearch, which was resolved via elastic/elasticsearch#96061. I will not be running a flaky test suite here, as these tests were consistently failing, as opposed to flaky.
Resolves #157017 Resolves #157018 Unskips our Interactive Setup functional tests, which started failing after a recent ES snapshot promotion. This was caused by a regression in Elasticsearch, which was resolved via elastic/elasticsearch#96061. I will not be running a flaky test suite here, as these tests were consistently failing, as opposed to flaky.
This address HTTP OPTIONS requests following the authentication refactoring in elastic#95112. Relates elastic#95112
This address HTTP OPTIONS requests following
the authentication refactoring in #95112.
Relates #95112