-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Skip remote clusters when performing up front privileges validat…
…ion (#91895)
- Loading branch information
1 parent
9e04540
commit 23eafaa
Showing
7 changed files
with
363 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 91895 | ||
summary: Skip remote clusters when performing up front privileges validation for datafeeds | ||
area: Machine Learning | ||
type: bug | ||
issues: | ||
- 87832 |
63 changes: 63 additions & 0 deletions
63
x-pack/plugin/ml/qa/multi-cluster-tests-with-security/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import org.elasticsearch.gradle.internal.test.RestIntegTestTask | ||
import org.elasticsearch.gradle.Version | ||
import org.elasticsearch.gradle.VersionProperties | ||
|
||
apply plugin: 'elasticsearch.internal-testclusters' | ||
apply plugin: 'elasticsearch.standalone-rest-test' | ||
apply plugin: 'elasticsearch.rest-resources' | ||
|
||
dependencies { | ||
testImplementation project(':x-pack:qa') | ||
} | ||
|
||
Version ccsCompatVersion = new Version(VersionProperties.getElasticsearchVersion().getMajor(), VersionProperties.getElasticsearchVersion().getMinor() - 1, 0) | ||
|
||
restResources { | ||
restApi { | ||
include '_common', 'bulk', 'indices', 'cluster', 'search', 'security', 'ml' | ||
} | ||
} | ||
|
||
def remoteCluster = testClusters.register('remote-cluster') { | ||
testDistribution = 'DEFAULT' | ||
versions = [ccsCompatVersion.toString(), project.version] | ||
numberOfNodes = 2 | ||
setting 'node.roles', '[data,ingest,master]' | ||
setting 'xpack.security.enabled', 'true' | ||
setting 'xpack.watcher.enabled', 'false' | ||
setting 'xpack.license.self_generated.type', 'trial' | ||
|
||
user username: "test_user", password: "x-pack-test-password" | ||
} | ||
|
||
testClusters.register('mixed-cluster') { | ||
testDistribution = 'DEFAULT' | ||
numberOfNodes = 2 | ||
setting 'node.roles', '[data,ingest,master]' | ||
setting 'xpack.security.enabled', 'true' | ||
setting 'xpack.watcher.enabled', 'false' | ||
setting 'xpack.license.self_generated.type', 'trial' | ||
setting 'cluster.remote.my_remote_cluster.seeds', { | ||
remoteCluster.get().getAllTransportPortURI().collect { "\"$it\"" }.toString() | ||
} | ||
setting 'cluster.remote.connections_per_cluster', "1" | ||
|
||
user username: "test_user", password: "x-pack-test-password" | ||
} | ||
|
||
tasks.register('remote-cluster', RestIntegTestTask) { | ||
mustRunAfter("precommit") | ||
systemProperty 'tests.rest.suite', 'remote_cluster' | ||
} | ||
|
||
tasks.register('mixed-cluster', RestIntegTestTask) { | ||
dependsOn 'remote-cluster' | ||
useCluster remoteCluster | ||
systemProperty 'tests.rest.suite', 'multi_cluster' | ||
} | ||
|
||
tasks.register("integTest") { | ||
dependsOn 'mixed-cluster' | ||
} | ||
|
||
tasks.named("check").configure { dependsOn("integTest") } |
46 changes: 46 additions & 0 deletions
46
...h-security/src/test/java/org/elasticsearch/multi_cluster/MultiClusterYamlTestSuiteIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.multi_cluster; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.Name; | ||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; | ||
|
||
import org.apache.lucene.tests.util.TimeUnits; | ||
import org.elasticsearch.common.settings.SecureString; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; | ||
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; | ||
|
||
@TimeoutSuite(millis = 5 * TimeUnits.MINUTE) // to account for slow as hell VMs | ||
public class MultiClusterYamlTestSuiteIT extends ESClientYamlSuiteTestCase { | ||
|
||
private static final String USER = "test_user"; | ||
private static final String PASS = "x-pack-test-password"; | ||
|
||
@Override | ||
protected boolean preserveIndicesUponCompletion() { | ||
return true; | ||
} | ||
|
||
public MultiClusterYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { | ||
super(testCandidate); | ||
} | ||
|
||
@ParametersFactory | ||
public static Iterable<Object[]> parameters() throws Exception { | ||
return createParameters(); | ||
} | ||
|
||
@Override | ||
protected Settings restClientSettings() { | ||
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray())); | ||
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build(); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
...uster-tests-with-security/src/test/resources/rest-api-spec/test/multi_cluster/30_jobs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
setup: | ||
- skip: | ||
features: headers | ||
|
||
- do: | ||
cluster.health: | ||
wait_for_status: yellow | ||
|
||
- do: | ||
security.put_user: | ||
username: "joe" | ||
body: > | ||
{ | ||
"password": "joe-password", | ||
"roles" : [ "x_cluster_role" ] | ||
} | ||
- do: | ||
security.put_role: | ||
name: "x_cluster_role" | ||
body: > | ||
{ | ||
"cluster": ["manage_ml"], | ||
"indices": [ | ||
{ | ||
"names": ["test_index"], | ||
"privileges": ["read", "view_index_metadata"] | ||
} | ||
] | ||
} | ||
--- | ||
teardown: | ||
- do: | ||
security.delete_user: | ||
username: "joe" | ||
ignore: 404 | ||
|
||
--- | ||
"Test ML job with local indices only": | ||
- do: | ||
catch: /Cannot create datafeed \[job-with-local-indices\] because user joe lacks permissions on the indices/ | ||
headers: { Authorization: "Basic am9lOmpvZS1wYXNzd29yZA==" } # This is joe | ||
ml.put_job: | ||
job_id: job-with-local-indices | ||
body: > | ||
{ | ||
"description":"Analysis of response time by airline", | ||
"analysis_config" : { | ||
"detectors" :[{"function":"count"}] | ||
}, | ||
"analysis_limits" : { | ||
"model_memory_limit": "20mb" | ||
}, | ||
"data_description" : { | ||
"format":"xcontent" | ||
}, | ||
"datafeed_config": { | ||
"indexes":["test_index", "test_index-2"] | ||
} | ||
} | ||
--- | ||
"Test ML job with local and remote index": | ||
- do: | ||
headers: { Authorization: "Basic am9lOmpvZS1wYXNzd29yZA==" } # This is joe | ||
ml.put_job: | ||
job_id: job-with-local-and-remote-index | ||
body: > | ||
{ | ||
"description":"Analysis of response time by airline", | ||
"analysis_config" : { | ||
"detectors" :[{"function":"count"}] | ||
}, | ||
"analysis_limits" : { | ||
"model_memory_limit": "20mb" | ||
}, | ||
"data_description" : { | ||
"format":"xcontent" | ||
}, | ||
"datafeed_config": { | ||
"indexes":["test_index", "my_remote_cluster:remote_test_index"] | ||
} | ||
} | ||
- match: { job_id: "job-with-local-and-remote-index" } | ||
- is_true: datafeed_config | ||
- match: { datafeed_config.job_id: "job-with-local-and-remote-index" } | ||
- match: { datafeed_config.datafeed_id: "job-with-local-and-remote-index" } | ||
- is_true: datafeed_config.authorization.roles | ||
- is_true: create_time | ||
|
||
--- | ||
"Test ML job with remote index only": | ||
- do: | ||
headers: { Authorization: "Basic am9lOmpvZS1wYXNzd29yZA==" } # This is joe | ||
ml.put_job: | ||
job_id: job-with-remote-index-only | ||
body: > | ||
{ | ||
"description":"Analysis of response time by airline", | ||
"analysis_config" : { | ||
"detectors" :[{"function":"count"}] | ||
}, | ||
"analysis_limits" : { | ||
"model_memory_limit": "20mb" | ||
}, | ||
"data_description" : { | ||
"format":"xcontent" | ||
}, | ||
"datafeed_config": { | ||
"indexes":["my_remote_cluster:remote_test_index"] | ||
} | ||
} | ||
- match: { job_id: "job-with-remote-index-only" } | ||
- is_true: datafeed_config | ||
- match: { datafeed_config.job_id: "job-with-remote-index-only" } | ||
- match: { datafeed_config.datafeed_id: "job-with-remote-index-only" } | ||
- is_true: datafeed_config.authorization.roles | ||
- is_true: create_time |
97 changes: 97 additions & 0 deletions
97
...ster-tests-with-security/src/test/resources/rest-api-spec/test/remote_cluster/30_jobs.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
setup: | ||
- skip: | ||
features: headers | ||
|
||
- do: | ||
cluster.health: | ||
wait_for_status: yellow | ||
- do: | ||
security.put_user: | ||
username: "joe" | ||
body: > | ||
{ | ||
"password": "joe-password", | ||
"roles" : [ "x_cluster_role" ] | ||
} | ||
- do: | ||
security.put_role: | ||
name: "x_cluster_role" | ||
body: > | ||
{ | ||
"cluster": [], | ||
"indices": [ | ||
{ | ||
"names": ["remote_test_index"], | ||
"privileges": ["read", "view_index_metadata"] | ||
} | ||
] | ||
} | ||
--- | ||
teardown: | ||
- do: | ||
security.delete_user: | ||
username: "joe" | ||
ignore: 404 | ||
|
||
--- | ||
"Index data on the remote cluster": | ||
- do: | ||
indices.create: | ||
index: remote_test_index | ||
body: | ||
settings: | ||
index: | ||
number_of_shards: 3 | ||
number_of_replicas: 0 | ||
aliases: | ||
test_alias: {} | ||
mappings: | ||
properties: | ||
time: | ||
type: date | ||
user: | ||
type: keyword | ||
stars: | ||
type: integer | ||
coolness: | ||
type: integer | ||
|
||
- do: | ||
bulk: | ||
refresh: true | ||
body: | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "a", "stars": 1, "date" : "2018-10-29T12:12:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "a", "stars": 4, "date" : "2018-10-29T12:14:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "a", "stars": 5, "date" : "2018-10-29T12:16:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "b", "stars": 2, "date" : "2018-10-29T12:17:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "b", "stars": 3, "date" : "2018-10-29T12:22:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "a", "stars": 5, "date" : "2018-10-29T12:23:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "b", "stars": 1, "date" : "2018-10-29T12:32:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "a", "stars": 3, "date" : "2018-10-29T12:34:12.123456789Z"}' | ||
- '{"index": {"_index": "remote_test_index"}}' | ||
- '{"user": "c", "stars": 4, "date" : "2018-10-29T12:35:12.123456789Z"}' | ||
- do: | ||
headers: { Authorization: "Basic am9lOmpvZS1wYXNzd29yZA==" } # This is joe | ||
search: | ||
rest_total_hits_as_int: true | ||
index: remote_test_index | ||
body: | ||
aggs: | ||
user: | ||
terms: | ||
field: user | ||
|
||
- match: { _shards.total: 3 } | ||
- match: { hits.total: 9 } | ||
- length: { aggregations.user.buckets: 3 } | ||
- match: { aggregations.user.buckets.0.key: "a" } | ||
- match: { aggregations.user.buckets.0.doc_count: 5 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.