Correctly configure testclsuters for fips (#43186)

Configuration was not being triggered for all projects with the way it
was previusly set up.
With this change we do it for each project directly.
This commit is contained in:
Alpar Torok 2019-06-14 10:51:03 +03:00
parent 7cc6dca697
commit 023a126b57
4 changed files with 35 additions and 26 deletions

View File

@ -33,6 +33,7 @@ import org.elasticsearch.gradle.precommit.DependencyLicensesTask
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.elasticsearch.gradle.test.ErrorReportingTestListener
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException
@ -100,13 +101,17 @@ class BuildPlugin implements Plugin<Project> {
project.rootProject.pluginManager.apply(GlobalBuildInfoPlugin)
if (project.pluginManager.hasPlugin('elasticsearch.standalone-rest-test')) {
throw new InvalidUserDataException('elasticsearch.standalone-test, '
+ 'elasticsearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
throw new InvalidUserDataException('elasticsearch.standalone-test, '
+ 'elasticsearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
}
String minimumGradleVersion = null
InputStream is = getClass().getResourceAsStream("/minimumGradleVersion")
try { minimumGradleVersion = IOUtils.toString(is, StandardCharsets.UTF_8.toString()) } finally { is.close() }
try {
minimumGradleVersion = IOUtils.toString(is, StandardCharsets.UTF_8.toString())
} finally {
is.close()
}
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion.trim())) {
throw new GradleException(
"Gradle ${minimumGradleVersion}+ is required to use elasticsearch.build plugin"
@ -140,23 +145,25 @@ class BuildPlugin implements Plugin<Project> {
configurePrecommit(project)
configureDependenciesInfo(project)
// Common config when running with a FIPS-140 runtime JVM
// Need to do it here to support external plugins
if (project == project.rootProject) {
GlobalInfoExtension globalInfo = project.extensions.getByType(GlobalInfoExtension)
// wait until global info is populated because we don't know if we are running in a fips jvm until execution time
globalInfo.ready {
project.subprojects { Project subproject ->
ExtraPropertiesExtension ext = subproject.extensions.getByType(ExtraPropertiesExtension)
// Common config when running with a FIPS-140 runtime JVM
if (ext.has('inFipsJvm') && ext.get('inFipsJvm')) {
subproject.tasks.withType(Test) { Test task ->
task.systemProperty 'javax.net.ssl.trustStorePassword', 'password'
task.systemProperty 'javax.net.ssl.keyStorePassword', 'password'
}
project.pluginManager.withPlugin("elasticsearch.testclusters") {
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = subproject.extensions.getByName('testClusters') as NamedDomainObjectContainer<ElasticsearchCluster>
configureFips140(project)
}
public static void configureFips140(Project project) {
// Need to do it here to support external plugins
GlobalInfoExtension globalInfo = project.rootProject.extensions.getByType(GlobalInfoExtension)
// wait until global info is populated because we don't know if we are running in a fips jvm until execution time
globalInfo.ready {
ExtraPropertiesExtension ext = project.extensions.getByType(ExtraPropertiesExtension)
// Common config when running with a FIPS-140 runtime JVM
if (ext.has('inFipsJvm') && ext.get('inFipsJvm')) {
project.tasks.withType(Test) { Test task ->
task.systemProperty 'javax.net.ssl.trustStorePassword', 'password'
task.systemProperty 'javax.net.ssl.keyStorePassword', 'password'
}
project.pluginManager.withPlugin("elasticsearch.testclusters") {
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = project.extensions.findByName(TestClustersPlugin.EXTENSION_NAME) as NamedDomainObjectContainer<ElasticsearchCluster>
if (testClusters != null) {
testClusters.all { ElasticsearchCluster cluster ->
cluster.systemProperty 'javax.net.ssl.trustStorePassword', 'password'
cluster.systemProperty 'javax.net.ssl.keyStorePassword', 'password'
@ -164,7 +171,6 @@ class BuildPlugin implements Plugin<Project> {
}
}
}
}
}
}
@ -261,7 +267,7 @@ class BuildPlugin implements Plugin<Project> {
}
protected static void checkDockerVersionRecent(String dockerVersion) {
final Matcher matcher = dockerVersion =~ /Docker version (\d+\.\d+)\.\d+(?:-ce)?, build [0-9a-f]{7,40}/
final Matcher matcher = dockerVersion =~ /Docker version (\d+\.\d+)\.\d+(?:-[a-zA-Z0-9]+)?, build [0-9a-f]{7,40}/
assert matcher.matches(): dockerVersion
final dockerMajorMinorVersion = matcher.group(1)
final String[] majorMinor = dockerMajorMinorVersion.split("\\.")

View File

@ -25,6 +25,7 @@ import groovy.transform.CompileStatic
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.gradle.api.InvalidUserDataException
import org.gradle.api.JavaVersion
@ -57,12 +58,14 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
+ 'elasticsearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
}
project.rootProject.pluginManager.apply(GlobalBuildInfoPlugin)
project.pluginManager.apply(JavaBasePlugin)
project.getTasks().create("buildResources", ExportElasticsearchBuildResourcesTask)
BuildPlugin.configureRepositories(project)
BuildPlugin.configureTestTasks(project)
BuildPlugin.configureInputNormalization(project)
BuildPlugin.configureFips140(project)
ExtraPropertiesExtension ext = project.extensions.getByType(ExtraPropertiesExtension)
project.extensions.getByType(JavaPluginExtension).sourceCompatibility = ext.get('minimumRuntimeVersion') as JavaVersion

View File

@ -116,7 +116,7 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
String versionedJavaHome = System.getenv(getJavaHomeEnvVarName(version));
if (versionedJavaHome == null) {
throw new GradleException(
"$versionedVarName must be set to build Elasticsearch. " +
"$" + getJavaHomeEnvVarName(version) + " must be set to build Elasticsearch. " +
"Note that if the variable was just set you might have to run `./gradlew --stop` for " +
"it to be picked up. See https://github.com/elastic/elasticsearch/issues/31399 details."
);

View File

@ -55,7 +55,7 @@ import java.util.stream.Collectors;
public class TestClustersPlugin implements Plugin<Project> {
private static final String LIST_TASK_NAME = "listTestClusters";
private static final String NODE_EXTENSION_NAME = "testClusters";
public static final String EXTENSION_NAME = "testClusters";
private static final String HELPER_CONFIGURATION_PREFIX = "testclusters";
private static final String SYNC_ARTIFACTS_TASK_NAME = "syncTestClustersArtifacts";
private static final int EXECUTOR_SHUTDOWN_TIMEOUT = 1;
@ -124,7 +124,7 @@ public class TestClustersPlugin implements Plugin<Project> {
new File(project.getBuildDir(), "testclusters")
)
);
project.getExtensions().add(NODE_EXTENSION_NAME, container);
project.getExtensions().add(EXTENSION_NAME, container);
return container;
}
@ -274,7 +274,7 @@ public class TestClustersPlugin implements Plugin<Project> {
@SuppressWarnings("unchecked")
public static NamedDomainObjectContainer<ElasticsearchCluster> getNodeExtension(Project project) {
return (NamedDomainObjectContainer<ElasticsearchCluster>)
project.getExtensions().getByName(NODE_EXTENSION_NAME);
project.getExtensions().getByName(EXTENSION_NAME);
}
private static void autoConfigureClusterDependencies(