Skip to content

Commit

Permalink
Fix Azure tests in FIPS mode again (#111611)
Browse files Browse the repository at this point in the history
Closes #111345 Closes #111607 Closes #111608
  • Loading branch information
DaveCTurner authored Aug 6, 2024
1 parent e3a2ce9 commit 7ed83fd
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions modules/repository-azure/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.apache.tools.ant.filters.ReplaceTokens
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.internal.test.InternalClusterTestPlugin
import org.elasticsearch.gradle.internal.test.RestIntegTestTask

Expand Down Expand Up @@ -326,6 +327,12 @@ tasks.register("workloadIdentityYamlRestTest", RestIntegTestTask) {
// omitting key and sas_token so that we use a bearer token from workload identity
}

if (BuildParams.inFipsJvm) {
// Cannot override the trust store in FIPS mode, and these tasks require a HTTPS fixture
tasks.named("managedIdentityYamlRestTest").configure { enabled = false }
tasks.named("workloadIdentityYamlRestTest").configure { enabled = false }
}

tasks.register("azureThirdPartyUnitTest", Test) {
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
SourceSet internalTestSourceSet = sourceSets.getByName(InternalClusterTestPlugin.SOURCE_SET_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class RepositoryAzureClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
private static final boolean USE_FIXTURE = Booleans.parseBoolean(System.getProperty("test.azure.fixture", "true"));
private static final boolean USE_HTTPS_FIXTURE = USE_FIXTURE && ESTestCase.inFipsJvm() == false;
// TODO when https://github.com/elastic/elasticsearch/issues/111532 addressed, use a HTTPS fixture in FIPS mode too

private static final String AZURE_TEST_ACCOUNT = System.getProperty("test.azure.account");
private static final String AZURE_TEST_CONTAINER = System.getProperty("test.azure.container");
Expand Down Expand Up @@ -87,7 +88,7 @@ private static Predicate<String> decideAuthHeaderPredicate() {
s -> USE_HTTPS_FIXTURE && Strings.hasText(AZURE_TEST_CLIENT_ID) && Strings.hasText(AZURE_TEST_TENANT_ID)
)
.systemProperty("AZURE_POD_IDENTITY_AUTHORITY_HOST", fixture::getMetadataAddress, s -> USE_FIXTURE)
.systemProperty("AZURE_AUTHORITY_HOST", fixture::getOAuthTokenServiceAddress, s -> USE_FIXTURE)
.systemProperty("AZURE_AUTHORITY_HOST", fixture::getOAuthTokenServiceAddress, s -> USE_HTTPS_FIXTURE)
.systemProperty("AZURE_CLIENT_ID", () -> AZURE_TEST_CLIENT_ID, s -> Strings.hasText(AZURE_TEST_CLIENT_ID))
.systemProperty("AZURE_TENANT_ID", () -> AZURE_TEST_TENANT_ID, s -> Strings.hasText(AZURE_TEST_TENANT_ID))
.configFile("storage-azure/azure-federated-token", Resource.fromString(fixture.getFederatedToken()))
Expand Down
4 changes: 0 additions & 4 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ tests:
issue: https://github.com/elastic/elasticsearch/issues/111448
- class: org.elasticsearch.search.SearchServiceTests
issue: https://github.com/elastic/elasticsearch/issues/111529
- class: org.elasticsearch.repositories.blobstore.testkit.AzureSnapshotRepoTestKitIT
issue: https://github.com/elastic/elasticsearch/issues/111607
- class: org.elasticsearch.repositories.azure.RepositoryAzureClientYamlTestSuiteIT
issue: https://github.com/elastic/elasticsearch/issues/111345
- class: org.elasticsearch.xpack.esql.CsvTests
issue: https://github.com/elastic/elasticsearch/issues/111612

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.ssl.KeyStoreUtil;
import org.elasticsearch.common.ssl.PemUtils;
import org.elasticsearch.core.Nullable;
Expand Down Expand Up @@ -112,10 +113,13 @@ public AzureHttpFixture(
Protocol protocol,
String account,
String container,
@Nullable String tenantId,
@Nullable String clientId,
@Nullable String rawTenantId,
@Nullable String rawClientId,
Predicate<String> authHeaderPredicate
) {
final var tenantId = Strings.hasText(rawTenantId) ? rawTenantId : null;
final var clientId = Strings.hasText(rawClientId) ? rawClientId : null;

if ((clientId == null) != (tenantId == null)) {
fail(null, "either both [tenantId] and [clientId] must be set or neither must be set");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public TestTrustStore(CheckedSupplier<InputStream, IOException> pemStreamSupplie
private Path trustStorePath;

public Path getTrustStorePath() {
// TODO when https://github.com/elastic/elasticsearch/issues/111532 addressed we should be able to use this in FIPS mode too
assertFalse("Tests in FIPS mode cannot supply a custom trust store", ESTestCase.inFipsJvm());
return Objects.requireNonNullElseGet(trustStorePath, () -> ESTestCase.fail(null, "trust store not created"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public class AzureRepositoriesMeteringIT extends AbstractRepositoriesMeteringAPIRestTestCase {
private static final boolean USE_FIXTURE = Booleans.parseBoolean(System.getProperty("test.azure.fixture", "true"));
private static final boolean USE_HTTPS_FIXTURE = USE_FIXTURE && ESTestCase.inFipsJvm() == false;
// TODO when https://github.com/elastic/elasticsearch/issues/111532 addressed, use a HTTPS fixture in FIPS mode too

private static final String AZURE_TEST_ACCOUNT = System.getProperty("test.azure.account");
private static final String AZURE_TEST_CONTAINER = System.getProperty("test.azure.container");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class AzureSearchableSnapshotsIT extends AbstractSearchableSnapshotsRestTestCase {
private static final boolean USE_FIXTURE = Booleans.parseBoolean(System.getProperty("test.azure.fixture", "true"));
private static final boolean USE_HTTPS_FIXTURE = USE_FIXTURE && ESTestCase.inFipsJvm() == false;
// TODO when https://github.com/elastic/elasticsearch/issues/111532 addressed, use a HTTPS fixture in FIPS mode too

private static final String AZURE_TEST_ACCOUNT = System.getProperty("test.azure.account");
private static final String AZURE_TEST_CONTAINER = System.getProperty("test.azure.container");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public class AzureSnapshotBasedRecoveryIT extends AbstractSnapshotBasedRecoveryRestTestCase {
private static final boolean USE_FIXTURE = Booleans.parseBoolean(System.getProperty("test.azure.fixture", "true"));
private static final boolean USE_HTTPS_FIXTURE = USE_FIXTURE && ESTestCase.inFipsJvm() == false;
// TODO when https://github.com/elastic/elasticsearch/issues/111532 addressed, use a HTTPS fixture in FIPS mode too

private static final String AZURE_TEST_ACCOUNT = System.getProperty("test.azure.account");
private static final String AZURE_TEST_CONTAINER = System.getProperty("test.azure.container");
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugin/snapshot-repo-test-kit/qa/azure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ tasks.register("workloadIdentityJavaRestTest", RestIntegTestTask) {
nonInputProperties.systemProperty 'test.azure.base_path', azureBasePath + "_repository_test_kit_tests_" + BuildParams.testSeed
}

if (BuildParams.inFipsJvm) {
// Cannot override the trust store in FIPS mode, and these tasks require a HTTPS fixture
tasks.named("managedIdentityJavaRestTest").configure { enabled = false }
tasks.named("workloadIdentityJavaRestTest").configure { enabled = false }
}

tasks.named("check") {
dependsOn("managedIdentityJavaRestTest")
dependsOn("workloadIdentityJavaRestTest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class AzureSnapshotRepoTestKitIT extends AbstractSnapshotRepoTestKitRestTestCase {
private static final boolean USE_FIXTURE = Booleans.parseBoolean(System.getProperty("test.azure.fixture", "true"));
private static final boolean USE_HTTPS_FIXTURE = USE_FIXTURE && ESTestCase.inFipsJvm() == false;
// TODO when https://github.com/elastic/elasticsearch/issues/111532 addressed, use a HTTPS fixture in FIPS mode too

private static final String AZURE_TEST_ACCOUNT = System.getProperty("test.azure.account");
private static final String AZURE_TEST_CONTAINER = System.getProperty("test.azure.container");
Expand Down Expand Up @@ -82,7 +83,7 @@ private static Predicate<String> decideAuthHeaderPredicate() {
s -> USE_HTTPS_FIXTURE && Strings.hasText(AZURE_TEST_CLIENT_ID) && Strings.hasText(AZURE_TEST_TENANT_ID)
)
.systemProperty("AZURE_POD_IDENTITY_AUTHORITY_HOST", fixture::getMetadataAddress, s -> USE_FIXTURE)
.systemProperty("AZURE_AUTHORITY_HOST", fixture::getOAuthTokenServiceAddress, s -> USE_FIXTURE)
.systemProperty("AZURE_AUTHORITY_HOST", fixture::getOAuthTokenServiceAddress, s -> USE_HTTPS_FIXTURE)
.systemProperty("AZURE_CLIENT_ID", () -> AZURE_TEST_CLIENT_ID, s -> Strings.hasText(AZURE_TEST_CLIENT_ID))
.systemProperty("AZURE_TENANT_ID", () -> AZURE_TEST_TENANT_ID, s -> Strings.hasText(AZURE_TEST_TENANT_ID))
.configFile("storage-azure/azure-federated-token", Resource.fromString(fixture.getFederatedToken()))
Expand Down

0 comments on commit 7ed83fd

Please sign in to comment.