authors.asciidoc 5.6 KB

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