1515import org .elasticsearch .test .MapMatcher ;
1616import org .elasticsearch .test .cluster .ElasticsearchCluster ;
1717import org .elasticsearch .test .cluster .util .resource .Resource ;
18- import org .elasticsearch .test .junit .RunnableTestRuleAdapter ;
1918import org .elasticsearch .xcontent .XContentBuilder ;
2019import org .elasticsearch .xcontent .json .JsonXContent ;
2120import org .junit .ClassRule ;
2423
2524import java .io .IOException ;
2625import java .util .Locale ;
27- import java .util .Map ;
28- import java .util .concurrent .atomic .AtomicBoolean ;
29- import java .util .concurrent .atomic .AtomicReference ;
3026
3127import static org .elasticsearch .test .ListMatcher .matchesList ;
3228import static org .elasticsearch .test .MapMatcher .assertMap ;
3329import static org .elasticsearch .test .MapMatcher .matchesMap ;
3430
35- public class RemoteClusterSecurityDataStreamEsqlIT extends AbstractRemoteClusterSecurityTestCase {
36- private static final AtomicReference <Map <String , Object >> API_KEY_MAP_REF = new AtomicReference <>();
37- private static final AtomicBoolean SSL_ENABLED_REF = new AtomicBoolean ();
38- private static final AtomicBoolean NODE1_RCS_SERVER_ENABLED = new AtomicBoolean ();
39- private static final AtomicBoolean NODE2_RCS_SERVER_ENABLED = new AtomicBoolean ();
40-
31+ // TODO consolidate me with RemoteClusterSecurityDataStreamEsqlRcs2IT
32+ public class RemoteClusterSecurityDataStreamEsqlRcs1IT extends AbstractRemoteClusterSecurityTestCase {
4133 static {
4234 fulfillingCluster = ElasticsearchCluster .local ()
4335 .name ("fulfilling-cluster" )
44- .nodes (3 )
4536 .module ("x-pack-autoscaling" )
4637 .module ("x-pack-esql" )
4738 .module ("x-pack-enrich" )
4839 .module ("x-pack-ml" )
4940 .module ("x-pack-ilm" )
5041 .module ("ingest-common" )
5142 .apply (commonClusterConfig )
52- .setting ("remote_cluster.port" , "0" )
5343 .setting ("xpack.ml.enabled" , "false" )
54- .setting ("xpack.security.remote_cluster_server.ssl.enabled" , () -> String .valueOf (SSL_ENABLED_REF .get ()))
55- .setting ("xpack.security.remote_cluster_server.ssl.key" , "remote-cluster.key" )
56- .setting ("xpack.security.remote_cluster_server.ssl.certificate" , "remote-cluster.crt" )
5744 .setting ("xpack.security.authc.token.enabled" , "true" )
58- .keystore ("xpack.security.remote_cluster_server.ssl.secure_key_passphrase" , "remote-cluster-password" )
59- .node (0 , spec -> spec .setting ("remote_cluster_server.enabled" , "true" ))
60- .node (1 , spec -> spec .setting ("remote_cluster_server.enabled" , () -> String .valueOf (NODE1_RCS_SERVER_ENABLED .get ())))
61- .node (2 , spec -> spec .setting ("remote_cluster_server.enabled" , () -> String .valueOf (NODE2_RCS_SERVER_ENABLED .get ())))
45+ .rolesFile (Resource .fromClasspath ("roles.yml" ))
6246 .build ();
6347
6448 queryCluster = ElasticsearchCluster .local ()
@@ -71,23 +55,7 @@ public class RemoteClusterSecurityDataStreamEsqlIT extends AbstractRemoteCluster
7155 .module ("ingest-common" )
7256 .apply (commonClusterConfig )
7357 .setting ("xpack.ml.enabled" , "false" )
74- .setting ("xpack.security.remote_cluster_client.ssl.enabled" , () -> String .valueOf (SSL_ENABLED_REF .get ()))
75- .setting ("xpack.security.remote_cluster_client.ssl.certificate_authorities" , "remote-cluster-ca.crt" )
7658 .setting ("xpack.security.authc.token.enabled" , "true" )
77- .keystore ("cluster.remote.my_remote_cluster.credentials" , () -> {
78- if (API_KEY_MAP_REF .get () == null ) {
79- final Map <String , Object > apiKeyMap = createCrossClusterAccessApiKey ("""
80- {
81- "search": [
82- {
83- "names": ["logs-*", "alias-*"]
84- }
85- ]
86- }""" );
87- API_KEY_MAP_REF .set (apiKeyMap );
88- }
89- return (String ) API_KEY_MAP_REF .get ().get ("encoded" );
90- })
9159 .rolesFile (Resource .fromClasspath ("roles.yml" ))
9260 .user ("logs_foo_all" , "x-pack-test-password" , "logs_foo_all" , false )
9361 .user ("logs_foo_16_only" , "x-pack-test-password" , "logs_foo_16_only" , false )
@@ -98,37 +66,62 @@ public class RemoteClusterSecurityDataStreamEsqlIT extends AbstractRemoteCluster
9866 }
9967
10068 @ ClassRule
101- // Use a RuleChain to ensure that fulfilling cluster is started before query cluster
102- // `SSL_ENABLED_REF` is used to control the SSL-enabled setting on the test clusters
103- // We set it here, since randomization methods are not available in the static initialize context above
104- public static TestRule clusterRule = RuleChain .outerRule (new RunnableTestRuleAdapter (() -> {
105- SSL_ENABLED_REF .set (usually ());
106- NODE1_RCS_SERVER_ENABLED .set (randomBoolean ());
107- NODE2_RCS_SERVER_ENABLED .set (randomBoolean ());
108- })).around (fulfillingCluster ).around (queryCluster );
69+ public static TestRule clusterRule = RuleChain .outerRule (fulfillingCluster ).around (queryCluster );
10970
11071 public void testDataStreamsWithDls () throws Exception {
111- configureRemoteCluster ();
112- createDataStream ();
72+ configureRemoteCluster (REMOTE_CLUSTER_ALIAS , fulfillingCluster , true , randomBoolean (), randomBoolean ());
73+ createDataStreamOnFulfillingCluster ();
74+
11375 MapMatcher twoResults = matchesMap ().extraOk ().entry ("values" , matchesList ().item (matchesList ().item (2 )));
11476 MapMatcher oneResult = matchesMap ().extraOk ().entry ("values" , matchesList ().item (matchesList ().item (1 )));
115- assertMap (entityAsMap (runESQLCommand ("logs_foo_all" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )), twoResults );
116- assertMap (entityAsMap (runESQLCommand ("logs_foo_16_only" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )), oneResult );
117- assertMap (entityAsMap (runESQLCommand ("logs_foo_after_2021" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )), oneResult );
11877 assertMap (
119- entityAsMap (runESQLCommand ("logs_foo_after_2021_pattern" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )),
78+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_all" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )),
79+ twoResults
80+ );
81+ assertMap (
82+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_16_only" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )),
83+ oneResult
84+ );
85+ assertMap (
86+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_after_2021" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )),
87+ oneResult
88+ );
89+ assertMap (
90+ entityAsMap (
91+ runESQLCommandAgainstQueryCluster ("logs_foo_after_2021_pattern" , "FROM my_remote_cluster:logs-foo | STATS COUNT(*)" )
92+ ),
93+ oneResult
94+ );
95+ assertMap (
96+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_all" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )),
97+ twoResults
98+ );
99+ assertMap (
100+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_16_only" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )),
101+ oneResult
102+ );
103+ assertMap (
104+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_after_2021" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )),
105+ oneResult
106+ );
107+ assertMap (
108+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_after_2021_pattern" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )),
120109 oneResult
121110 );
122- assertMap (entityAsMap (runESQLCommand ("logs_foo_all" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )), twoResults );
123- assertMap (entityAsMap (runESQLCommand ("logs_foo_16_only" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )), oneResult );
124- assertMap (entityAsMap (runESQLCommand ("logs_foo_after_2021" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )), oneResult );
125- assertMap (entityAsMap (runESQLCommand ("logs_foo_after_2021_pattern" , "FROM my_remote_cluster:logs-* | STATS COUNT(*)" )), oneResult );
126111
127- assertMap (entityAsMap (runESQLCommand ("logs_foo_after_2021_alias" , "FROM my_remote_cluster:alias-foo | STATS COUNT(*)" )), oneResult );
128- assertMap (entityAsMap (runESQLCommand ("logs_foo_after_2021_alias" , "FROM my_remote_cluster:alias-* | STATS COUNT(*)" )), oneResult );
112+ assertMap (
113+ entityAsMap (
114+ runESQLCommandAgainstQueryCluster ("logs_foo_after_2021_alias" , "FROM my_remote_cluster:alias-foo | STATS COUNT(*)" )
115+ ),
116+ oneResult
117+ );
118+ assertMap (
119+ entityAsMap (runESQLCommandAgainstQueryCluster ("logs_foo_after_2021_alias" , "FROM my_remote_cluster:alias-* | STATS COUNT(*)" )),
120+ oneResult
121+ );
129122 }
130123
131- protected Response runESQLCommand (String user , String command ) throws IOException {
124+ static Response runESQLCommandAgainstQueryCluster (String user , String command ) throws IOException {
132125 if (command .toLowerCase (Locale .ROOT ).contains ("limit" ) == false ) {
133126 // add a (high) limit to avoid warnings on default limit
134127 command += " | limit 10000000" ;
@@ -176,15 +169,15 @@ static Settings randomPragmas() {
176169 return settings .build ();
177170 }
178171
179- private void createDataStream () throws IOException {
172+ static void createDataStreamOnFulfillingCluster () throws IOException {
180173 createDataStreamPolicy ();
181174 createDataStreamComponentTemplate ();
182175 createDataStreamIndexTemplate ();
183176 createDataStreamDocuments ();
184177 createDataStreamAlias ();
185178 }
186179
187- private void createDataStreamPolicy () throws IOException {
180+ private static void createDataStreamPolicy () throws IOException {
188181 Request request = new Request ("PUT" , "_ilm/policy/my-lifecycle-policy" );
189182 request .setJsonEntity ("""
190183 {
@@ -210,7 +203,7 @@ private void createDataStreamPolicy() throws IOException {
210203 performRequestAgainstFulfillingCluster (request );
211204 }
212205
213- private void createDataStreamComponentTemplate () throws IOException {
206+ private static void createDataStreamComponentTemplate () throws IOException {
214207 Request request = new Request ("PUT" , "_component_template/my-template" );
215208 request .setJsonEntity ("""
216209 {
@@ -236,7 +229,7 @@ private void createDataStreamComponentTemplate() throws IOException {
236229 performRequestAgainstFulfillingCluster (request );
237230 }
238231
239- private void createDataStreamIndexTemplate () throws IOException {
232+ private static void createDataStreamIndexTemplate () throws IOException {
240233 Request request = new Request ("PUT" , "_index_template/my-index-template" );
241234 request .setJsonEntity ("""
242235 {
@@ -248,7 +241,7 @@ private void createDataStreamIndexTemplate() throws IOException {
248241 performRequestAgainstFulfillingCluster (request );
249242 }
250243
251- private void createDataStreamDocuments () throws IOException {
244+ private static void createDataStreamDocuments () throws IOException {
252245 Request request = new Request ("POST" , "logs-foo/_bulk" );
253246 request .addParameter ("refresh" , "" );
254247 request .setJsonEntity ("""
@@ -260,7 +253,7 @@ private void createDataStreamDocuments() throws IOException {
260253 assertMap (entityAsMap (performRequestAgainstFulfillingCluster (request )), matchesMap ().extraOk ().entry ("errors" , false ));
261254 }
262255
263- private void createDataStreamAlias () throws IOException {
256+ private static void createDataStreamAlias () throws IOException {
264257 Request request = new Request ("PUT" , "_alias" );
265258 request .setJsonEntity ("""
266259 {
@@ -275,6 +268,4 @@ private void createDataStreamAlias() throws IOException {
275268 }""" );
276269 assertMap (entityAsMap (performRequestAgainstFulfillingCluster (request )), matchesMap ().extraOk ().entry ("errors" , false ));
277270 }
278-
279- record ExpectedCluster (String clusterAlias , String indexExpression , String status , Integer totalShards ) {}
280271}
0 commit comments