Skip to content
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

[WIP] Add BouncyCastleFipsProvider as test dependency #41024

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ class BuildPlugin implements Plugin<Project> {
runtimeJavaVersionDetails = findJavaVersionDetails(project, runtimeJavaHome)
runtimeJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, runtimeJavaHome))
}

String inFipsJvmScript = 'print(java.security.Security.getProviders()[0].name.toLowerCase().contains("fips"));'
boolean inFipsJvm = Boolean.parseBoolean(runJavaAsScript(project, runtimeJavaHome, inFipsJvmScript))
// Java home name checking is fragile, but we control the environment
boolean inFipsJvm = runtimeJavaHome.contains("fips")
Copy link
Member Author

@jkakavas jkakavas Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the Provider was statically added as a system wide dependency ( in lib/ext of a jdk8 JVM ) so we could evaluate the getProviders() result here. Now the preference order is still set in java.security but the dependency is not yet available so the provider won't be loaded


// Build debugging info
println '======================================='
Expand Down Expand Up @@ -906,6 +905,16 @@ class BuildPlugin implements Plugin<Project> {
File heapdumpDir = new File(project.buildDir, 'heapdump')

project.tasks.withType(Test) { Test test ->
RepositoryHandler repos = project.repositories
jkakavas marked this conversation as resolved.
Show resolved Hide resolved
if (project.ext.inFipsJvm) {
repos.ivy {
url "https://downloads.bouncycastle.org"
patternLayout {
artifact 'fips-java/[module]-[revision].[ext]'
}
}
project.dependencies.add('testRuntimeOnly', "org.bouncycastle:bc-fips:1.0.1:jar")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we carry this classpath tot he clusters running in the rest tests, so these will probably not be running with fips enabled. We should have a smoke test to verify that fips is really enabled everywhere we think it is when we build.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I missed this but it seems this won't for rest tests as the tests themselves will run on fips jvm but the cluster will not.

Good catch, thanks

How about the integTest clusters? Those are covered by the above, correct ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes internal clusters run in the same jvm as tests so would are covered.

}
File testOutputDir = new File(test.reports.junitXml.getDestination(), "output")

doFirst {
Expand Down
9 changes: 4 additions & 5 deletions distribution/tools/plugin-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ test {
systemProperty 'tests.security.manager', 'false'
}

if (project.inFipsJvm) {
// FIPS JVM includes manny classes from bouncycastle which count as jar hell for the third party audit,
// rather than provide a long list of exclusions, disable the check on FIPS.
thirdPartyAudit.enabled = false
}
if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this PrecommitTasks.configureJarHell() where the JarHell task is actually created rather than have to explicitly disable this all over the place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we fine with disabling jarHell for all projects while running tests in a FIPS JVM ? If so, I'd be more than happy to

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We have numerous other builds that will catch any issues here.

}
11 changes: 2 additions & 9 deletions modules/transport-netty4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ thirdPartyAudit {
'org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder',
'org.bouncycastle.jce.provider.BouncyCastleProvider',
'org.bouncycastle.operator.jcajce.JcaContentSignerBuilder',
'org.bouncycastle.asn1.x500.X500Name',

// from io.netty.handler.ssl.JettyNpnSslEngine (netty)
'org.eclipse.jetty.npn.NextProtoNego$ClientProvider',
Expand Down Expand Up @@ -169,12 +170,4 @@ thirdPartyAudit {
'io.netty.util.internal.shaded.org.jctools.util.UnsafeRefArrayAccess',
'io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator'
)
}

if (project.inFipsJvm == false) {
// BouncyCastleFIPS provides this class, so the exclusion is invalid when running CI in
// a FIPS JVM with BouncyCastleFIPS Provider
thirdPartyAudit.ignoreMissingClasses (
'org.bouncycastle.asn1.x500.X500Name'
)
}
}
8 changes: 7 additions & 1 deletion plugins/discovery-azure-classic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
compile 'org.codehaus.jackson:jackson-core-asl:1.9.2'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.2'
compile 'org.codehaus.jackson:jackson-jaxrs:1.9.2'
compile 'org.codehaus.jackson:jackson-xc:1.9.2'
compile 'org.codehaus.jackson:jackson-xc:1.9.2'

// HACK: javax.xml.bind was removed from default modules in java 9, so we pull the api in here,
// and whitelist this hack in JarHell
Expand All @@ -63,6 +63,7 @@ File keystore = new File(project.buildDir, 'keystore/test-node.jks')

// generate the keystore
task createKey(type: LoggedExec) {
onlyIf { inFipsJvm == false }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this task would fail as the JVM is setup for FIPS (BCFKS keystores, etc) but the dependency is not added when this is evaluated so the necessary classes are not available. We don't use the produced keystore eitherway as this can only work with a JKS keystore which is not available in FIPS - and this is why the integTest task is also disabled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. If integTest is disabled, what would try to run this task in FIPS mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's because of processTestResources.dependsOn(createKey) below. I'd be happy to explore alternatives if you have suggestions!

doFirst {
project.delete(keystore.parentFile)
keystore.parentFile.mkdirs()
Expand Down Expand Up @@ -133,3 +134,8 @@ thirdPartyAudit.ignoreMissingClasses (
'com.sun.xml.fastinfoset.stax.StAXDocumentParser',
'com.sun.xml.fastinfoset.stax.StAXDocumentSerializer'
)

if (inFipsJvm) {
// We do not run integ tests in FIPS mode as these use a JKS keystore for the azure settings
integTest.enabled = false
}
10 changes: 6 additions & 4 deletions plugins/ingest-attachment/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ dependencies {
compile "org.apache.pdfbox:jempbox:1.8.16"
compile "commons-logging:commons-logging:${versions.commonslogging}"
compile "org.bouncycastle:bcmail-jdk15on:${versions.bouncycastle}"
compile "org.bouncycastle:bcprov-jdk15on:${versions.bouncycastle}"
if (inFipsJvm == false) {
// In FIPS JVMs we add bc fips provider as a testRuntimeOnly dependency
compile "org.bouncycastle:bcprov-jdk15on:${versions.bouncycastle}"
}
compile "org.bouncycastle:bcpkix-jdk15on:${versions.bouncycastle}"
// OpenOffice
compile "org.apache.poi:poi-ooxml:${versions.poi}"
Expand Down Expand Up @@ -85,7 +88,6 @@ thirdPartyAudit{
}

if (project.inFipsJvm) {
// FIPS JVM includes manny classes from bouncycastle which count as jar hell for the third party audit,
// rather than provide a long list of exclusions, disable the check on FIPS.
thirdPartyAudit.enabled = false
// Unused license bcprov-jdk15on-LICENSE.txt when not adding bcprov as compile dependency
dependencyLicenses.enabled = false
}
10 changes: 2 additions & 8 deletions plugins/transport-nio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ thirdPartyAudit {
'org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder',
'org.bouncycastle.jce.provider.BouncyCastleProvider',
'org.bouncycastle.operator.jcajce.JcaContentSignerBuilder',
'org.bouncycastle.asn1.x500.X500Name',

// from io.netty.handler.ssl.JettyNpnSslEngine (netty)
'org.eclipse.jetty.npn.NextProtoNego$ClientProvider',
Expand Down Expand Up @@ -147,11 +148,4 @@ thirdPartyAudit {

'io.netty.handler.ssl.util.OpenJdkSelfSignedCertGenerator'
)
}
if (project.inFipsJvm == false) {
// BouncyCastleFIPS provides this class, so the exclusion is invalid when running CI in
// a FIPS JVM with BouncyCastleFIPS Provider
thirdPartyAudit.ignoreMissingClasses (
'org.bouncycastle.asn1.x500.X500Name'
)
}
}
4 changes: 4 additions & 0 deletions x-pack/plugin/ml/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ gradle.projectsEvaluated {
task icTest {
dependsOn internalClusterTest
}
if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
4 changes: 4 additions & 0 deletions x-pack/plugin/ml/qa/native-multi-node-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ integTestCluster {
return tmpFile.exists()
}
}
if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
5 changes: 5 additions & 0 deletions x-pack/plugin/security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,8 @@ gradle.projectsEvaluated {
.each { check.dependsOn it.check }
}

if (inFipsJvm){
// Disable jarHell in FIPS as we bundle the BC FIPS Provider for the tests and there are libraries (opensaml) that
// depend on the plain BC Provider
jarHell.enabled = false
}
7 changes: 3 additions & 4 deletions x-pack/plugin/security/cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ dependencyLicenses {
}

if (project.inFipsJvm) {
// Disable jarHell in FIPS as we bundle the BC FIPS Provider for the tests and this project depends on the the normal
// BouncyCastle Provider
jarHell.enabled = false
test.enabled = false
testingConventions.enabled = false
// Forbiden APIs non-portable checks fail because bouncy castle classes being used from the FIPS JDK since those are
// not part of the Java specification - all of this is as designed, so we have to relax this check for FIPS.
tasks.withType(CheckForbiddenApis) {
bundledSignatures -= "jdk-non-portable"
}
// FIPS JVM includes many classes from bouncycastle which count as jar hell for the third party audit,
// rather than provide a long list of exclusions, disable the check on FIPS.
thirdPartyAudit.enabled = false

}
4 changes: 4 additions & 0 deletions x-pack/plugin/security/qa/tls-basic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ integTestCluster {
}
}

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
4 changes: 4 additions & 0 deletions x-pack/plugin/sql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,7 @@ task regen {
}
}
}
if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
9 changes: 7 additions & 2 deletions x-pack/plugin/sql/qa/security/with-ssl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ integTestCluster {
}
}
Closure notRunningFips = {
Boolean.parseBoolean(BuildPlugin.runJavaAsScript(project, project.runtimeJavaHome,
'print(java.security.Security.getProviders()[0].name.toLowerCase().contains("fips"));')) == false
inFipsJvm == false
}

