Skip to content

Commit b121ee2

Browse files
authored
Reinstate S3SearchableSnapshotsCredentialsReloadIT in FIPS JVMs (#126324)
* Reinstate `S3SearchableSnapshotsCredentialsReloadIT` in FIPS JVMs These tests only don't work in a FIPS JVM because they use a secret key that is unacceptably short. This commit replaces the relevant uses of `randomIdentifier` with `randomSecretKey` so they work whether in FIPS mode or not. Backport of #126109 to `8.x` * CI poke
1 parent bdf8c1e commit b121ee2

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

modules/repository-s3/src/javaRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3RestReloadCredentialsIT.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.repositories.s3;
1111

1212
import fixture.s3.S3HttpFixture;
13-
import io.netty.handler.codec.http.HttpMethod;
1413

1514
import org.elasticsearch.client.Request;
1615
import org.elasticsearch.client.ResponseException;
@@ -106,12 +105,4 @@ public void testReloadCredentialsFromKeystore() throws IOException {
106105
// Check access using refreshed credentials
107106
assertOK(client().performRequest(verifyRequest));
108107
}
109-
110-
private Request createReloadSecureSettingsRequest() throws IOException {
111-
return newXContentRequest(
112-
HttpMethod.POST,
113-
"/_nodes/reload_secure_settings",
114-
(b, p) -> inFipsJvm() ? b.field("secure_settings_password", "keystore-password") : b
115-
);
116-
}
117108
}

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,4 +2705,21 @@ protected static void assertResultMap(
27052705
) {
27062706
assertMap(result, mapMatcher.entry("columns", columnMatcher).entry("values", valuesMatcher));
27072707
}
2708+
2709+
public static final String FIPS_KEYSTORE_PASSWORD = "keystore-password";
2710+
2711+
/**
2712+
* @return a REST {@link Request} which will reload the keystore in the test cluster.
2713+
*/
2714+
protected final Request createReloadSecureSettingsRequest() {
2715+
try {
2716+
return newXContentRequest(
2717+
HttpMethod.POST,
2718+
"/_nodes/reload_secure_settings",
2719+
(b, p) -> inFipsJvm() ? b.field("secure_settings_password", FIPS_KEYSTORE_PASSWORD) : b
2720+
);
2721+
} catch (IOException e) {
2722+
throw new AssertionError("impossible", e);
2723+
}
2724+
}
27082725
}

x-pack/plugin/searchable-snapshots/qa/s3/src/javaRestTest/java/org/elasticsearch/xpack/searchablesnapshots/s3/S3SearchableSnapshotsCredentialsReloadIT.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.test.rest.ObjectPath;
2828
import org.elasticsearch.xcontent.XContentBuilder;
2929
import org.elasticsearch.xcontent.XContentType;
30-
import org.junit.Before;
3130
import org.junit.ClassRule;
3231
import org.junit.rules.RuleChain;
3332
import org.junit.rules.TestRule;
@@ -76,11 +75,6 @@ protected String getTestRestCluster() {
7675
return cluster.getHttpAddresses();
7776
}
7877

79-
@Before
80-
public void skipFips() {
81-
assumeFalse("getting these tests to run in a FIPS JVM is kinda fiddly and we don't really need the extra coverage", inFipsJvm());
82-
}
83-
8478
public void testReloadCredentialsFromKeystore() throws IOException {
8579
final TestHarness testHarness = new TestHarness();
8680
testHarness.putRepository();
@@ -89,9 +83,9 @@ public void testReloadCredentialsFromKeystore() throws IOException {
8983
final String accessKey1 = randomIdentifier();
9084
repositoryAccessKey = accessKey1;
9185
keystoreSettings.put("s3.client.default.access_key", accessKey1);
92-
keystoreSettings.put("s3.client.default.secret_key", randomIdentifier());
86+
keystoreSettings.put("s3.client.default.secret_key", randomSecretKey());
9387
cluster.updateStoredSecureSettings();
94-
assertOK(client().performRequest(new Request("POST", "/_nodes/reload_secure_settings")));
88+
assertOK(client().performRequest(createReloadSecureSettingsRequest()));
9589

9690
testHarness.createFrozenSearchableSnapshotIndex();
9791

@@ -111,7 +105,7 @@ public void testReloadCredentialsFromKeystore() throws IOException {
111105
logger.info("--> update keystore contents");
112106
keystoreSettings.put("s3.client.default.access_key", accessKey2);
113107
cluster.updateStoredSecureSettings();
114-
assertOK(client().performRequest(new Request("POST", "/_nodes/reload_secure_settings")));
108+
assertOK(client().performRequest(createReloadSecureSettingsRequest()));
115109

116110
// Check access using refreshed credentials
117111
logger.info("--> expect success");
@@ -129,11 +123,11 @@ public void testReloadCredentialsFromAlternativeClient() throws IOException {
129123

130124
repositoryAccessKey = accessKey1;
131125
keystoreSettings.put("s3.client.default.access_key", accessKey1);
132-
keystoreSettings.put("s3.client.default.secret_key", randomIdentifier());
126+
keystoreSettings.put("s3.client.default.secret_key", randomSecretKey());
133127
keystoreSettings.put("s3.client." + alternativeClient + ".access_key", accessKey2);
134-
keystoreSettings.put("s3.client." + alternativeClient + ".secret_key", randomIdentifier());
128+
keystoreSettings.put("s3.client." + alternativeClient + ".secret_key", randomSecretKey());
135129
cluster.updateStoredSecureSettings();
136-
assertOK(client().performRequest(new Request("POST", "/_nodes/reload_secure_settings")));
130+
assertOK(client().performRequest(createReloadSecureSettingsRequest()));
137131

138132
testHarness.createFrozenSearchableSnapshotIndex();
139133

@@ -165,7 +159,7 @@ public void testReloadCredentialsFromMetadata() throws IOException {
165159
final String accessKey1 = randomIdentifier();
166160
final String accessKey2 = randomValueOtherThan(accessKey1, ESTestCase::randomIdentifier);
167161

168-
testHarness.putRepository(b -> b.put("access_key", accessKey1).put("secret_key", randomIdentifier()));
162+
testHarness.putRepository(b -> b.put("access_key", accessKey1).put("secret_key", randomSecretKey()));
169163
repositoryAccessKey = accessKey1;
170164

171165
testHarness.createFrozenSearchableSnapshotIndex();
@@ -183,7 +177,7 @@ public void testReloadCredentialsFromMetadata() throws IOException {
183177

184178
// Adjust repository to use new client
185179
logger.info("--> update repository metadata");
186-
testHarness.putRepository(b -> b.put("access_key", accessKey2).put("secret_key", randomIdentifier()));
180+
testHarness.putRepository(b -> b.put("access_key", accessKey2).put("secret_key", randomSecretKey()));
187181

188182
// Check access using refreshed credentials
189183
logger.info("--> expect success");

0 commit comments

Comments
 (0)