Skip to content

Commit 6b3d6bd

Browse files
prwhelanchrisparrinello
authored andcommitted
[ML] Disable CrossProject for Datafeeds (elastic#136897)
Initially, Datafeeds will not support cross-project source indices. We will verify that the IndicesOptions is not trying to resolve a cross-project index expression and throw a cross-project specific error message.
1 parent f9d8cba commit 6b3d6bd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
1111
import org.elasticsearch.ElasticsearchException;
12+
import org.elasticsearch.ElasticsearchStatusException;
1213
import org.elasticsearch.TransportVersion;
1314
import org.elasticsearch.action.search.SearchRequest;
1415
import org.elasticsearch.action.support.IndicesOptions;
@@ -21,6 +22,7 @@
2122
import org.elasticsearch.core.TimeValue;
2223
import org.elasticsearch.core.Tuple;
2324
import org.elasticsearch.index.query.QueryBuilder;
25+
import org.elasticsearch.rest.RestStatus;
2426
import org.elasticsearch.search.aggregations.AggregationBuilder;
2527
import org.elasticsearch.search.aggregations.AggregatorFactories;
2628
import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregationBuilder;
@@ -1050,6 +1052,10 @@ public DatafeedConfig build() {
10501052
if (indicesOptions == null) {
10511053
indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN_HIDDEN_FORBID_CLOSED;
10521054
}
1055+
if (indicesOptions.resolveCrossProjectIndexExpression()) {
1056+
throw new ElasticsearchStatusException("Cross-project search is not enabled for Datafeeds", RestStatus.FORBIDDEN);
1057+
}
1058+
10531059
return new DatafeedConfig(
10541060
id,
10551061
jobId,

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfigBuilderTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
*/
77
package org.elasticsearch.xpack.core.ml.datafeed;
88

9+
import org.elasticsearch.ElasticsearchStatusException;
910
import org.elasticsearch.action.search.SearchRequest;
1011
import org.elasticsearch.action.support.IndicesOptions;
1112
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1213
import org.elasticsearch.common.io.stream.Writeable;
1314
import org.elasticsearch.common.settings.Settings;
1415
import org.elasticsearch.core.TimeValue;
16+
import org.elasticsearch.rest.RestStatus;
1517
import org.elasticsearch.search.SearchModule;
1618
import org.elasticsearch.search.aggregations.AggregationBuilder;
1719
import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -30,6 +32,7 @@
3032

3133
import static org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfigTests.randomStringList;
3234
import static org.elasticsearch.xpack.core.ml.utils.QueryProviderTests.createTestQueryProvider;
35+
import static org.hamcrest.Matchers.equalTo;
3336

3437
public class DatafeedConfigBuilderTests extends AbstractWireSerializingTestCase<DatafeedConfig.Builder> {
3538

@@ -147,4 +150,17 @@ protected Writeable.Reader<DatafeedConfig.Builder> instanceReader() {
147150
return DatafeedConfig.Builder::new;
148151
}
149152

153+
public void testResolveCrossProjectIsDisabled() {
154+
var datafeedBuilder = createRandomizedDatafeedConfigBuilder("jobId", "datafeed-id", 3600000);
155+
datafeedBuilder = datafeedBuilder.setIndicesOptions(
156+
IndicesOptions.builder(datafeedBuilder.getIndicesOptions())
157+
.crossProjectModeOptions(new IndicesOptions.CrossProjectModeOptions(true))
158+
.build()
159+
);
160+
161+
var actualException = assertThrows(ElasticsearchStatusException.class, datafeedBuilder::build);
162+
assertThat(actualException.getMessage(), equalTo("Cross-project search is not enabled for Datafeeds"));
163+
assertThat(actualException.status(), equalTo(RestStatus.FORBIDDEN));
164+
}
165+
150166
}

0 commit comments

Comments
 (0)