Skip to content

Commit ce9f17d

Browse files
authored
Enabled security on a bunch of logsdb and tsdb javaRestTests (#137135)
1 parent 3d272e1 commit ce9f17d

File tree

9 files changed

+122
-11
lines changed

9 files changed

+122
-11
lines changed

modules/data-streams/src/javaRestTest/java/org/elasticsearch/datastreams/MultiClustersIT.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import org.elasticsearch.client.RestClient;
1717
import org.elasticsearch.common.Randomness;
1818
import org.elasticsearch.common.Strings;
19+
import org.elasticsearch.common.settings.SecureString;
20+
import org.elasticsearch.common.settings.Settings;
21+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1922
import org.elasticsearch.common.xcontent.XContentHelper;
2023
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2124
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
@@ -52,12 +55,16 @@ public class MultiClustersIT extends ESRestTestCase {
5255
static List<Document> localStandardDocs = null;
5356
static List<Document> remoteStandardDocs = null;
5457

58+
private static final String USER = "test_admin";
59+
private static final String PASS = "x-pack-test-password";
60+
5561
public static ElasticsearchCluster remoteCluster = ElasticsearchCluster.local()
5662
.name("remote_cluster")
5763
.distribution(DistributionType.DEFAULT)
5864
.module("data-streams")
5965
.module("x-pack-stack")
60-
.setting("xpack.security.enabled", "false")
66+
.setting("xpack.security.autoconfiguration.enabled", "false")
67+
.user(USER, PASS)
6168
.setting("xpack.license.self_generated.type", "trial")
6269
.setting("cluster.logsdb.enabled", "true")
6370
.build();
@@ -67,7 +74,8 @@ public class MultiClustersIT extends ESRestTestCase {
6774
.distribution(DistributionType.DEFAULT)
6875
.module("data-streams")
6976
.module("x-pack-stack")
70-
.setting("xpack.security.enabled", "false")
77+
.setting("xpack.security.autoconfiguration.enabled", "false")
78+
.user(USER, PASS)
7179
.setting("xpack.license.self_generated.type", "trial")
7280
.setting("cluster.logsdb.enabled", "true")
7381
.setting("node.roles", "[data,ingest,master,remote_cluster_client]")
@@ -89,6 +97,11 @@ private RestClient remoteClusterClient() throws IOException {
8997
return buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[0]));
9098
}
9199

100+
protected Settings restClientSettings() {
101+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
102+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
103+
}
104+
92105
private record Document(long timestamp, String cluster, String hostName, long pid, String method, long messageId, String message) {
93106

94107
@SuppressWarnings("unchecked")

x-pack/plugin/logsdb/qa/with-custom-cutoff/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsdbWithBasicRestIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
package org.elasticsearch.xpack.logsdb;
99

10+
import org.elasticsearch.common.settings.SecureString;
11+
import org.elasticsearch.common.settings.Settings;
12+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1013
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1114
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1215
import org.elasticsearch.test.rest.ESRestTestCase;
@@ -18,11 +21,15 @@
1821

1922
public class LogsdbWithBasicRestIT extends ESRestTestCase {
2023

24+
private static final String USER = "test_admin";
25+
private static final String PASS = "x-pack-test-password";
26+
2127
@ClassRule
2228
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
2329
.distribution(DistributionType.DEFAULT)
2430
.systemProperty("es.mapping.synthetic_source_fallback_to_stored_source.cutoff_date_restricted_override", "2027-12-31T23:59")
25-
.setting("xpack.security.enabled", "false")
31+
.setting("xpack.security.autoconfiguration.enabled", "false")
32+
.user(USER, PASS)
2633
.setting("cluster.logsdb.enabled", "true")
2734
.build();
2835

@@ -31,6 +38,11 @@ protected String getTestRestCluster() {
3138
return cluster.getHttpAddresses();
3239
}
3340

41+
protected Settings restClientSettings() {
42+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
43+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
44+
}
45+
3446
public void testCustomCutoffDateUsage() throws IOException {
3547
var response = getAsMap("/_xpack/usage");
3648
Map<?, ?> usage = (Map<?, ?>) response.get("logsdb");

x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/DataStreamLicenseChangeTestCase.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@
88
package org.elasticsearch.xpack.logsdb;
99

1010
import org.elasticsearch.client.Request;
11+
import org.elasticsearch.common.settings.SecureString;
12+
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1114
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1215
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1316
import org.junit.ClassRule;
1417

1518
import java.io.IOException;
1619

1720
public abstract class DataStreamLicenseChangeTestCase extends LogsIndexModeRestTestIT {
21+
22+
private static final String USER = "test_admin";
23+
private static final String PASS = "x-pack-test-password";
24+
1825
@ClassRule
1926
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
2027
.distribution(DistributionType.DEFAULT)
2128
.module("data-streams")
2229
.module("x-pack-stack")
2330
.setting("cluster.logsdb.enabled", "true")
24-
.setting("xpack.security.enabled", "false")
31+
.setting("xpack.security.autoconfiguration.enabled", "false")
32+
.user(USER, PASS)
2533
.setting("xpack.license.self_generated.type", "basic")
2634
.build();
2735

@@ -30,6 +38,11 @@ protected String getTestRestCluster() {
3038
return cluster.getHttpAddresses();
3139
}
3240

41+
protected Settings restClientSettings() {
42+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
43+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
44+
}
45+
3346
protected static void startBasic() throws IOException {
3447
Request startTrial = new Request("POST", "/_license/start_basic");
3548
startTrial.addParameter("acknowledge", "true");

x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsDbSourceModeMigrationIT.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import org.elasticsearch.client.RestClient;
1313
import org.elasticsearch.common.Strings;
1414
import org.elasticsearch.common.bytes.BytesReference;
15+
import org.elasticsearch.common.settings.SecureString;
16+
import org.elasticsearch.common.settings.Settings;
17+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1518
import org.elasticsearch.common.xcontent.XContentHelper;
1619
import org.elasticsearch.index.query.QueryBuilders;
1720
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -36,6 +39,10 @@
3639
import static org.hamcrest.Matchers.is;
3740

3841
public class LogsDbSourceModeMigrationIT extends LogsIndexModeRestTestIT {
42+
43+
private static final String USER = "test_admin";
44+
private static final String PASS = "x-pack-test-password";
45+
3946
public static final String INDEX_TEMPLATE = """
4047
{
4148
"index_patterns": ["my-logs-*-*"],
@@ -108,7 +115,8 @@ public class LogsDbSourceModeMigrationIT extends LogsIndexModeRestTestIT {
108115
.module("mapper-extras")
109116
.module("x-pack-aggregate-metric")
110117
.module("x-pack-stack")
111-
.setting("xpack.security.enabled", "false")
118+
.setting("xpack.security.autoconfiguration.enabled", "false")
119+
.user(USER, PASS)
112120
.setting("xpack.otel_data.registry.enabled", "false")
113121
.setting("xpack.license.self_generated.type", "trial")
114122
.setting("cluster.logsdb.enabled", "true")
@@ -127,6 +135,11 @@ public void setup() {
127135

128136
private RestClient client;
129137

138+
protected Settings restClientSettings() {
139+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
140+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
141+
}
142+
130143
public void testSwitchFromStoredToSyntheticSource() throws IOException {
131144
assertOK(putComponentTemplate(client, "my-logs-mapping", MAPPING_COMPONENT_TEMPLATE));
132145
assertOK(putComponentTemplate(client, "my-logs-original-source", STORED_SOURCE_COMPONENT_TEMPLATE));

x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import org.elasticsearch.client.Request;
1111
import org.elasticsearch.client.ResponseException;
1212
import org.elasticsearch.client.RestClient;
13+
import org.elasticsearch.common.settings.SecureString;
1314
import org.elasticsearch.common.settings.Settings;
15+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1416
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1517
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1618
import org.junit.Before;
@@ -27,6 +29,10 @@
2729

2830
@SuppressWarnings("unchecked")
2931
public class LogsIndexModeCustomSettingsIT extends LogsIndexModeRestTestIT {
32+
33+
private static final String USER = "test_admin";
34+
private static final String PASS = "x-pack-test-password";
35+
3036
@ClassRule()
3137
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
3238
.distribution(DistributionType.DEFAULT)
@@ -35,7 +41,8 @@ public class LogsIndexModeCustomSettingsIT extends LogsIndexModeRestTestIT {
3541
.module("mapper-extras")
3642
.module("x-pack-aggregate-metric")
3743
.module("x-pack-stack")
38-
.setting("xpack.security.enabled", "false")
44+
.setting("xpack.security.autoconfiguration.enabled", "false")
45+
.user(USER, PASS)
3946
.setting("xpack.otel_data.registry.enabled", "false")
4047
.setting("xpack.license.self_generated.type", "trial")
4148
.setting("cluster.logsdb.enabled", "true")
@@ -54,6 +61,11 @@ public void setup() throws Exception {
5461

5562
private RestClient client;
5663

64+
protected Settings restClientSettings() {
65+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
66+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
67+
}
68+
5769
public void testOverrideIndexSorting() throws IOException {
5870
var indexSortOverrideTemplate = """
5971
{

x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeDisabledRestTestIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
package org.elasticsearch.xpack.logsdb;
99

1010
import org.elasticsearch.client.RestClient;
11+
import org.elasticsearch.common.settings.SecureString;
12+
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1114
import org.elasticsearch.index.IndexMode;
1215
import org.elasticsearch.index.IndexSettings;
1316
import org.elasticsearch.test.cluster.ElasticsearchCluster;
@@ -22,6 +25,9 @@
2225

2326
public class LogsIndexModeDisabledRestTestIT extends LogsIndexModeRestTestIT {
2427

28+
private static final String USER = "test_admin";
29+
private static final String PASS = "x-pack-test-password";
30+
2531
private static final String MAPPINGS = """
2632
{
2733
"template": {
@@ -46,7 +52,8 @@ public class LogsIndexModeDisabledRestTestIT extends LogsIndexModeRestTestIT {
4652
.module("mapper-extras")
4753
.module("x-pack-aggregate-metric")
4854
.module("x-pack-stack")
49-
.setting("xpack.security.enabled", "false")
55+
.setting("xpack.security.autoconfiguration.enabled", "false")
56+
.user(USER, PASS)
5057
.setting("xpack.license.self_generated.type", "trial")
5158
.build();
5259

@@ -63,6 +70,11 @@ public void setup() throws Exception {
6370

6471
private RestClient client;
6572

73+
protected Settings restClientSettings() {
74+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
75+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
76+
}
77+
6678
public void testLogsSettingsIndexModeEnabledByDefault() throws IOException {
6779
assertOK(createDataStream(client, "logs-custom-dev"));
6880
final String indexMode = (String) getSetting(

x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeEnabledRestTestIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import org.elasticsearch.client.Response;
1111
import org.elasticsearch.client.ResponseException;
1212
import org.elasticsearch.client.RestClient;
13+
import org.elasticsearch.common.settings.SecureString;
14+
import org.elasticsearch.common.settings.Settings;
15+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1316
import org.elasticsearch.index.IndexMode;
1417
import org.elasticsearch.index.IndexSettings;
1518
import org.elasticsearch.test.cluster.ElasticsearchCluster;
@@ -24,6 +27,9 @@
2427

2528
public class LogsIndexModeEnabledRestTestIT extends LogsIndexModeRestTestIT {
2629

30+
private static final String USER = "test_admin";
31+
private static final String PASS = "x-pack-test-password";
32+
2733
@ClassRule()
2834
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
2935
.distribution(DistributionType.DEFAULT)
@@ -32,7 +38,8 @@ public class LogsIndexModeEnabledRestTestIT extends LogsIndexModeRestTestIT {
3238
.module("mapper-extras")
3339
.module("x-pack-aggregate-metric")
3440
.module("x-pack-stack")
35-
.setting("xpack.security.enabled", "false")
41+
.setting("xpack.security.autoconfiguration.enabled", "false")
42+
.user(USER, PASS)
3643
.setting("xpack.license.self_generated.type", "trial")
3744
.setting("cluster.logsdb.enabled", "true")
3845
.build();
@@ -176,6 +183,11 @@ public void setup() throws Exception {
176183
"host": { "cloud_region" : "us-west", "availability_zone" : "us-west-4b", "name" : "fdfgf-881197" } }
177184
""";
178185

186+
protected Settings restClientSettings() {
187+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
188+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
189+
}
190+
179191
public void testCreateDataStream() throws IOException {
180192
assertOK(putComponentTemplate(client, "logs@custom", MAPPINGS));
181193
assertOK(createDataStream(client, "logs-custom-dev"));

x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/patterntext/PatternTextBasicRestIT.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
import org.elasticsearch.client.Request;
1313
import org.elasticsearch.client.Response;
14+
import org.elasticsearch.common.settings.SecureString;
1415
import org.elasticsearch.common.settings.Settings;
1516
import org.elasticsearch.common.time.DateFormatter;
1617
import org.elasticsearch.common.time.FormatNames;
18+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1719
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1820
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1921
import org.elasticsearch.test.rest.ESRestTestCase;
@@ -33,11 +35,15 @@
3335

3436
public class PatternTextBasicRestIT extends ESRestTestCase {
3537

38+
private static final String USER = "test_admin";
39+
private static final String PASS = "x-pack-test-password";
40+
3641
@ClassRule
3742
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
3843
.distribution(DistributionType.DEFAULT)
3944
.setting("xpack.license.self_generated.type", "trial")
40-
.setting("xpack.security.enabled", "false")
45+
.setting("xpack.security.autoconfiguration.enabled", "false")
46+
.user(USER, PASS)
4147
.build();
4248

4349
@Override
@@ -56,6 +62,11 @@ public PatternTextBasicRestIT(boolean disableTemplating) {
5662
this.disableTemplating = disableTemplating;
5763
}
5864

65+
protected Settings restClientSettings() {
66+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
67+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
68+
}
69+
5970
@SuppressWarnings("unchecked")
6071
public void testBulkInsertThenMatchAllSource() throws IOException {
6172

x-pack/plugin/ml/qa/datafeed-multicluster-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/datafeed/DatafeedRemoteClusterClientIT.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import org.elasticsearch.client.ResponseException;
1616
import org.elasticsearch.client.RestClient;
1717
import org.elasticsearch.cluster.metadata.IndexMetadata;
18+
import org.elasticsearch.common.settings.SecureString;
1819
import org.elasticsearch.common.settings.Settings;
20+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1921
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2022
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
2123
import org.elasticsearch.test.rest.ESRestTestCase;
@@ -36,12 +38,17 @@
3638
* @see <a href="https://github.com/elastic/elasticsearch/issues/121149">GitHub issue 121149</a>
3739
*/
3840
public class DatafeedRemoteClusterClientIT extends ESRestTestCase {
41+
42+
private static final String USER = "test_admin";
43+
private static final String PASS = "x-pack-test-password";
44+
3945
public static ElasticsearchCluster remoteCluster = ElasticsearchCluster.local()
4046
.name("remote_cluster")
4147
.distribution(DistributionType.DEFAULT)
4248
.module("data-streams")
4349
.module("x-pack-stack")
44-
.setting("xpack.security.enabled", "false")
50+
.setting("xpack.security.autoconfiguration.enabled", "false")
51+
.user(USER, PASS)
4552
.setting("xpack.license.self_generated.type", "trial")
4653
.setting("cluster.logsdb.enabled", "true")
4754
.build();
@@ -51,7 +58,8 @@ public class DatafeedRemoteClusterClientIT extends ESRestTestCase {
5158
.distribution(DistributionType.DEFAULT)
5259
.module("data-streams")
5360
.module("x-pack-stack")
54-
.setting("xpack.security.enabled", "false")
61+
.setting("xpack.security.autoconfiguration.enabled", "false")
62+
.user(USER, PASS)
5563
.setting("xpack.license.self_generated.type", "trial")
5664
.setting("cluster.logsdb.enabled", "true")
5765
.setting("node.roles", "[data,ingest,master,ml]") // remote_cluster_client not included
@@ -73,6 +81,11 @@ private RestClient remoteClusterClient() throws IOException {
7381
return buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[0]));
7482
}
7583

84+
protected Settings restClientSettings() {
85+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
86+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
87+
}
88+
7689
public void testSource() throws IOException {
7790
String localIndex = "local_index";
7891
String remoteIndex = "remote_index";

0 commit comments

Comments
 (0)