Skip to content

Commit

Permalink
[Transform] Fix stats can return old state information if security is…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Hendrik Muhs authored Feb 12, 2020
1 parent a3cfa5a commit 0460712
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -67,7 +66,6 @@ public class TransportStopTransformAction extends TransportTasksAction<Transform
private final ThreadPool threadPool;
private final TransformConfigManager transformConfigManager;
private final PersistentTasksService persistentTasksService;
private final Client client;

@Inject
public TransportStopTransformAction(
Expand Down Expand Up @@ -105,7 +103,6 @@ protected TransportStopTransformAction(
this.threadPool = threadPool;
this.transformConfigManager = transformServices.getConfigManager();
this.persistentTasksService = persistentTasksService;
this.client = client;
}

static void validateTaskState(ClusterState state, List<String> transformIds, boolean isForce) {
Expand Down Expand Up @@ -274,13 +271,10 @@ protected StopTransformAction.Response newResponse(
private ActionListener<Response> waitForStopListener(Request request, ActionListener<Response> listener) {

ActionListener<Response> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -634,6 +636,17 @@ public void getTransformStoredDocs(Collection<String> transformIds, ActionListen
);
}

@Override
public void refresh(ActionListener<Boolean> listener) {
executeAsyncWithOrigin(
client.threadPool().getThreadContext(),
TRANSFORM_ORIGIN,
new RefreshRequest(TransformInternalIndexConstants.LATEST_INDEX_NAME),
ActionListener.<RefreshResponse>wrap(r -> listener.onResponse(true), listener::onFailure),
client.admin().indices()::refresh
);
}

private void parseTransformLenientlyFromSource(
BytesReference source,
String transformId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ void putOrUpdateTransformStoredDoc(

void getTransformStoredDocs(Collection<String> transformIds, ActionListener<List<TransformStoredDoc>> listener);

void refresh(ActionListener<Boolean> listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,9 @@ public void getTransformStoredDocs(Collection<String> transformIds, ActionListen
listener.onResponse(docs);
}

@Override
public void refresh(ActionListener<Boolean> listener) {
listener.onResponse(true);
}

}

0 comments on commit 0460712

Please sign in to comment.