Skip to content

Commit 24bc505

Browse files
authored
[Test] Increase test secret key length (#117675)
Running with FIPS approved mode requires secret keys to be at least 114 bits long. Relates: #117324 Resolves: #117596 Resolves: #117709 Resolves: #117710 Resolves: #117711 Resolves: #117712
1 parent 5663728 commit 24bc505

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

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

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

1212
import fixture.s3.S3HttpFixture;
13+
import io.netty.handler.codec.http.HttpMethod;
1314

1415
import org.elasticsearch.client.Request;
1516
import org.elasticsearch.client.ResponseException;
@@ -61,8 +62,6 @@ protected String getTestRestCluster() {
6162
}
6263

6364
public void testReloadCredentialsFromKeystore() throws IOException {
64-
assumeFalse("doesn't work in a FIPS JVM, but that's ok", inFipsJvm());
65-
6665
// Register repository (?verify=false because we don't have access to the blob store yet)
6766
final var repositoryName = randomIdentifier();
6867
registerRepository(
@@ -77,15 +76,16 @@ public void testReloadCredentialsFromKeystore() throws IOException {
7776
final var accessKey1 = randomIdentifier();
7877
repositoryAccessKey = accessKey1;
7978
keystoreSettings.put("s3.client.default.access_key", accessKey1);
80-
keystoreSettings.put("s3.client.default.secret_key", randomIdentifier());
79+
keystoreSettings.put("s3.client.default.secret_key", randomSecretKey());
8180
cluster.updateStoredSecureSettings();
82-
assertOK(client().performRequest(new Request("POST", "/_nodes/reload_secure_settings")));
81+
82+
assertOK(client().performRequest(createReloadSecureSettingsRequest()));
8383

8484
// Check access using initial credentials
8585
assertOK(client().performRequest(verifyRequest));
8686

8787
// Rotate credentials in blob store
88-
final var accessKey2 = randomValueOtherThan(accessKey1, ESTestCase::randomIdentifier);
88+
final var accessKey2 = randomValueOtherThan(accessKey1, ESTestCase::randomSecretKey);
8989
repositoryAccessKey = accessKey2;
9090

9191
// Ensure that initial credentials now invalid
@@ -99,10 +99,17 @@ public void testReloadCredentialsFromKeystore() throws IOException {
9999
// Set up refreshed credentials
100100
keystoreSettings.put("s3.client.default.access_key", accessKey2);
101101
cluster.updateStoredSecureSettings();
102-
assertOK(client().performRequest(new Request("POST", "/_nodes/reload_secure_settings")));
102+
assertOK(client().performRequest(createReloadSecureSettingsRequest()));
103103

104104
// Check access using refreshed credentials
105105
assertOK(client().performRequest(verifyRequest));
106106
}
107107

108+
private Request createReloadSecureSettingsRequest() throws IOException {
109+
return newXContentRequest(
110+
HttpMethod.POST,
111+
"/_nodes/reload_secure_settings",
112+
(b, p) -> inFipsJvm() ? b.field("secure_settings_password", "keystore-password") : b
113+
);
114+
}
108115
}

muted-tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ tests:
216216
- class: org.elasticsearch.reservedstate.service.FileSettingsServiceTests
217217
method: testStopWorksInMiddleOfProcessing
218218
issue: https://github.com/elastic/elasticsearch/issues/117591
219-
- class: org.elasticsearch.repositories.s3.RepositoryS3ClientYamlTestSuiteIT
220-
issue: https://github.com/elastic/elasticsearch/issues/117596
221219
- class: "org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT"
222220
method: "test {scoring.*}"
223221
issue: https://github.com/elastic/elasticsearch/issues/117641

test/fixtures/aws-sts-fixture/src/main/java/fixture/aws/sts/AwsStsHttpHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.stream.Collectors;
2929

3030
import static org.elasticsearch.test.ESTestCase.randomIdentifier;
31+
import static org.elasticsearch.test.ESTestCase.randomSecretKey;
3132

3233
/**
3334
* Minimal HTTP handler that emulates the AWS STS server
@@ -102,7 +103,7 @@ public void handle(final HttpExchange exchange) throws IOException {
102103
ROLE_ARN,
103104
ROLE_NAME,
104105
sessionToken,
105-
randomIdentifier(),
106+
randomSecretKey(),
106107
ZonedDateTime.now().plusDays(1L).format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")),
107108
accessKey
108109
).getBytes(StandardCharsets.UTF_8);

test/fixtures/ec2-imds-fixture/src/main/java/fixture/aws/imds/Ec2ImdsHttpHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.function.BiConsumer;
2929

3030
import static org.elasticsearch.test.ESTestCase.randomIdentifier;
31+
import static org.elasticsearch.test.ESTestCase.randomSecretKey;
3132

3233
/**
3334
* Minimal HTTP handler that emulates the EC2 IMDS server
@@ -84,7 +85,7 @@ public void handle(final HttpExchange exchange) throws IOException {
8485
accessKey,
8586
ZonedDateTime.now(Clock.systemUTC()).plusDays(1L).format(DateTimeFormatter.ISO_DATE_TIME),
8687
randomIdentifier(),
87-
randomIdentifier(),
88+
randomSecretKey(),
8889
sessionToken
8990
).getBytes(StandardCharsets.UTF_8);
9091
exchange.getResponseHeaders().add("Content-Type", "application/json");

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,13 @@ public static String randomDateFormatterPattern() {
13581358
return randomFrom(FormatNames.values()).getName();
13591359
}
13601360

1361+
/**
1362+
* Generate a random string of at least 112 bits to satisfy minimum entropy requirement when running in FIPS mode.
1363+
*/
1364+
public static String randomSecretKey() {
1365+
return randomAlphaOfLengthBetween(14, 20);
1366+
}
1367+
13611368
/**
13621369
* Randomly choose between {@link EsExecutors#DIRECT_EXECUTOR_SERVICE} (which does not fork), {@link ThreadPool#generic}, and one of the
13631370
* other named threadpool executors.

0 commit comments

Comments
 (0)