authors.asciidoc 4.8 KB

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