build.gradle 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import org.elasticsearch.gradle.info.BuildParams
  2. /*
  3. * Licensed to Elasticsearch under one or more contributor
  4. * license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright
  6. * ownership. Elasticsearch licenses this file to you under
  7. * the Apache License, Version 2.0 (the "License"); you may
  8. * not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. esplugin {
  21. description 'The EC2 discovery plugin allows to use AWS API for the unicast discovery mechanism.'
  22. classname 'org.elasticsearch.discovery.ec2.Ec2DiscoveryPlugin'
  23. }
  24. versions << [
  25. 'aws': '1.11.749'
  26. ]
  27. dependencies {
  28. compile "com.amazonaws:aws-java-sdk-ec2:${versions.aws}"
  29. compile "com.amazonaws:aws-java-sdk-core:${versions.aws}"
  30. compile "org.apache.httpcomponents:httpclient:${versions.httpclient}"
  31. compile "org.apache.httpcomponents:httpcore:${versions.httpcore}"
  32. compile "commons-logging:commons-logging:${versions.commonslogging}"
  33. compile "org.apache.logging.log4j:log4j-1.2-api:${versions.log4j}"
  34. compile "commons-codec:commons-codec:${versions.commonscodec}"
  35. compile "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
  36. compile "com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}"
  37. }
  38. restResources {
  39. restApi {
  40. includeCore '_common', 'cluster', 'nodes'
  41. }
  42. }
  43. tasks.named("dependencyLicenses").configure {
  44. mapping from: /aws-java-sdk-.*/, to: 'aws-java-sdk'
  45. mapping from: /jackson-.*/, to: 'jackson'
  46. }
  47. bundlePlugin {
  48. from('config/discovery-ec2') {
  49. into 'config'
  50. }
  51. }
  52. task writeTestJavaPolicy {
  53. doLast {
  54. final File tmp = file("${buildDir}/tmp")
  55. if (tmp.exists() == false && tmp.mkdirs() == false) {
  56. throw new GradleException("failed to create temporary directory [${tmp}]")
  57. }
  58. final File javaPolicy = file("${tmp}/java.policy")
  59. if (BuildParams.inFipsJvm) {
  60. javaPolicy.write(
  61. [
  62. "grant {",
  63. "permission java.security.SecurityPermission \"putProviderProperty.BCFIPS\";",
  64. "permission java.security.SecurityPermission \"putProviderProperty.BCJSSE\";",
  65. "permission java.lang.RuntimePermission \"getProtectionDomain\";",
  66. "permission java.util.PropertyPermission \"java.runtime.name\", \"read\";",
  67. "permission org.bouncycastle.crypto.CryptoServicesPermission \"tlsAlgorithmsEnabled\";",
  68. "permission java.lang.RuntimePermission \"accessClassInPackage.sun.security.internal.spec\";",
  69. "permission java.lang.RuntimePermission \"accessDeclaredMembers\";",
  70. "permission java.util.PropertyPermission \"intellij.debug.agent\", \"read\";",
  71. "permission java.util.PropertyPermission \"intellij.debug.agent\", \"write\";",
  72. "permission org.bouncycastle.crypto.CryptoServicesPermission \"exportSecretKey\";",
  73. "permission org.bouncycastle.crypto.CryptoServicesPermission \"exportPrivateKey\";",
  74. "permission java.io.FilePermission \"\${javax.net.ssl.trustStore}\", \"read\";",
  75. " permission java.util.PropertyPermission \"com.amazonaws.sdk.ec2MetadataServiceEndpointOverride\", \"write\";",
  76. "};"
  77. ].join("\n")
  78. )
  79. } else {
  80. javaPolicy.write(
  81. [
  82. "grant {",
  83. " permission java.util.PropertyPermission \"com.amazonaws.sdk.ec2MetadataServiceEndpointOverride\", \"write\";",
  84. "};"
  85. ].join("\n"))
  86. }
  87. }
  88. }
  89. test {
  90. dependsOn writeTestJavaPolicy
  91. // this is needed for insecure plugins, remove if possible!
  92. systemProperty 'tests.artifact', project.name
  93. // this is needed to manipulate com.amazonaws.sdk.ec2MetadataServiceEndpointOverride system property
  94. // it is better rather disable security manager at all with `systemProperty 'tests.security.manager', 'false'`
  95. if (BuildParams.inFipsJvm){
  96. systemProperty 'java.security.policy', "=file://${buildDir}/tmp/java.policy"
  97. } else {
  98. systemProperty 'java.security.policy', "file://${buildDir}/tmp/java.policy"
  99. }
  100. }
  101. check {
  102. // also execute the QA tests when testing the plugin
  103. dependsOn 'qa:amazon-ec2:check'
  104. }
  105. thirdPartyAudit.ignoreMissingClasses(
  106. // classes are missing
  107. 'com.amazonaws.jmespath.JmesPathEvaluationVisitor',
  108. 'com.amazonaws.jmespath.JmesPathExpression',
  109. 'com.amazonaws.jmespath.JmesPathField',
  110. 'com.amazonaws.jmespath.JmesPathFlatten',
  111. 'com.amazonaws.jmespath.JmesPathIdentity',
  112. 'com.amazonaws.jmespath.JmesPathLengthFunction',
  113. 'com.amazonaws.jmespath.JmesPathLiteral',
  114. 'com.amazonaws.jmespath.JmesPathProjection',
  115. 'com.amazonaws.jmespath.JmesPathSubExpression',
  116. 'com.amazonaws.jmespath.ObjectMapperSingleton',
  117. 'com.amazonaws.jmespath.OpGreaterThan',
  118. 'software.amazon.ion.IonReader',
  119. 'software.amazon.ion.IonSystem',
  120. 'software.amazon.ion.IonType',
  121. 'software.amazon.ion.IonWriter',
  122. 'software.amazon.ion.Timestamp',
  123. 'software.amazon.ion.system.IonBinaryWriterBuilder',
  124. 'software.amazon.ion.system.IonSystemBuilder',
  125. 'software.amazon.ion.system.IonTextWriterBuilder',
  126. 'software.amazon.ion.system.IonWriterBuilder',
  127. 'javax.servlet.ServletContextEvent',
  128. 'javax.servlet.ServletContextListener',
  129. 'org.apache.avalon.framework.logger.Logger',
  130. 'org.apache.log.Hierarchy',
  131. 'org.apache.log.Logger'
  132. )
  133. thirdPartyAudit.ignoreMissingClasses(
  134. 'javax.xml.bind.DatatypeConverter',
  135. 'javax.xml.bind.JAXBContext'
  136. )