authors.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. [[plugin-authors]]
  2. == Help for plugin authors
  3. :plugin-properties-files: {docdir}/../../buildSrc/src/main/resources
  4. The Elasticsearch repository contains examples of:
  5. * a https://github.com/elastic/elasticsearch/tree/master/plugins/jvm-example[Java plugin]
  6. which contains Java code.
  7. * a https://github.com/elastic/elasticsearch/tree/master/plugins/examples/rescore[Java plugin]
  8. which contains a rescore plugin.
  9. * a https://github.com/elastic/elasticsearch/tree/master/plugins/examples/script-expert-scoring[Java plugin]
  10. which contains a script plugin.
  11. * a https://github.com/elastic/elasticsearch/tree/master/plugins/examples/meta-plugin[Java plugin]
  12. which contains a meta plugin.
  13. These examples provide the bare bones needed to get started. For more
  14. information about how to write a plugin, we recommend looking at the plugins
  15. listed in this documentation for inspiration.
  16. [float]
  17. === Plugin Structure
  18. All plugin files must be contained in a directory called `elasticsearch`.
  19. [float]
  20. === Plugin descriptor file
  21. All plugins must contain a file called `plugin-descriptor.properties` in the folder named `elasticsearch`.
  22. The format for this file is described in detail in this example:
  23. ["source","properties",subs="attributes"]
  24. --------------------------------------------------
  25. include::{plugin-properties-files}/plugin-descriptor.properties[]
  26. --------------------------------------------------
  27. Either fill in this template yourself or, if you are using Elasticsearch's Gradle build system, you
  28. can fill in the necessary values in the `build.gradle` file for your plugin.
  29. [float]
  30. ==== Mandatory elements for plugins
  31. [cols="<,<,<",options="header",]
  32. |=======================================================================
  33. |Element | Type | Description
  34. |`description` |String | simple summary of the plugin
  35. |`version` |String | plugin's version
  36. |`name` |String | the plugin name
  37. |`classname` |String | the name of the class to load, fully-qualified.
  38. |`java.version` |String | version of java the code is built against.
  39. Use the system property `java.specification.version`. Version string must be a sequence
  40. of nonnegative decimal integers separated by "."'s and may have leading zeros.
  41. |`elasticsearch.version` |String | version of Elasticsearch compiled against.
  42. |=======================================================================
  43. Note that only jar files in the 'elasticsearch' directory are added to the classpath for the plugin!
  44. If you need other resources, package them into a resources jar.
  45. [IMPORTANT]
  46. .Plugin release lifecycle
  47. ==============================================
  48. You will have to release a new version of the plugin for each new Elasticsearch release.
  49. This version is checked when the plugin is loaded so Elasticsearch will refuse to start
  50. in the presence of plugins with the incorrect `elasticsearch.version`.
  51. ==============================================
  52. [float]
  53. === Testing your plugin
  54. When testing a Java plugin, it will only be auto-loaded if it is in the
  55. `plugins/` directory. Use `bin/elasticsearch-plugin install file:///path/to/your/plugin`
  56. to install your plugin for testing.
  57. You may also load your plugin within the test framework for integration tests.
  58. Read more in {ref}/integration-tests.html#changing-node-configuration[Changing Node Configuration].
  59. [float]
  60. [[plugin-authors-jsm]]
  61. === Java Security permissions
  62. Some plugins may need additional security permissions. A plugin can include
  63. the optional `plugin-security.policy` file containing `grant` statements for
  64. additional permissions. Any additional permissions will be displayed to the user
  65. with a large warning, and they will have to confirm them when installing the
  66. plugin interactively. So if possible, it is best to avoid requesting any
  67. spurious permissions!
  68. If you are using the Elasticsearch Gradle build system, place this file in
  69. `src/main/plugin-metadata` and it will be applied during unit tests as well.
  70. Keep in mind that the Java security model is stack-based, and the additional
  71. permissions will only be granted to the jars in your plugin, so you will have
  72. write proper security code around operations requiring elevated privileges.
  73. It is recommended to add a check to prevent unprivileged code (such as scripts)
  74. from gaining escalated permissions. For example:
  75. [source,java]
  76. --------------------------------------------------
  77. // ES permission you should check before doPrivileged() blocks
  78. import org.elasticsearch.SpecialPermission;
  79. SecurityManager sm = System.getSecurityManager();
  80. if (sm != null) {
  81. // unprivileged code such as scripts do not have SpecialPermission
  82. sm.checkPermission(new SpecialPermission());
  83. }
  84. AccessController.doPrivileged(
  85. // sensitive operation
  86. );
  87. --------------------------------------------------
  88. See http://www.oracle.com/technetwork/java/seccodeguide-139067.html[Secure Coding Guidelines for Java SE]
  89. for more information.
  90. [float]
  91. === Meta Plugin
  92. It is also possible to bundle multiple plugins into a meta plugin.
  93. A directory for each sub-plugin must be contained in a directory called `elasticsearch.
  94. The meta plugin must also contain a file called `meta-plugin-descriptor.properties` in the directory named
  95. `elasticsearch`.
  96. The format for this file is described in detail in this example:
  97. ["source","properties",subs="attributes"]
  98. --------------------------------------------------
  99. include::{plugin-properties-files}/meta-plugin-descriptor.properties[]
  100. --------------------------------------------------
  101. A meta plugin can be installed/removed like a normal plugin with the `bin/elasticsearch-plugin` command.