diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java index 6cf06695c7c91..0e1ca9dd9aec3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportDeleteExpiredDataAction.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction; import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.ml.job.retention.ExpiredForecastsRemover; @@ -40,7 +41,7 @@ public TransportDeleteExpiredDataAction(Settings settings, ThreadPool threadPool Client client, ClusterService clusterService) { super(settings, DeleteExpiredDataAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, DeleteExpiredDataAction.Request::new); - this.client = client; + this.client = ClientHelper.clientWithOrigin(client, ClientHelper.ML_ORIGIN); this.clusterService = clusterService; } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java index 30c49a834be58..75deb7bf0ae6d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredForecastsRemover.java @@ -45,6 +45,10 @@ * Removes up to {@link #MAX_FORECASTS} forecasts (stats + forecasts docs) that have expired. * A forecast is deleted if its expiration timestamp is earlier * than the start of the current day (local time-zone). + * + * This is expected to be used by actions requiring admin rights. Thus, + * it is also expected that the provided client will be a client with the + * ML origin so that permissions to manage ML indices are met. */ public class ExpiredForecastsRemover implements MlDataRemover { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemover.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemover.java index 3b1105774ea66..8808ed34277a4 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemover.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredModelSnapshotsRemover.java @@ -34,6 +34,10 @@ * of their respective job with the exception of the currently used snapshot. * A snapshot is deleted if its timestamp is earlier than the start of the * current day (local time-zone) minus the retention period. + * + * This is expected to be used by actions requiring admin rights. Thus, + * it is also expected that the provided client will be a client with the + * ML origin so that permissions to manage ML indices are met. */ public class ExpiredModelSnapshotsRemover extends AbstractExpiredJobDataRemover { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java index 3f0ca4558b570..f59fdddedecdb 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/retention/ExpiredResultsRemover.java @@ -33,14 +33,15 @@ import java.time.format.DateTimeFormatter; import java.util.Objects; -import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; -import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; - /** * Removes all results that have expired the configured retention time * of their respective job. A result is deleted if its timestamp is earlier * than the start of the current day (local time-zone) minus the retention * period. + * + * This is expected to be used by actions requiring admin rights. Thus, + * it is also expected that the provided client will be a client with the + * ML origin so that permissions to manage ML indices are met. */ public class ExpiredResultsRemover extends AbstractExpiredJobDataRemover { @@ -65,7 +66,7 @@ protected void removeDataBefore(Job job, long cutoffEpochMs, ActionListener() { + client.execute(DeleteByQueryAction.INSTANCE, request, new ActionListener() { @Override public void onResponse(BulkByScrollResponse bulkByScrollResponse) { try {