Skip to content
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

[Question] How to determine when a REST request is destined for an extension #2526

Closed
1 task done
Tracked by #2596
stephen-crawford opened this issue Mar 8, 2023 · 2 comments
Closed
1 task done
Tracked by #2596
Assignees
Labels
triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.

Comments

@stephen-crawford
Copy link
Contributor

stephen-crawford commented Mar 8, 2023

Problem Statement

The Security Plugin needs to be able to tell when a REST request is destined for an extension.

$\textcolor{orange}{\textsf{Orange text is a header for a decision that is not made }}$
$\textcolor{teal}{\textsf{Teal text is a header for a decision that is made }}$
$\textcolor{violet}{\textsf{Violet text is the recommended option }}$
$\textcolor{lime}{\textsf{Lime text is the chosen option }}$

What type of REST requests are intended for extensions?
How does the Security Plugin interact with REST requests?
What is the current method of signifying things?

Action items decided on this issue:

  • How do we signal a request is destined for an extension?

$\textcolor{orange}{\textsf{How do we signal a request is destined for an extension?}}$

When a request is made by a user, it needs to be possible to determine whether the request is destined to an extension or simply intended for OpenSearch itself. If the request is meant for an extension the authorization steps are more complex since the Security plugin needs to grant an on-behalf-of token (if it is a user request). The RestRequest logic in core does not a have a built-in way of determining when a request is meant for an extension so one will have to be added.

In the current version of the opensearch-sdk-java, extensions routes look like /_extensions/_opensearch-sdk-java-1/hello.

For example:

curl -X GET localhost:9200/_extensions/_opensearch-sdk-java-1/hello

This leaves two main options for signifying a request is destined for an extension:

  1. The first option is simply to parse the request and check that the route has both the _extensions flag as well as a registered extension name i.e. _opensearch-sdk-java-1. This option is easy to implement and only requires the addition of a hook to parse the request before a token is created.
Pros Cons
Easy to implement Requires parsing the request
Connects to REST Handler Could be issues if there are requests with the same route elements not intended for an extension, i.e. an API to change settings for the extension

What do code changes look like?
For this option, changes will take place in the Security Plugin by parsing the REST request during the REST layer authorization. Putting a check at the start of the REST layer authorization process will allow the Security plugin to determine whether a request is destined for an extension before it needs to parse the authorization credentials. This will let the Security plugin handle the request appropriately from the start.

  1. The second option is to make use of the RestSendToExtensionAction.

It may be possible to do this by seeing if the original RestHandler is a RestSendToExtensionAction. This option would lookup the registration in core to determine whether a request is in fact destined to an extension based on the previous registration of the actions request. By parsing information on registration and then storing it somewhere, it would be possible to later check whether a request is destined for an extension. This lookup would decrease any unnecessary work done in the Security Plugin since you could direct the request immediately to the appropriate authorization channel based on where it was destined.

Relevant lines read:

public TransportResponse handleRegisterRestActionsRequest(RegisterRestActionsRequest restActionsRequest) throws Exception {
    DiscoveryExtensionNode discoveryExtensionNode = extensionIdMap.get(restActionsRequest.getUniqueId());
    RestHandler handler = new RestSendToExtensionAction(restActionsRequest, discoveryExtensionNode, transportService);
    restController.registerHandler(handler);
    return new AcknowledgedResponse(true);
}

What do code changes look like?
For this option, changes would be required in OpenSearch core since the introduction of a new handler during the REST action registration would be required. It would also require adding code to direct the request to a different area of the Security REST authorization logic. It would not make sense to make the changes in core if the request were just going to be handled the same in the Security Plugin. So determining how to shortcut the authorization based on the destination would be required and need to be added into the authorization logic in the Security Plugin.

@stephen-crawford stephen-crawford self-assigned this Mar 8, 2023
@stephen-crawford stephen-crawford converted this from a draft issue Mar 8, 2023
@github-actions github-actions bot added the untriaged Require the attention of the repository maintainers and may need to be prioritized label Mar 8, 2023
@peternied peternied removed the untriaged Require the attention of the repository maintainers and may need to be prioritized label Mar 13, 2023
@stephen-crawford stephen-crawford added the triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable. label Mar 20, 2023
@cwperks
Copy link
Member

cwperks commented Mar 28, 2023

@scrawfor99 Can this be closed? If a request is destined for an extension the RestHandler will be an instance of RestSendToExtensionAction

@stephen-crawford
Copy link
Contributor Author

@cwperks sounds good.

[Closure] As mentioned by Craig, if a request is destined for an extension the RestHandler will be an instance of RestSendToExtensionAction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.
Projects
Status: Done
Development

No branches or pull requests

3 participants