Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,10 @@ public DatafeedConfig build() {
if (indicesOptions == null) {
indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN_HIDDEN_FORBID_CLOSED;
}
if (indicesOptions.resolveCrossProjectIndexExpression()) {
throw ExceptionsHelper.crossProjectSearchIsDisabled();
}

return new DatafeedConfig(
id,
jobId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public static ElasticsearchStatusException taskOperationFailureToStatusException
return new ElasticsearchStatusException(failure.getCause().getMessage(), failure.getStatus(), failure.getCause());
}

public static ElasticsearchStatusException crossProjectSearchIsDisabled() {
return new ElasticsearchStatusException("Cross-project search is not enabled for any ML feature", RestStatus.FORBIDDEN);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its useful to track and throw for particular features if possible. Can we specify Datafeeds here?

}

/**
* Creates an error message that explains there are shard failures, displays info
* for the first failure (shard/reason) and kindly asks to see more info in the logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/
package org.elasticsearch.xpack.core.ml.datafeed;

import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
Expand All @@ -30,6 +32,7 @@

import static org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfigTests.randomStringList;
import static org.elasticsearch.xpack.core.ml.utils.QueryProviderTests.createTestQueryProvider;
import static org.hamcrest.Matchers.equalTo;

public class DatafeedConfigBuilderTests extends AbstractWireSerializingTestCase<DatafeedConfig.Builder> {

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

public void testResolveCrossProjectIsDisabled() {
var datafeedBuilder = createRandomizedDatafeedConfigBuilder("jobId", "datafeed-id", 3600000);
datafeedBuilder = datafeedBuilder.setIndicesOptions(
IndicesOptions.builder(datafeedBuilder.getIndicesOptions())
.crossProjectModeOptions(new IndicesOptions.CrossProjectModeOptions(true))
.build()
);

var actualException = assertThrows(ElasticsearchStatusException.class, datafeedBuilder::build);
assertThat(actualException.getMessage(), equalTo("Cross-project search is not enabled for any ML feature"));
assertThat(actualException.status(), equalTo(RestStatus.FORBIDDEN));
}

}