2020-05-22 11:49:36 -04:00
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
2020-06-02 09:33:53 -04:00
|
|
|
import org.elasticsearch.gradle.network.SanEvaluator
|
2020-05-22 11:49:36 -04:00
|
|
|
import org.elasticsearch.gradle.info.BuildParams
|
2020-05-27 18:20:41 -04:00
|
|
|
import org.gradle.internal.jvm.Jvm
|
2020-05-22 11:49:36 -04:00
|
|
|
|
|
|
|
// Tell the tests we're running with ssl enabled
|
|
|
|
integTest.runner {
|
|
|
|
systemProperty 'tests.ssl.enabled', 'true'
|
|
|
|
}
|
|
|
|
|
|
|
|
// needed to be consistent with ssl host checking
|
|
|
|
Object san = new SanEvaluator()
|
|
|
|
|
|
|
|
// needed to be consistent with ssl host checking
|
|
|
|
String host = InetAddress.getLoopbackAddress().getHostAddress();
|
|
|
|
|
|
|
|
// location of generated keystores and certificates
|
|
|
|
File keystoreDir = new File(project.buildDir, 'keystore')
|
|
|
|
|
|
|
|
// Generate the node's keystore
|
|
|
|
File nodeKeystore = file("$keystoreDir/test-node.jks")
|
2020-06-02 09:33:53 -04:00
|
|
|
tasks.register("createNodeKeyStore", LoggedExec) {
|
2020-05-22 11:49:36 -04:00
|
|
|
doFirst {
|
|
|
|
if (nodeKeystore.parentFile.exists() == false) {
|
|
|
|
nodeKeystore.parentFile.mkdirs()
|
|
|
|
}
|
|
|
|
if (nodeKeystore.exists()) {
|
|
|
|
delete nodeKeystore
|
|
|
|
}
|
|
|
|
}
|
2020-05-27 18:20:41 -04:00
|
|
|
executable = "${Jvm.current().javaHome}/bin/keytool"
|
2020-05-22 11:49:36 -04:00
|
|
|
standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8'))
|
|
|
|
args '-genkey',
|
|
|
|
'-alias', 'test-node',
|
|
|
|
'-keystore', nodeKeystore,
|
|
|
|
'-keyalg', 'RSA',
|
|
|
|
'-keysize', '2048',
|
|
|
|
'-validity', '712',
|
|
|
|
'-dname', 'CN=' + host,
|
|
|
|
'-keypass', 'keypass',
|
|
|
|
'-storepass', 'keypass',
|
2020-06-02 09:33:53 -04:00
|
|
|
'-ext', san.toString()
|
2020-05-22 11:49:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the client's keystore
|
|
|
|
File clientKeyStore = file("$keystoreDir/test-client.jks")
|
2020-06-02 09:33:53 -04:00
|
|
|
tasks.register("createClientKeyStore", LoggedExec) {
|
2020-05-22 11:49:36 -04:00
|
|
|
doFirst {
|
|
|
|
if (clientKeyStore.parentFile.exists() == false) {
|
|
|
|
clientKeyStore.parentFile.mkdirs()
|
|
|
|
}
|
|
|
|
if (clientKeyStore.exists()) {
|
|
|
|
delete clientKeyStore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
executable = "${BuildParams.runtimeJavaHome}/bin/keytool"
|
|
|
|
standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8'))
|
|
|
|
args '-genkey',
|
|
|
|
'-alias', 'test-client',
|
|
|
|
'-keystore', clientKeyStore,
|
|
|
|
'-keyalg', 'RSA',
|
|
|
|
'-keysize', '2048',
|
|
|
|
'-validity', '712',
|
|
|
|
'-dname', 'CN=' + host,
|
|
|
|
'-keypass', 'keypass',
|
|
|
|
'-storepass', 'keypass',
|
2020-06-02 09:33:53 -04:00
|
|
|
'-ext', san.toString()
|
2020-05-22 11:49:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Export the node's certificate
|
|
|
|
File nodeCertificate = file("$keystoreDir/test-node.cert")
|
2020-06-02 09:33:53 -04:00
|
|
|
tasks.register("exportNodeCertificate", LoggedExec) {
|
|
|
|
dependsOn "createNodeKeyStore"
|
2020-05-22 11:49:36 -04:00
|
|
|
doFirst {
|
|
|
|
if (nodeCertificate.parentFile.exists() == false) {
|
|
|
|
nodeCertificate.parentFile.mkdirs()
|
|
|
|
}
|
|
|
|
if (nodeCertificate.exists()) {
|
|
|
|
delete nodeCertificate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
executable = "${BuildParams.runtimeJavaHome}/bin/keytool"
|
|
|
|
args '-export',
|
|
|
|
'-alias', 'test-node',
|
|
|
|
'-keystore', nodeKeystore,
|
|
|
|
'-storepass', 'keypass',
|
|
|
|
'-file', nodeCertificate
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the node certificate in the client's keystore
|
2020-06-02 09:33:53 -04:00
|
|
|
tasks.register("importNodeCertificateInClientKeyStore", LoggedExec) {
|
|
|
|
dependsOn "createClientKeyStore", "exportNodeCertificate"
|
2020-05-22 11:49:36 -04:00
|
|
|
executable = "${BuildParams.runtimeJavaHome}/bin/keytool"
|
|
|
|
args '-import',
|
|
|
|
'-alias', 'test-node',
|
|
|
|
'-keystore', clientKeyStore,
|
|
|
|
'-storepass', 'keypass',
|
|
|
|
'-file', nodeCertificate,
|
|
|
|
'-noprompt'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Export the client's certificate
|
|
|
|
File clientCertificate = file("$keystoreDir/test-client.cert")
|
2020-06-02 09:33:53 -04:00
|
|
|
tasks.register("exportClientCertificate", LoggedExec) {
|
|
|
|
dependsOn "createClientKeyStore"
|
2020-05-22 11:49:36 -04:00
|
|
|
doFirst {
|
|
|
|
if (clientCertificate.parentFile.exists() == false) {
|
|
|
|
clientCertificate.parentFile.mkdirs()
|
|
|
|
}
|
|
|
|
if (clientCertificate.exists()) {
|
|
|
|
delete clientCertificate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
executable = "${BuildParams.runtimeJavaHome}/bin/keytool"
|
|
|
|
args '-export',
|
|
|
|
'-alias', 'test-client',
|
|
|
|
'-keystore', clientKeyStore,
|
|
|
|
'-storepass', 'keypass',
|
|
|
|
'-file', clientCertificate
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the client certificate in the node's keystore
|
2020-06-02 09:33:53 -04:00
|
|
|
tasks.register("importClientCertificateInNodeKeyStore", LoggedExec) {
|
|
|
|
dependsOn "createNodeKeyStore", "exportClientCertificate"
|
2020-05-22 11:49:36 -04:00
|
|
|
executable = "${BuildParams.runtimeJavaHome}/bin/keytool"
|
|
|
|
args '-import',
|
|
|
|
'-alias', 'test-client',
|
|
|
|
'-keystore', nodeKeystore,
|
|
|
|
'-storepass', 'keypass',
|
|
|
|
'-file', clientCertificate,
|
|
|
|
'-noprompt'
|
|
|
|
}
|
|
|
|
|
|
|
|
forbiddenPatterns {
|
|
|
|
exclude '**/*.cert'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add keystores to test classpath: it expects it there
|
|
|
|
sourceSets.test.resources.srcDir(keystoreDir)
|
2020-06-02 09:33:53 -04:00
|
|
|
processTestResources.dependsOn("importNodeCertificateInClientKeyStore", "importClientCertificateInNodeKeyStore")
|
2020-05-22 11:49:36 -04:00
|
|
|
|
|
|
|
integTest.runner {
|
2020-06-02 09:33:53 -04:00
|
|
|
dependsOn("importClientCertificateInNodeKeyStore")
|
2020-05-22 11:49:36 -04:00
|
|
|
onlyIf {
|
|
|
|
// Do not attempt to form a cluster in a FIPS JVM, as doing so with a JKS keystore will fail.
|
|
|
|
// TODO Revisit this when SQL CLI client can handle key/certificate instead of only Keystores.
|
|
|
|
// https://github.com/elastic/elasticsearch/issues/32306
|
|
|
|
BuildParams.inFipsJvm == false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testClusters.integTest {
|
|
|
|
// The setup that we actually want
|
|
|
|
setting 'xpack.license.self_generated.type', 'trial'
|
|
|
|
setting 'xpack.security.http.ssl.enabled', 'true'
|
|
|
|
setting 'xpack.security.transport.ssl.enabled', 'true'
|
|
|
|
|
|
|
|
// ceremony to set up ssl
|
|
|
|
setting 'xpack.security.transport.ssl.keystore.path', 'test-node.jks'
|
|
|
|
setting 'xpack.security.http.ssl.keystore.path', 'test-node.jks'
|
|
|
|
keystore 'xpack.security.transport.ssl.keystore.secure_password', 'keypass'
|
|
|
|
keystore 'xpack.security.http.ssl.keystore.secure_password', 'keypass'
|
|
|
|
|
|
|
|
|
|
|
|
// copy keystores into config/
|
|
|
|
extraConfigFile nodeKeystore.name, nodeKeystore
|
|
|
|
extraConfigFile clientKeyStore.name, clientKeyStore
|
|
|
|
}
|