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
"""

0 commit comments

Comments
 (0)