Skip to content

Commit e23a5e7

Browse files
authored
Enable security in a number of logsdb and tsdb integration tests. (#128877)
This change enables security in a number of tsdb and logsdb integration tests. A number of java/yaml rest tests in logsdb module, additionally logsdb and tsdb rolling upgrade tests. A recent bug (#128050) wouldn't have happened if logsdb rolling upgrade tests ran with security enabled.
1 parent 2131323 commit e23a5e7

File tree

14 files changed

+149
-12
lines changed

14 files changed

+149
-12
lines changed

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/AbstractRollingUpgradeTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public String get() {
4545
.setting("xpack.security.enabled", "false")
4646
.feature(FeatureFlag.TIME_SERIES_MODE);
4747

48+
// Avoid triggering bogus assertion when serialized parsed mappings don't match with original mappings, because _source key is
49+
// inconsistent
4850
if (oldVersion.before(Version.fromString("8.18.0"))) {
4951
cluster.jvmArg("-da:org.elasticsearch.index.mapper.DocumentMapper");
5052
cluster.jvmArg("-da:org.elasticsearch.index.mapper.MapperService");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.upgrades;
11+
12+
import com.carrotsearch.randomizedtesting.annotations.Name;
13+
14+
import org.elasticsearch.common.settings.SecureString;
15+
import org.elasticsearch.common.settings.Settings;
16+
import org.elasticsearch.common.util.concurrent.ThreadContext;
17+
import org.elasticsearch.core.SuppressForbidden;
18+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
19+
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
20+
import org.elasticsearch.test.cluster.util.Version;
21+
import org.junit.ClassRule;
22+
import org.junit.rules.RuleChain;
23+
import org.junit.rules.TemporaryFolder;
24+
import org.junit.rules.TestRule;
25+
26+
import java.util.function.Supplier;
27+
28+
public abstract class AbstractRollingUpgradeWithSecurityTestCase extends ParameterizedRollingUpgradeTestCase {
29+
30+
private static final String USER = "test_admin";
31+
private static final String PASS = "x-pack-test-password";
32+
33+
private static final TemporaryFolder repoDirectory = new TemporaryFolder();
34+
35+
private static final ElasticsearchCluster cluster = buildCluster();
36+
37+
private static ElasticsearchCluster buildCluster() {
38+
Version oldVersion = Version.fromString(OLD_CLUSTER_VERSION);
39+
var cluster = ElasticsearchCluster.local()
40+
.distribution(DistributionType.DEFAULT)
41+
.version(getOldClusterTestVersion())
42+
.nodes(NODE_NUM)
43+
.user(USER, PASS)
44+
.setting("xpack.security.autoconfiguration.enabled", "false")
45+
.setting("path.repo", new Supplier<>() {
46+
@Override
47+
@SuppressForbidden(reason = "TemporaryFolder only has io.File methods, not nio.File")
48+
public String get() {
49+
return repoDirectory.getRoot().getPath();
50+
}
51+
});
52+
53+
// Avoid triggering bogus assertion when serialized parsed mappings don't match with original mappings, because _source key is
54+
// inconsistent
55+
if (oldVersion.before(Version.fromString("8.18.0"))) {
56+
cluster.jvmArg("-da:org.elasticsearch.index.mapper.DocumentMapper");
57+
cluster.jvmArg("-da:org.elasticsearch.index.mapper.MapperService");
58+
}
59+
return cluster.build();
60+
}
61+
62+
@ClassRule
63+
public static TestRule ruleChain = RuleChain.outerRule(repoDirectory).around(cluster);
64+
65+
protected AbstractRollingUpgradeWithSecurityTestCase(@Name("upgradedNodes") int upgradedNodes) {
66+
super(upgradedNodes);
67+
}
68+
69+
@Override
70+
protected ElasticsearchCluster getUpgradeCluster() {
71+
return cluster;
72+
}
73+
74+
protected Settings restClientSettings() {
75+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
76+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
77+
}
78+
}

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/DownsampleIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import static org.hamcrest.Matchers.equalTo;
2727

28-
public class DownsampleIT extends AbstractRollingUpgradeTestCase {
28+
public class DownsampleIT extends AbstractRollingUpgradeWithSecurityTestCase {
2929

3030
private static final String FIXED_INTERVAL = "1h";
3131
private String index;

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/LogsIndexModeRollingUpgradeIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
import org.elasticsearch.client.Response;
1616
import org.elasticsearch.client.RestClient;
1717
import org.elasticsearch.common.network.InetAddresses;
18+
import org.elasticsearch.common.settings.SecureString;
19+
import org.elasticsearch.common.settings.Settings;
1820
import org.elasticsearch.common.time.DateFormatter;
1921
import org.elasticsearch.common.time.FormatNames;
22+
import org.elasticsearch.common.util.concurrent.ThreadContext;
2023
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2124
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
2225
import org.hamcrest.Matcher;
@@ -31,6 +34,9 @@
3134

3235
public class LogsIndexModeRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
3336

37+
private static final String USER = "test_admin";
38+
private static final String PASS = "x-pack-test-password";
39+
3440
@ClassRule()
3541
public static final ElasticsearchCluster cluster = ElasticsearchCluster.local()
3642
.distribution(DistributionType.DEFAULT)
@@ -39,7 +45,8 @@ public class LogsIndexModeRollingUpgradeIT extends AbstractRollingUpgradeTestCas
3945
.module("mapper-extras")
4046
.module("x-pack-aggregate-metric")
4147
.module("x-pack-stack")
42-
.setting("xpack.security.enabled", "false")
48+
.setting("xpack.security.autoconfiguration.enabled", "false")
49+
.user(USER, PASS)
4350
.setting("xpack.license.self_generated.type", initTestSeed().nextBoolean() ? "trial" : "basic")
4451
// We upgrade from standard to logsdb, so we need to start with logsdb disabled,
4552
// then later cluster.logsdb.enabled gets set to true and next rollover data stream is in logsdb mode.
@@ -56,6 +63,11 @@ protected String getTestRestCluster() {
5663
return cluster.getHttpAddresses();
5764
}
5865

66+
protected Settings restClientSettings() {
67+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
68+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
69+
}
70+
5971
private static final String BULK_INDEX_REQUEST = """
6072
{ "create": {} }
6173
{ "@timestamp": "%s", "host.name": "%s", "method": "%s", "ip.address": "%s", "message": "%s" }

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/LogsUsageRollingUpgradeIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.hamcrest.Matchers.hasKey;
2424
import static org.hamcrest.Matchers.not;
2525

26-
public class LogsUsageRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
26+
public class LogsUsageRollingUpgradeIT extends AbstractRollingUpgradeWithSecurityTestCase {
2727

2828
public LogsUsageRollingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
2929
super(upgradedNodes);

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/LogsdbIndexingRollingUpgradeIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3636
import static org.hamcrest.Matchers.notNullValue;
3737

38-
public class LogsdbIndexingRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
38+
public class LogsdbIndexingRollingUpgradeIT extends AbstractRollingUpgradeWithSecurityTestCase {
3939

4040
static String BULK_ITEM_TEMPLATE =
4141
"""

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/NoLogsUsageRollingUpgradeIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.hamcrest.Matchers.hasKey;
2121
import static org.hamcrest.Matchers.not;
2222

23-
public class NoLogsUsageRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
23+
public class NoLogsUsageRollingUpgradeIT extends AbstractRollingUpgradeWithSecurityTestCase {
2424

2525
public NoLogsUsageRollingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
2626
super(upgradedNodes);

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/ParameterizedRollingUpgradeTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected boolean preserveClusterUponCompletion() {
206206
}
207207

208208
@Override
209-
protected final Settings restClientSettings() {
209+
protected Settings restClientSettings() {
210210
return Settings.builder()
211211
.put(super.restClientSettings())
212212
// increase the timeout here to 90 seconds to handle long waits for a green

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/TsdbIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import static org.hamcrest.Matchers.equalTo;
2525
import static org.hamcrest.Matchers.hasSize;
2626

27-
public class TsdbIT extends AbstractRollingUpgradeTestCase {
27+
public class TsdbIT extends AbstractRollingUpgradeWithSecurityTestCase {
2828

2929
public TsdbIT(@Name("upgradedNodes") int upgradedNodes) {
3030
super(upgradedNodes);

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/TsdbIndexingRollingUpgradeIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3131
import static org.hamcrest.Matchers.notNullValue;
3232

33-
public class TsdbIndexingRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
33+
public class TsdbIndexingRollingUpgradeIT extends AbstractRollingUpgradeWithSecurityTestCase {
3434

3535
static String BULK_ITEM_TEMPLATE =
3636
"""

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

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

1010
import org.elasticsearch.client.Request;
1111
import org.elasticsearch.cluster.metadata.IndexMetadata;
12+
import org.elasticsearch.common.settings.SecureString;
1213
import org.elasticsearch.common.settings.Settings;
1314
import org.elasticsearch.common.time.DateFormatter;
1415
import org.elasticsearch.common.time.FormatNames;
16+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1517
import org.elasticsearch.common.xcontent.support.XContentMapValues;
1618
import org.elasticsearch.index.IndexSettings;
1719
import org.elasticsearch.test.cluster.ElasticsearchCluster;
@@ -30,10 +32,14 @@
3032

3133
public class LogsdbRestIT extends ESRestTestCase {
3234

35+
private static final String USER = "test_admin";
36+
private static final String PASS = "x-pack-test-password";
37+
3338
@ClassRule
3439
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
3540
.distribution(DistributionType.DEFAULT)
36-
.setting("xpack.security.enabled", "false")
41+
.user(USER, PASS, "superuser", false)
42+
.setting("xpack.security.autoconfiguration.enabled", "false")
3743
.setting("xpack.license.self_generated.type", "trial")
3844
.build();
3945

@@ -42,6 +48,11 @@ protected String getTestRestCluster() {
4248
return cluster.getHttpAddresses();
4349
}
4450

51+
protected Settings restClientSettings() {
52+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
53+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
54+
}
55+
4556
public void testFeatureUsageWithLogsdbIndex() throws IOException {
4657
{
4758
if (randomBoolean()) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import org.elasticsearch.client.Request;
1212
import org.elasticsearch.client.Response;
1313
import org.elasticsearch.common.network.InetAddresses;
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.common.xcontent.XContentHelper;
1820
import org.elasticsearch.core.SuppressForbidden;
1921
import org.elasticsearch.repositories.fs.FsRepository;
@@ -46,11 +48,14 @@
4648
public class LogsdbSnapshotRestoreIT extends ESRestTestCase {
4749

4850
private static TemporaryFolder repoDirectory = new TemporaryFolder();
51+
private static final String USER = "test_admin";
52+
private static final String PASS = "x-pack-test-password";
4953

5054
private static ElasticsearchCluster cluster = ElasticsearchCluster.local()
5155
.distribution(DistributionType.DEFAULT)
5256
.setting("path.repo", () -> getRepoPath())
53-
.setting("xpack.security.enabled", "false")
57+
.user(USER, PASS)
58+
.setting("xpack.security.autoconfiguration.enabled", "false")
5459
.setting("xpack.license.self_generated.type", "trial")
5560
.build();
5661

@@ -131,6 +136,11 @@ protected String getTestRestCluster() {
131136
return cluster.getHttpAddresses();
132137
}
133138

139+
protected Settings restClientSettings() {
140+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
141+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
142+
}
143+
134144
public void testSnapshotRestore() throws Exception {
135145
snapshotAndRestore("synthetic", "object", false);
136146
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import org.elasticsearch.client.RestClient;
1313
import org.elasticsearch.common.CheckedSupplier;
1414
import org.elasticsearch.common.Strings;
15+
import org.elasticsearch.common.settings.SecureString;
1516
import org.elasticsearch.common.settings.Settings;
17+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1618
import org.elasticsearch.core.CheckedConsumer;
1719
import org.elasticsearch.rest.RestStatus;
1820
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -30,6 +32,10 @@
3032
import java.util.function.Supplier;
3133

3234
public abstract class AbstractChallengeRestTest extends ESRestTestCase {
35+
36+
private static final String USER = "test_admin";
37+
private static final String PASS = "x-pack-test-password";
38+
3339
private final String baselineDataStreamName;
3440
private final String contenderDataStreamName;
3541
private final String baselineTemplateName;
@@ -48,7 +54,8 @@ public abstract class AbstractChallengeRestTest extends ESRestTestCase {
4854
.distribution(DistributionType.DEFAULT)
4955
.module("data-streams")
5056
.module("x-pack-stack")
51-
.setting("xpack.security.enabled", "false")
57+
.user(USER, PASS)
58+
.setting("xpack.security.autoconfiguration.enabled", "false")
5259
.setting("xpack.license.self_generated.type", "trial")
5360
.setting("cluster.logsdb.enabled", "true")
5461
.build();
@@ -58,6 +65,11 @@ protected String getTestRestCluster() {
5865
return cluster.getHttpAddresses();
5966
}
6067

68+
protected Settings restClientSettings() {
69+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
70+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
71+
}
72+
6173
public AbstractChallengeRestTest(
6274
final String baselineDataStreamName,
6375
final String contenderDataStreamName,

x-pack/plugin/logsdb/src/yamlRestTest/java/org/elasticsearch/xpack/logsdb/LogsdbTestSuiteIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import com.carrotsearch.randomizedtesting.annotations.Name;
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

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.test.cluster.ElasticsearchCluster;
1417
import org.elasticsearch.test.cluster.FeatureFlag;
1518
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
@@ -19,10 +22,14 @@
1922

2023
public class LogsdbTestSuiteIT extends ESClientYamlSuiteTestCase {
2124

25+
private static final String USER = "test_admin";
26+
private static final String PASS = "x-pack-test-password";
27+
2228
@ClassRule
2329
public static final ElasticsearchCluster cluster = ElasticsearchCluster.local()
2430
.distribution(DistributionType.DEFAULT)
25-
.setting("xpack.security.enabled", "false")
31+
.user(USER, PASS, "superuser", false)
32+
.setting("xpack.security.autoconfiguration.enabled", "false")
2633
.setting("xpack.license.self_generated.type", "trial")
2734
.feature(FeatureFlag.DOC_VALUES_SKIPPER)
2835
.feature(FeatureFlag.USE_LUCENE101_POSTINGS_FORMAT)
@@ -42,4 +49,9 @@ protected String getTestRestCluster() {
4249
return cluster.getHttpAddresses();
4350
}
4451

52+
protected Settings restClientSettings() {
53+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
54+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
55+
}
56+
4557
}

0 commit comments

Comments
 (0)