Skip to content

Commit a400d2f

Browse files
committed
Fix custom policy in plugins in FIPS 140 (elastic#52046)
Our FIPS 140 testing depends on setting the appropriate java policy in order to configure the JVM in FIPS mode. Some tests ( discovery-ec2 and ccr qa ) also needed to set a custom policy file to grant a specific permission, which overwrote the FIPS related policy and tests would fail. This change ensures that when a custom policy needs to be set in these tests, the permissions that are necessary for FIPS are also set. Resolves: elastic#51685, elastic#52034
1 parent 9b7356d commit a400d2f

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

x-pack/plugin/ccr/qa/downgrade-to-basic-license/build.gradle

+35-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.elasticsearch.gradle.info.BuildParams
12
import org.elasticsearch.gradle.test.RestIntegTestTask
23

34
apply plugin: 'elasticsearch.testclusters'
@@ -26,21 +27,47 @@ task writeJavaPolicy {
2627
if (policyFile.parentFile.exists() == false && policyFile.parentFile.mkdirs() == false) {
2728
throw new GradleException("failed to create temporary directory [${tmp}]")
2829
}
29-
policyFile.write(
30-
[
31-
"grant {",
32-
" permission java.io.FilePermission \"${-> testClusters."follow-cluster".getFirstNode().getServerLog()}\", \"read\";",
33-
"};"
34-
].join("\n")
35-
)
30+
if (BuildParams.inFipsJvm) {
31+
policyFile.write(
32+
[
33+
"grant {",
34+
"permission java.security.SecurityPermission \"putProviderProperty.BCFIPS\";",
35+
"permission java.security.SecurityPermission \"putProviderProperty.BCJSSE\";",
36+
"permission java.lang.RuntimePermission \"getProtectionDomain\";",
37+
"permission java.util.PropertyPermission \"java.runtime.name\", \"read\";",
38+
"permission org.bouncycastle.crypto.CryptoServicesPermission \"tlsAlgorithmsEnabled\";",
39+
"permission java.lang.RuntimePermission \"accessClassInPackage.sun.security.internal.spec\";",
40+
"permission java.lang.RuntimePermission \"accessDeclaredMembers\";",
41+
"permission java.util.PropertyPermission \"intellij.debug.agent\", \"read\";",
42+
"permission java.util.PropertyPermission \"intellij.debug.agent\", \"write\";",
43+
"permission org.bouncycastle.crypto.CryptoServicesPermission \"exportSecretKey\";",
44+
"permission org.bouncycastle.crypto.CryptoServicesPermission \"exportPrivateKey\";",
45+
"permission java.io.FilePermission \"\${javax.net.ssl.trustStore}\", \"read\";",
46+
"permission java.io.FilePermission \"${-> testClusters."follow-cluster".getFirstNode().getServerLog()}\", \"read\";",
47+
"};"
48+
].join("\n")
49+
)
50+
} else {
51+
policyFile.write(
52+
[
53+
"grant {",
54+
" permission java.io.FilePermission \"${-> testClusters."follow-cluster".getFirstNode().getServerLog()}\", \"read\";",
55+
"};"
56+
].join("\n")
57+
)
58+
}
3659
}
3760
}
3861

3962
task "follow-cluster"(type: RestIntegTestTask) {
4063
dependsOn 'writeJavaPolicy', "leader-cluster"
4164
runner {
4265
useCluster testClusters."leader-cluster"
43-
systemProperty 'java.security.policy', "file://${policyFile}"
66+
if (BuildParams.inFipsJvm){
67+
systemProperty 'java.security.policy', "=file://${policyFile}"
68+
} else {
69+
systemProperty 'java.security.policy', "file://${policyFile}"
70+
}
4471
systemProperty 'tests.target_cluster', 'follow'
4572
nonInputProperties.systemProperty 'tests.leader_host', "${-> testClusters."leader-cluster".getAllHttpSocketURI().get(0)}"
4673
nonInputProperties.systemProperty 'log', "${-> testClusters."follow-cluster".getFirstNode().getServerLog()}"

0 commit comments

Comments
 (0)