Skip to content

Commit d57b4f4

Browse files
committed
Reinstate S3SearchableSnapshotsCredentialsReloadIT in FIPS JVMs (elastic#126109)
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.
1 parent c6899b7 commit d57b4f4

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;
@@ -105,12 +104,4 @@ public void testReloadCredentialsFromKeystore() throws IOException {
105104
// Check access using refreshed credentials
106105
assertOK(client().performRequest(verifyRequest));
107106
}
108-
109-
private Request createReloadSecureSettingsRequest() throws IOException {
110-
return newXContentRequest(
111-
HttpMethod.POST,
112-
"/_nodes/reload_secure_settings",
113-
(b, p) -> inFipsJvm() ? b.field("secure_settings_password", "keystore-password") : b
114-
);
115-
}
116107
}

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;
@@ -75,11 +74,6 @@ protected String getTestRestCluster() {
7574
return cluster.getHttpAddresses();
7675
}
7776

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

9589
testHarness.createFrozenSearchableSnapshotIndex();
9690

@@ -110,7 +104,7 @@ public void testReloadCredentialsFromKeystore() throws IOException {
110104
logger.info("--> update keystore contents");
111105
keystoreSettings.put("s3.client.default.access_key", accessKey2);
112106
cluster.updateStoredSecureSettings();
113-
assertOK(client().performRequest(new Request("POST", "/_nodes/reload_secure_settings")));
107+
assertOK(client().performRequest(createReloadSecureSettingsRequest()));
114108

115109
// Check access using refreshed credentials
116110
logger.info("--> expect success");
@@ -128,11 +122,11 @@ public void testReloadCredentialsFromAlternativeClient() throws IOException {
128122

129123
repositoryAccessKey = accessKey1;
130124
keystoreSettings.put("s3.client.default.access_key", accessKey1);
131-
keystoreSettings.put("s3.client.default.secret_key", randomIdentifier());
125+
keystoreSettings.put("s3.client.default.secret_key", randomSecretKey());
132126
keystoreSettings.put("s3.client." + alternativeClient + ".access_key", accessKey2);
133-
keystoreSettings.put("s3.client." + alternativeClient + ".secret_key", randomIdentifier());
127+
keystoreSettings.put("s3.client." + alternativeClient + ".secret_key", randomSecretKey());
134128
cluster.updateStoredSecureSettings();
135-
assertOK(client().performRequest(new Request("POST", "/_nodes/reload_secure_settings")));
129+
assertOK(client().performRequest(createReloadSecureSettingsRequest()));
136130

137131
testHarness.createFrozenSearchableSnapshotIndex();
138132

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

167-
testHarness.putRepository(b -> b.put("access_key", accessKey1).put("secret_key", randomIdentifier()));
161+
testHarness.putRepository(b -> b.put("access_key", accessKey1).put("secret_key", randomSecretKey()));
168162
repositoryAccessKey = accessKey1;
169163

170164
testHarness.createFrozenSearchableSnapshotIndex();
@@ -182,7 +176,7 @@ public void testReloadCredentialsFromMetadata() throws IOException {
182176

183177
// Adjust repository to use new client
184178
logger.info("--> update repository metadata");
185-
testHarness.putRepository(b -> b.put("access_key", accessKey2).put("secret_key", randomIdentifier()));
179+
testHarness.putRepository(b -> b.put("access_key", accessKey2).put("secret_key", randomSecretKey()));
186180

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

0 commit comments

Comments
 (0)