authors.asciidoc 4.4 KB

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