Skip to content

Commit 007815e

Browse files
committed
Enable security in a number of logsdb and tsdb integration tests.
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 696ff89 commit 007815e

File tree

13 files changed

+145
-12
lines changed

13 files changed

+145
-12
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
if (oldVersion.before(Version.fromString("8.18.0"))) {
54+
cluster.jvmArg("-da:org.elasticsearch.index.mapper.DocumentMapper");
55+
cluster.jvmArg("-da:org.elasticsearch.index.mapper.MapperService");
56+
}
57+
return cluster.build();
58+
}
59+
60+
@ClassRule
61+
public static TestRule ruleChain = RuleChain.outerRule(repoDirectory).around(cluster);
62+
63+
protected AbstractRollingUpgradeWithSecurityTestCase(@Name("upgradedNodes") int upgradedNodes) {
64+
super(upgradedNodes);
65+
}
66+
67+
@Override
68+
protected ElasticsearchCluster getUpgradeCluster() {
69+
return cluster;
70+
}
71+
72+
protected Settings restClientSettings() {
73+
String token = basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray()));
74+
return Settings.builder().put(super.restClientSettings()).put(ThreadContext.PREFIX + ".Authorization", token).build();
75+
}
76+
}

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()) {

0 commit comments

Comments
 (0)