-
Notifications
You must be signed in to change notification settings - Fork 25.7k
POC: plug ES|QL project routing into index resolution #132971
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlProjectRoutingAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.action; | ||
|
|
||
| import org.elasticsearch.action.ActionType; | ||
|
|
||
| public class EsqlProjectRoutingAction extends ActionType<EsqlProjectRoutingResponse> { | ||
| public static final String NAME = "cluster:monitor/xpack/esql/project_routing"; | ||
| public static final EsqlProjectRoutingAction INSTANCE = new EsqlProjectRoutingAction(NAME); | ||
|
|
||
| public EsqlProjectRoutingAction(String name) { | ||
| super(NAME); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...gin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlProjectRoutingRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.action; | ||
|
|
||
| import org.elasticsearch.action.ActionRequest; | ||
| import org.elasticsearch.action.ActionRequestValidationException; | ||
| import org.elasticsearch.action.support.TransportAction; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| public class EsqlProjectRoutingRequest extends ActionRequest { | ||
| public EsqlProjectRoutingRequest(List<String> projects, String projectRoutingQuery) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public ActionRequestValidationException validate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| TransportAction.localOnly(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...in/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlProjectRoutingResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.action; | ||
|
|
||
| import org.elasticsearch.action.ActionResponse; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| public class EsqlProjectRoutingResponse extends ActionResponse { | ||
|
|
||
| private final List<String> projects; | ||
|
|
||
| public EsqlProjectRoutingResponse(List<String> projects) { | ||
| this.projects = projects; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeGenericList(projects, StreamOutput::writeString); | ||
| } | ||
|
|
||
| public List<String> getProjects() { | ||
| return projects; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
.../src/main/java/org/elasticsearch/xpack/esql/action/TransportEsqlProjectRoutingAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.action; | ||
|
|
||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.support.ActionFilters; | ||
| import org.elasticsearch.action.support.TransportAction; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
| import org.elasticsearch.injection.guice.Inject; | ||
| import org.elasticsearch.tasks.Task; | ||
| import org.elasticsearch.transport.TransportService; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class TransportEsqlProjectRoutingAction extends TransportAction<EsqlProjectRoutingRequest, EsqlProjectRoutingResponse> { | ||
| @Inject | ||
| public TransportEsqlProjectRoutingAction( | ||
| Settings settings, | ||
| TransportService transportService, | ||
| ActionFilters actionFilters, | ||
| ClusterService clusterService | ||
| ) { | ||
| super(EsqlProjectRoutingAction.NAME, actionFilters, transportService.getTaskManager(), EsExecutors.DIRECT_EXECUTOR_SERVICE); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doExecute(Task task, EsqlProjectRoutingRequest request, ActionListener<EsqlProjectRoutingResponse> listener) { | ||
| // whatever fancy ES|QL needs to happen here can happen here | ||
| listener.onResponse(new EsqlProjectRoutingResponse(List.of("project1", "project2", "project3"))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/EsqlProjectRouter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.security; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.client.internal.Client; | ||
| import org.elasticsearch.xpack.core.esql.action.EsqlQueryRequest; | ||
| import org.elasticsearch.xpack.core.esql.action.EsqlQueryRequestBuilder; | ||
| import org.elasticsearch.xpack.core.esql.action.EsqlQueryResponse; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class EsqlProjectRouter { | ||
|
|
||
| private static final Logger logger = LogManager.getLogger(EsqlProjectRouter.class); | ||
|
|
||
| private final Client client; | ||
|
|
||
| public EsqlProjectRouter(Client client) { | ||
| this.client = client; | ||
| } | ||
|
|
||
| public List<String> route(List<String> projects, String projectRoutingQuery) { | ||
| // Note: this just demonstrates that we can invoke the full ES|QL engine from the security layer | ||
| // we certainly don't want to just run a generic ES|QL query | ||
|
|
||
| // Instead we should expose the EsqlProjectRoutingAction to be called the same way we | ||
| // expose the EsqlQueryAction and call EsqlProjectRoutingAction here | ||
| // (we will need to repeat the dance done in https://github.com/elastic/elasticsearch/issues/104413) | ||
|
|
||
| // EsqlProjectRoutingAction will be localOnly as it will only access an on-the fly in-memory index | ||
| // so there are no network costs associated | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| EsqlQueryRequestBuilder<EsqlQueryRequest, EsqlQueryResponse> b = (EsqlQueryRequestBuilder< | ||
| EsqlQueryRequest, | ||
| EsqlQueryResponse>) EsqlQueryRequestBuilder.newRequestBuilder(client); | ||
|
|
||
| b.query(projectRoutingQuery).execute(new ActionListener<>() { | ||
| @Override | ||
| public void onResponse(EsqlQueryResponse response) { | ||
| logger.info("EsqlProjectRouter response: {}", response); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Exception e) { | ||
| logger.warn("EsqlProjectRouter failure", e); | ||
| } | ||
| }); | ||
|
|
||
| return projects; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Just showing that we can use the ES|QL engine in the security interceptor.