|
@@ -18,6 +18,8 @@
|
|
|
*/
|
|
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
+import org.elasticsearch.gradle.test.RestIntegTestTask
|
|
|
+
|
|
|
import java.nio.file.Files
|
|
|
import java.nio.file.Path
|
|
|
import java.nio.file.Paths
|
|
@@ -68,6 +70,61 @@ task hdfsFixture(type: org.elasticsearch.gradle.test.AntFixture) {
|
|
|
baseDir
|
|
|
}
|
|
|
|
|
|
+// MIT Kerberos Vagrant Testing Fixture
|
|
|
+String box = "krb5kdc"
|
|
|
+Map<String,String> vagrantEnvVars = [
|
|
|
+ 'VAGRANT_CWD' : "${project(':test:fixtures:krb5kdc-fixture').projectDir}",
|
|
|
+ 'VAGRANT_VAGRANTFILE' : 'Vagrantfile',
|
|
|
+ 'VAGRANT_PROJECT_DIR' : "${project(':test:fixtures:krb5kdc-fixture').projectDir}"
|
|
|
+]
|
|
|
+
|
|
|
+task krb5kdcUpdate(type: org.elasticsearch.gradle.vagrant.VagrantCommandTask) {
|
|
|
+ command 'box'
|
|
|
+ subcommand 'update'
|
|
|
+ boxName box
|
|
|
+ environmentVars vagrantEnvVars
|
|
|
+}
|
|
|
+
|
|
|
+task krb5kdcFixture(type: org.elasticsearch.gradle.test.VagrantFixture) {
|
|
|
+ command 'up'
|
|
|
+ args '--provision', '--provider', 'virtualbox'
|
|
|
+ boxName box
|
|
|
+ environmentVars vagrantEnvVars
|
|
|
+ dependsOn krb5kdcUpdate
|
|
|
+}
|
|
|
+
|
|
|
+task krb5AddPrincipals {
|
|
|
+ dependsOn krb5kdcFixture
|
|
|
+}
|
|
|
+
|
|
|
+List<String> principals = [ "elasticsearch", "hdfs/hdfs.build.elastic.co" ]
|
|
|
+String realm = "BUILD.ELASTIC.CO"
|
|
|
+
|
|
|
+for (String principal : principals) {
|
|
|
+ Task create = project.tasks.create("addPrincipal#${principal}", org.elasticsearch.gradle.vagrant.VagrantCommandTask) {
|
|
|
+ command 'ssh'
|
|
|
+ args '--command', "sudo bash /vagrant/src/main/resources/provision/addprinc.sh $principal"
|
|
|
+ boxName box
|
|
|
+ environmentVars vagrantEnvVars
|
|
|
+ dependsOn krb5kdcFixture
|
|
|
+ }
|
|
|
+ krb5AddPrincipals.dependsOn(create)
|
|
|
+}
|
|
|
+
|
|
|
+task secureHdfsFixture(type: org.elasticsearch.gradle.test.AntFixture) {
|
|
|
+ dependsOn project.configurations.hdfsFixture, krb5kdcFixture, krb5AddPrincipals
|
|
|
+ executable = new File(project.javaHome, 'bin/java')
|
|
|
+ env 'CLASSPATH', "${ -> project.configurations.hdfsFixture.asPath }"
|
|
|
+
|
|
|
+ Path keytabPath = project(':test:fixtures:krb5kdc-fixture').buildDir.toPath().resolve("keytabs").resolve("hdfs_hdfs.build.elastic.co.keytab")
|
|
|
+ Path krb5Config = project(':test:fixtures:krb5kdc-fixture').buildDir.toPath().resolve("conf").resolve("krb5.conf")
|
|
|
+
|
|
|
+ args "-Djava.security.krb5.conf=${krb5Config}", 'hdfs.MiniHDFS',
|
|
|
+ baseDir,
|
|
|
+ "hdfs/hdfs.build.elastic.co@${realm}",
|
|
|
+ "${keytabPath}"
|
|
|
+}
|
|
|
+
|
|
|
boolean fixtureSupported = false;
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
// hdfs fixture will not start without hadoop native libraries on windows
|
|
@@ -89,12 +146,69 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
|
|
if (fixtureSupported) {
|
|
|
integTestCluster.dependsOn hdfsFixture
|
|
|
+ integTestRunner.systemProperty 'tests.rest.suite', 'hdfs_repository'
|
|
|
} else {
|
|
|
logger.warn("hdfsFixture unsupported, please set HADOOP_HOME and put HADOOP_HOME\\bin in PATH")
|
|
|
// just tests that the plugin loads
|
|
|
integTestRunner.systemProperty 'tests.rest.suite', 'hdfs_repository/10_basic'
|
|
|
}
|
|
|
|
|
|
+boolean secureFixtureSupported = false;
|
|
|
+if (fixtureSupported) {
|
|
|
+ // Only do secure fixture support if the regular fixture is supported,
|
|
|
+ // and if vagrant is installed. The ignoreExitValue on exec only matters
|
|
|
+ // in cases where the command can be found and successfully started. In
|
|
|
+ // situations where the vagrant command isn't able to be started at all
|
|
|
+ // (it's not installed) then Gradle still throws ExecException.
|
|
|
+ ByteArrayOutputStream pipe = new ByteArrayOutputStream()
|
|
|
+ try {
|
|
|
+ ExecResult runResult = exec {
|
|
|
+ commandLine 'vagrant', '--version'
|
|
|
+ standardOutput pipe
|
|
|
+ ignoreExitValue true
|
|
|
+ }
|
|
|
+ String output = pipe.toString().trim()
|
|
|
+ if (runResult.exitValue == 0) {
|
|
|
+ secureFixtureSupported = (output ==~ /Vagrant 1\.(8\.[6-9]|9\.[0-9])+/)
|
|
|
+ } else {
|
|
|
+ logger.warn("Could not read installed vagrant version:\n" + output)
|
|
|
+ }
|
|
|
+ } catch (org.gradle.process.internal.ExecException e) {
|
|
|
+ logger.warn("Could not find vagrant: " + e.message)
|
|
|
+ // Swallow error. Vagrant isn't installed. Leave secure fixture support off.
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Create a Integration Test suite just for security based tests
|
|
|
+if (secureFixtureSupported) {
|
|
|
+ // This must execute before the afterEvaluate block from integTestSecure
|
|
|
+ project.afterEvaluate {
|
|
|
+ Path elasticsearchKT = project(':test:fixtures:krb5kdc-fixture').buildDir.toPath().resolve("keytabs").resolve("elasticsearch.keytab").toAbsolutePath()
|
|
|
+ Path krb5conf = project(':test:fixtures:krb5kdc-fixture').buildDir.toPath().resolve("conf").resolve("krb5.conf").toAbsolutePath()
|
|
|
+
|
|
|
+ project.integTestSecureCluster.dependsOn(project.bundlePlugin)
|
|
|
+ project.integTestSecure.clusterConfig.plugin(project.path)
|
|
|
+ project.integTestSecure.clusterConfig.extraConfigFile("repository-hdfs/krb5.keytab", "${elasticsearchKT}")
|
|
|
+ project.integTestSecure.clusterConfig.jvmArgs = "-Xms" + System.getProperty('tests.heap.size', '512m') +
|
|
|
+ " " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
|
|
|
+ " " + "-Djava.security.krb5.conf=${krb5conf}" +
|
|
|
+ " " + System.getProperty('tests.jvm.argline', '')
|
|
|
+ }
|
|
|
+
|
|
|
+ RestIntegTestTask integTestSecure = project.tasks.create('integTestSecure', RestIntegTestTask.class) {
|
|
|
+ description = "Runs rest tests against an elasticsearch cluster with HDFS secured by MIT Kerberos."
|
|
|
+ }
|
|
|
+
|
|
|
+ integTestSecure.mustRunAfter(project.integTest)
|
|
|
+ project.check.dependsOn(integTestSecure)
|
|
|
+
|
|
|
+ // Fixture dependencies
|
|
|
+ integTestSecureCluster.dependsOn secureHdfsFixture, krb5kdcFixture
|
|
|
+ integTestSecureRunner.systemProperty 'tests.rest.suite', 'secure_hdfs_repository'
|
|
|
+} else {
|
|
|
+ logger.warn("secured hdfsFixture is unsupported, please install Vagrant 1.8.6+ to enable")
|
|
|
+}
|
|
|
+
|
|
|
thirdPartyAudit.excludes = [
|
|
|
// classes are missing, because we added hadoop jars one by one until tests pass.
|
|
|
'com.google.gson.stream.JsonReader',
|