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

[ML] Plugin support for scoped clients #62886

Closed
rylnd opened this issue Apr 7, 2020 · 4 comments · Fixed by #64432
Closed

[ML] Plugin support for scoped clients #62886

rylnd opened this issue Apr 7, 2020 · 4 comments · Fixed by #64432
Assignees
Labels
:ml Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.8.0

Comments

@rylnd
Copy link
Contributor

rylnd commented Apr 7, 2020

Describe a specific use case for the feature:
Interaction with ML during alert execution, using the alert's permissions (role/licensing authorization).

Describe the feature:
The ML Plugin's contract exposes a number of useful services for consumers to use.

However, all of these service providers require an ApiCaller argument (i.e. a cluster client) to function, and this client must define ml-specific paths in order to function.

As a temporary workaround for 7.7, I exposed the ML client as part of ML's contract. This provides consumers with a ml-path-enriched client to pass to those services. Additionally, it can be used in a request handler to make calls on behalf of the current user by using the asScoped method.

However, there is one major limitation with this approach, and that's alerting. Alerts execute independent of a request (so we cannot use asScoped) but execute on behalf of the user that created them. To support that, alerts are provided a cluster client scoped to their creator (via an API key mimicking their permission). However, due to the paths requirement mentioned above, we cannot use said client with ML services, and are left with the following options:

  1. Write custom queries agains ML indices using the scoped client
    • data access is respected, but ML logic is leaked
    • SIEM currently does this to query anomalies during ML Rule execution
  2. Use ML services with mlClient.callAsInternalUser)
    • ML logic is not leaked, but neither is data access respected
    • SIEM currently does this to check jobs' status during ML Rule execution
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@rylnd
Copy link
Contributor Author

rylnd commented Apr 15, 2020

Pinging @elastic/kibana-alerting-services in case they might be able to offer a quick solution here:

Our limitations are as follows:

  • ML calls require the mlClient as it defines the ML ES endpoints that are called, but:
  • mlClient cannot be scoped to the alert's user (via asScoped) because we have no request in the execution context

After looking through the alerting code, it looks like you already do something similar to what I wanted to propose: generate a dummy request in order to scope the provided AlertServices.

If alerting could expose that request (or at least the API key) to the executor, we'd be able to scope the ML client without any other changes. Thoughts?

@rylnd
Copy link
Contributor Author

rylnd commented Apr 16, 2020

@jgowdyelastic I Spoke briefly with @mikecote about the above. From a technical perspective this should indeed be a quick solution, but he's going to talk first with the kibana security team about the implications of exposing that information to the alert.

@mikecote one quick thought: instead of exposing the credentials directly, alerting could provide a function to scope an arbitrary client:

const scopedMlClient = alertingServices.scopeClusterClient(mlClient);

@mikecote mikecote added the Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) label Apr 17, 2020
@mikecote
Copy link
Contributor

I've made a comment here to see what drawbacks we would have exposing the request in the alerting framework.

Is there a 7.8 alert that is waiting for a scoped ML client or is the goal to have a client exposed within 7.8?

@mikecote one quick thought: instead of exposing the credentials directly, alerting could provide a function to scope an arbitrary client:

const scopedMlClient = alertingServices.scopeClusterClient(mlClient);

Something like that could work, depending on the answer from platform team, we could also take on code debt and provide a scoped ML client within the services the alert executor receives in the time being.

@mikecote mikecote self-assigned this Apr 24, 2020
@kobelb kobelb added the needs-team Issues missing a team label label Jan 31, 2022
@botelastic botelastic bot removed the needs-team Issues missing a team label label Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:ml Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.8.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants