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

Add a specialized PainlessExecuteIndexAction #78825

Closed
wants to merge 5 commits into from

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Oct 7, 2021

This change refactors the painless execute action into two actions:

  • PainlessExecuteAction
  • PainlessExecuteIndexAction

Script context that require an index to run should use the newly added PainlessExecuteIndexAction.
This action checks if the user has the read permission on the index to run but unlike the existing
PainlessExecuteAction, no cluster privilege is required.
For scripts that run outside of an index context, the existing PainlessExecuteAction can still be used.
Note that passing the index in the body continues to work for backward compatibility purpose but in such
case it's the old action that requires the cluster privilege and the read privilege that will run.

Relates #48856

This change refactors the painless execute action into two actions:
  * PainlessExecuteAction
  * PainlessExecuteIndexAction

Script context that require an index to run should use the newly added PainlessExecuteIndexAction.
This action checks if the user has the read permission on the index to run but unlike the existing
PainlessExecuteAction, no cluster privilege is required.
For scripts that run outside of an index context, the existing PainlessExecuteAction can still be used.
Note that passing the index in the body continues to work for backward compatibility purpose but in such
case it's the old action that requires the cluster privilege **and** the read privilege that will run.

Relates elastic#48856
@jimczi jimczi added >enhancement :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v8.0.0 v7.16.0 labels Oct 7, 2021
@jimczi jimczi requested a review from jdconrad October 7, 2021 12:12
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Oct 7, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@sethmlarson sethmlarson added the Team:Clients Meta label for clients team label Oct 8, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/clients-team (Team:Clients)

Copy link
Contributor

@jdconrad jdconrad left a comment

Choose a reason for hiding this comment

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

This looks really good, thanks for doing this!

I do have two comments I'd like to discuss prior to approval.

The first is the path for this action as noted in a comment on the pr.

The second is I wonder if we should allow execute w/o any index to run under the most lenient permissions possible. Maybe we deprecate index usage as part of the existing execute action, and then reduce the required permissions in a future pr?

@@ -113,7 +113,7 @@ In this example, `message` is the `<field_name>` and `response` is the

[source,console]
----
POST /_scripts/painless/_execute
POST /my_index/_scripts/painless/_execute
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we not want to use my-index-000001 as in the other examples?

Comment on lines +116 to +117
new Route(GET, "{index}/_scripts/painless/_execute"),
new Route(POST, "{index}/_scripts/painless/_execute"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I have concerns about this path. Do we really want the index name to lead the path for an action that is exclusive to Painless and in the future possibly scripting? I understand that for most index actions this is how we describe them, but in this case I'm not sure of the fit.

I would think of something more like /_scripts/{action} where lang and index end up specified as part of body. Or /scripts/{action}/lang/{lang}/index/{index} where lang and index become optional interchangeable pieces of the path, and other parameters can extend this path easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we want the index to be part of the path. That's the differentiator for this route compared to the other execute action. I didn't want to introduce a whole new path since the existing rest action will stay so we need some consistency ?

@jimczi
Copy link
Contributor Author

jimczi commented Oct 11, 2021

The second is I wonder if we should allow execute w/o any index to run under the most lenient permissions possible. Maybe we deprecate index usage as part of the existing execute action, and then reduce the required permissions in a future pr?

+1 to deprecate in a follow up. I tried to do it in this PR but there are some BWC tests that we'll need to adapt. It's also quite late in 7x so that deserves a separate discussion.

@jimczi
Copy link
Contributor Author

jimczi commented Oct 15, 2021

After discussing with @jdconrad and @rjernst we've decided to close this PR. It doesn't solve the original issue, the manage cluster permission is needed to run a script without an index context, so it's more an hack than a long-term solution.
Kibana will switch to _search to simulate scripts until we find a proper solution for #48856.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Clients Meta label for clients team Team:Core/Infra Meta label for core/infra team v7.16.0 v8.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants