From 0460712f55822492f38e8099d1b278cc135275e7 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Wed, 12 Feb 2020 07:49:08 +0100 Subject: [PATCH] [Transform] Fix stats can return old state information if security is enabled (#51732) (#51739) do index refresh of the internal transform index with the system user instead of using the calling user which does not have sufficient rights if security is enabled fixes #51728 --- .../action/TransportStopTransformAction.java | 14 ++++---------- .../IndexBasedTransformConfigManager.java | 13 +++++++++++++ .../persistence/TransformConfigManager.java | 1 + .../InMemoryTransformConfigManager.java | 5 +++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStopTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStopTransformAction.java index 98c45e1118657..3c77bc765503a 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStopTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStopTransformAction.java @@ -43,7 +43,6 @@ import org.elasticsearch.xpack.core.transform.transforms.TransformState; import org.elasticsearch.xpack.core.transform.transforms.TransformTaskParams; import org.elasticsearch.xpack.core.transform.transforms.TransformTaskState; -import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants; import org.elasticsearch.xpack.transform.TransformServices; import org.elasticsearch.xpack.transform.persistence.TransformConfigManager; import org.elasticsearch.xpack.transform.transforms.TransformTask; @@ -67,7 +66,6 @@ public class TransportStopTransformAction extends TransportTasksAction transformIds, boolean isForce) { @@ -274,13 +271,10 @@ protected StopTransformAction.Response newResponse( private ActionListener waitForStopListener(Request request, ActionListener listener) { ActionListener onStopListener = ActionListener.wrap( - waitResponse -> client.admin() - .indices() - .prepareRefresh(TransformInternalIndexConstants.LATEST_INDEX_NAME) - .execute(ActionListener.wrap(r -> listener.onResponse(waitResponse), e -> { - logger.info("Failed to refresh internal index after delete", e); - listener.onResponse(waitResponse); - })), + waitResponse -> transformConfigManager.refresh(ActionListener.wrap(r -> listener.onResponse(waitResponse), e -> { + logger.warn("Could not refresh state, state information might be outdated", e); + listener.onResponse(waitResponse); + })), listener::onFailure ); return ActionListener.wrap( diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/IndexBasedTransformConfigManager.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/IndexBasedTransformConfigManager.java index e3345aa6a2d83..338a17dec6905 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/IndexBasedTransformConfigManager.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/IndexBasedTransformConfigManager.java @@ -14,6 +14,8 @@ import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.DocWriteRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.bulk.BulkItemResponse; import org.elasticsearch.action.index.IndexAction; import org.elasticsearch.action.index.IndexRequest; @@ -634,6 +636,17 @@ public void getTransformStoredDocs(Collection transformIds, ActionListen ); } + @Override + public void refresh(ActionListener listener) { + executeAsyncWithOrigin( + client.threadPool().getThreadContext(), + TRANSFORM_ORIGIN, + new RefreshRequest(TransformInternalIndexConstants.LATEST_INDEX_NAME), + ActionListener.wrap(r -> listener.onResponse(true), listener::onFailure), + client.admin().indices()::refresh + ); + } + private void parseTransformLenientlyFromSource( BytesReference source, String transformId, diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformConfigManager.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformConfigManager.java index 61c639964e963..bc1465f6ceafa 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformConfigManager.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformConfigManager.java @@ -149,4 +149,5 @@ void putOrUpdateTransformStoredDoc( void getTransformStoredDocs(Collection transformIds, ActionListener> listener); + void refresh(ActionListener listener); } diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/InMemoryTransformConfigManager.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/InMemoryTransformConfigManager.java index c52e8dea8fde2..d8ee3d309a8e5 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/InMemoryTransformConfigManager.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/InMemoryTransformConfigManager.java @@ -214,4 +214,9 @@ public void getTransformStoredDocs(Collection transformIds, ActionListen listener.onResponse(docs); } + @Override + public void refresh(ActionListener listener) { + listener.onResponse(true); + } + }