// Do not attempt to form a cluster in a FIPS JVM, as doing so with a JKS keystore will fail.
Expand All @@ -219,6 +218,12 @@ tasks.matching({ it.name == "integTestCluster#init" }).all { onlyIf notRunningFi
tasks.matching({ it.name == "integTestCluster#start" }).all { onlyIf notRunningFips }
tasks.matching({ it.name == "integTestCluster#wait" }).all { onlyIf notRunningFips }
tasks.matching({ it.name == "integTestRunner" }).all { onlyIf notRunningFips }
tasks.matching({ it.name == "createNodeKeyStore" }).all { onlyIf notRunningFips }
tasks.matching({ it.name == "createClientKeyStore" }).all { onlyIf notRunningFips }
tasks.matching({ it.name == "exportNodeCertificate" }).all { onlyIf notRunningFips }
tasks.matching({ it.name == "exportClientCertificate" }).all { onlyIf notRunningFips }
tasks.matching({ it.name == "importNodeCertificateInClientKeyStore" }).all { onlyIf notRunningFips}
tasks.matching({ it.name == "importClientCertificateInNodeKeyStore" }).all { onlyIf notRunningFips}

/** A lazy evaluator to find the san to use for certificate generation. */
class SanEvaluator {
Expand Down
5 changes: 5 additions & 0 deletions x-pack/qa/core-rest-tests-with-security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ integTestCluster {
return tmpFile.exists()
}
}

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
5 changes: 5 additions & 0 deletions x-pack/qa/evil-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ test {
systemProperty 'tests.security.manager', 'false'
include '**/*Tests.class'
}

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
5 changes: 5 additions & 0 deletions x-pack/qa/full-cluster-restart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,8 @@ task copyXPackPluginProps(type: Copy) {
into outputDir
}
project.sourceSets.test.output.dir(outputDir, builtBy: copyXPackPluginProps)

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
4 changes: 4 additions & 0 deletions x-pack/qa/kerberos-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ task copyKeytabToGeneratedResources(type: Copy) {
}
project.sourceSets.test.output.dir(generatedResources, builtBy:copyKeytabToGeneratedResources)

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
7 changes: 6 additions & 1 deletion x-pack/qa/oidc-op-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ integTestCluster {
}
}

thirdPartyAudit.enabled = false
thirdPartyAudit.enabled = false

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
5 changes: 5 additions & 0 deletions x-pack/qa/openldap-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ task copyIdpTrust(type: Copy) {
into outputDir
}
project.sourceSets.test.output.dir(outputDir, builtBy: copyIdpTrust)

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
5 changes: 5 additions & 0 deletions x-pack/qa/reindex-tests-with-security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ integTestCluster {
return http.wait(5000)
}
}

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
5 changes: 5 additions & 0 deletions x-pack/qa/saml-idp-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ thirdPartyAudit {
'com.ibm.icu.lang.UCharacter'
)
}

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
5 changes: 5 additions & 0 deletions x-pack/qa/security-tools-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ forbiddenPatterns {

// these are just tests, no need to audit
thirdPartyAudit.enabled = false

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}
4 changes: 4 additions & 0 deletions x-pack/qa/third-party/active-directory/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ test {
include '**/*Tests.class'
}

if (inFipsJvm){
// Disable jarHell in FIPS as we add the BC FIPS Provider as a dependency for the tests
jarHell.enabled = false
}