-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Parameterize the Security
plugin with the request-wise thread context supplier
#95040
Parameterize the Security
plugin with the request-wise thread context supplier
#95040
Conversation
@@ -510,7 +501,6 @@ private static void sendContentTypeErrorMessage(@Nullable List<String> contentTy | |||
|
|||
private void tryAllHandlers(final RestRequest request, final RestChannel channel, final ThreadContext threadContext) throws Exception { | |||
try { | |||
copyRestHeaders(request, threadContext); |
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.
The RestController
is not responsible to set (part of) the thread context anymore, mainly because the Security
plugin cannot hook-in at this point. Instead, the Security
plugin wraps the RestController
before passing it to the Netty4HttpServerTransport
that it builds (Security
builds a HttpServerTransport
in order to implement TLS).
populateClientCertificate.accept(restRequest.getHttpChannel(), threadContext); | ||
RemoteHostHeader.process(restRequest, threadContext); |
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 additional thread context that Security
constructs, brought together in this single place. This context must be set before AuthenticationService#authenticate
is attempted.
if (extractClientCertificate) { | ||
HttpChannel httpChannel = request.getHttpChannel(); | ||
SSLEngineUtils.extractClientCertificates(logger, threadContext, httpChannel); | ||
} | ||
|
||
final RestRequest wrappedRequest = maybeWrapRestRequest(request); | ||
RemoteHostHeader.process(request, threadContext); |
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.
These things moved.
HttpServerTransport.Dispatcher dispatcherWithContext = HttpServerTransport.Dispatcher.dispatchWithThreadContextWrapper( | ||
dispatcher, | ||
(httpPreRequest -> dispatcherContext.accept(httpPreRequest, threadPool.getThreadContext())) | ||
); |
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.
Previously, the RestController
was in charge to build the thread context from the request headers.
Now, the dispatcherContext
does that, and it is exposed by the ActionModule
, to be used by the plugins that build HttpServerTransport
implementations (which take the RestController
as the argument).
Security
plugin with the request-wise thread context supplier
@@ -1592,6 +1596,7 @@ public Map<String, Supplier<HttpServerTransport>> getHttpTransports( | |||
NamedXContentRegistry xContentRegistry, | |||
NetworkService networkService, | |||
HttpServerTransport.Dispatcher dispatcher, | |||
BiConsumer<HttpPreRequest, ThreadContext> dispatcherContext, |
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 important. The Security
plugin needs access to this supplier of thread context.
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.
change is looking good, thanks for the change away from the dispatch wrapper i think this reads much better. just a couple minor questions and nitpicks
server/src/main/java/org/elasticsearch/action/ActionModule.java
Outdated
Show resolved
Hide resolved
modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Plugin.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/rest/RestController.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java
Show resolved
Hide resolved
Thank you for the speedy reviews @jakelandis ! |
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, thanks for the discussion and updates
…xt supplier (elastic#95040) When `Security` authenticates a request (AuthenticationService#authenticate) it mostly looks in the thread context for all the request details that it needs. Consequently, there's code that populates the thread context before invoking authentication. This PR brings all the code that's responsible for populating the said thread context, as a parameter to the `Security` plugin. This is required in the follow-up that is going to involve setting up the thread context (given the aforementioned parameter), and running the authentication under that context, before the request is dispatched (rather than "while" it's being dispatched, currently).
When
Security
authenticates a request (AuthenticationService#authenticate
) it mostly looks in the thread context for all the request details that it needs.Consequently, there's code that populates the thread context before running authentication.
This PR brings all the code that's responsible for populating the said thread context, as a parameter to the
Security
plugin.This is required in the follow-up that is going to involve setting up the thread context (given the aforementioned parameter), and running the authentication under that context, before the request is dispatched (rather than "while" it's being dispatched, currently).