-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Integ Tests to run in a FIPS-140 JVM #31989
Changes from 3 commits
c9008db
32a9b89
740259d
86ba696
ced0e72
86bdddd
7e1550f
dd61b4b
8f020b1
7660385
12b7ccb
a44d734
b5753bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,7 +287,7 @@ class BuildPlugin implements Plugin<Project> { | |
} | ||
|
||
/** Runs the given javascript using jjs from the jdk, and returns the output */ | ||
private static String runJavascript(Project project, String javaHome, String script) { | ||
static String runJavascript(Project project, String javaHome, String script) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see my comment about this use. This can go back to private. |
||
ByteArrayOutputStream stdout = new ByteArrayOutputStream() | ||
ByteArrayOutputStream stderr = new ByteArrayOutputStream() | ||
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.hamcrest.Matchers.anyOf; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
@@ -205,7 +206,10 @@ public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) { | |
assertThat(nodesMap.size(), equalTo(cluster().size())); | ||
for (final NodesReloadSecureSettingsResponse.NodeResponse nodeResponse : nodesReloadResponse.getNodes()) { | ||
assertThat(nodeResponse.reloadException(), notNullValue()); | ||
assertThat(nodeResponse.reloadException(), instanceOf(IOException.class)); | ||
// Running in a JVM with a BouncyCastle FIPS Security Provider, decrypting the Keystore with the wrong | ||
// password can return a SecurityException if the DataInputStream can't be fully consumed | ||
assertThat(nodeResponse.reloadException(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should set an additional system property when running in a fips jvm so tests can conditionalize checks like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something similar is already added in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we should add whatever extra properties are necessary for the test to distinguish the two cases. What would happen if one jvm started throwing the other exception? The test would be out of date but we would have no idea there was a behavior change. |
||
anyOf(instanceOf(IOException.class), instanceOf(SecurityException.class))); | ||
} | ||
} catch (final AssertionError e) { | ||
reloadSettingsError.set(e); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,39 +104,26 @@ integTestRunner { | |
systemProperty 'tests.rest.blacklist', blacklist.join(',') | ||
} | ||
|
||
// location of generated keystores and certificates | ||
// location for keys and certificates | ||
File keystoreDir = new File(project.buildDir, 'keystore') | ||
|
||
// Generate the node's keystore | ||
File nodeKeystore = new File(keystoreDir, 'test-node.jks') | ||
task createNodeKeyStore(type: LoggedExec) { | ||
doFirst { | ||
if (nodeKeystore.parentFile.exists() == false) { | ||
nodeKeystore.parentFile.mkdirs() | ||
} | ||
if (nodeKeystore.exists()) { | ||
delete nodeKeystore | ||
File nodeKey = new File(keystoreDir, 'testnode.pem') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is usually written There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I was merely following existing conventions here. I'll change this |
||
File nodeCert = new File(keystoreDir, 'testnode.crt') | ||
|
||
// Add key and certs to test classpath: it expects them there | ||
// User cert and key PEM files instead of a JKS Keystore for the cluster's trust material so that | ||
// it can run in a FIPS 140 JVM | ||
task copyKeyCerts(type: Copy) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a comment with a TODO and link to the PR that will make this not use cross project references? |
||
from('./core/src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creating coupling between projects like this is not a good idea in Gradle.
Where In this case, would it be feasible to have the build generate these files ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unfortunately not.
Not all projects need all files ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about doing in Java what openssl would do ? Maybe using BouncyCastle or some other lib ? Would it be more effort than what it's worth ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, can't do that. We explicitly removed BC dependency recently on purpose ( see #30358 on why ). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, BouncyCastle would be a dependency for the build, which is a bit different, I don't think we'll be able to run Gradle itself on a FIPS JVM, or if we even want to. That being said I suggested it because it seemed the cleanest and not too much work - but admittedly I'm missing a lot of context on this so I could be totally wrong. I don't have a strong preference for this, separate project or referencing trough project is also fine for me ( in this order of preference ). |
||
include 'testnode.crt', 'testnode.pem' | ||
} | ||
} | ||
executable = new File(project.runtimeJavaHome, 'bin/keytool') | ||
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=smoke-test-plugins-ssl', | ||
'-keypass', 'keypass', | ||
'-storepass', 'keypass' | ||
into keystoreDir | ||
} | ||
|
||
// Add keystores to test classpath: it expects it there | ||
sourceSets.test.resources.srcDir(keystoreDir) | ||
processTestResources.dependsOn(createNodeKeyStore) | ||
processTestResources.dependsOn(copyKeyCerts) | ||
|
||
integTestCluster { | ||
dependsOn createNodeKeyStore | ||
dependsOn copyKeyCerts | ||
setting 'xpack.ml.enabled', 'true' | ||
setting 'xpack.security.enabled', 'true' | ||
setting 'logger.org.elasticsearch.xpack.ml.datafeed', 'TRACE' | ||
|
@@ -145,18 +132,20 @@ integTestCluster { | |
setting 'xpack.monitoring.exporters._local.enabled', 'false' | ||
setting 'xpack.security.authc.token.enabled', 'true' | ||
setting 'xpack.security.transport.ssl.enabled', 'true' | ||
setting 'xpack.security.transport.ssl.keystore.path', nodeKeystore.name | ||
setting 'xpack.security.transport.ssl.key', nodeKey.name | ||
setting 'xpack.security.transport.ssl.certificate', nodeCert.name | ||
setting 'xpack.security.transport.ssl.verification_mode', 'certificate' | ||
setting 'xpack.security.audit.enabled', 'true' | ||
setting 'xpack.license.self_generated.type', 'trial' | ||
keystoreSetting 'bootstrap.password', 'x-pack-test-password' | ||
keystoreSetting 'xpack.security.transport.ssl.keystore.secure_password', 'keypass' | ||
keystoreSetting 'xpack.security.transport.ssl.secure_key_passphrase', 'testnode' | ||
keystoreSetting 'xpack.security.ingest.hash.processor.key', 'hmackey' | ||
distribution = 'zip' // this is important since we use the reindex module in ML | ||
|
||
setupCommand 'setupTestUser', 'bin/elasticsearch-users', 'useradd', 'x_pack_rest_user', '-p', 'x-pack-test-password', '-r', 'superuser' | ||
|
||
extraConfigFile nodeKeystore.name, nodeKeystore | ||
extraConfigFile nodeKey.name, nodeKey | ||
extraConfigFile nodeCert.name, nodeCert | ||
|
||
waitCondition = { NodeInfo node, AntBuilder ant -> | ||
File tmpFile = new File(node.cwd, 'wait.success') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not actually guarantee that it will be run right before the test is executed. Other doFirst blocks could (and are) added throughout the build, and which order they run in is dependent on when they are added to the task.
I think this would be better as setting a project property in
BuildPlugin.globalBuildInfo
alongside how we setruntimeJavaHome
. Then inBuildPlugin.commonTestConfig
have a condition on whether it is a fips jvm to add these sysprops.