creating-classic-plugins.asciidoc 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. [[creating-classic-plugins]]
  2. === Creating classic plugins
  3. Classic plugins provide {es} with mechanisms for custom authentication,
  4. authorization, scoring, and more.
  5. [IMPORTANT]
  6. .Plugin release lifecycle
  7. ==============================================
  8. Classic plugins require you to build a new version for each new {es} release.
  9. This version is checked when the plugin is installed and when it is loaded. {es}
  10. will refuse to start in the presence of plugins with the incorrect
  11. `elasticsearch.version`.
  12. ==============================================
  13. [discrete]
  14. ==== Classic plugin file structure
  15. Classis plugins are ZIP files composed of JAR files and
  16. <<plugin-descriptor-file-{plugin-type},a metadata file called
  17. `plugin-descriptor.properties`>>, a Java properties file that describes the
  18. plugin.
  19. Note that only JAR files at the root of the plugin are added to the classpath
  20. for the plugin. If you need other resources, package them into a resources JAR.
  21. [discrete]
  22. ==== Example plugins
  23. The {es} repository contains {es-repo}tree/main/plugins/examples[examples of plugins]. Some of these include:
  24. * a plugin with {es-repo}tree/main/plugins/examples/custom-settings[custom settings]
  25. * adding {es-repo}tree/main/plugins/examples/rest-handler[custom rest endpoints]
  26. * adding a {es-repo}tree/main/plugins/examples/rescore[custom rescorer]
  27. * a script {es-repo}tree/main/plugins/examples/script-expert-scoring[implemented in Java]
  28. These examples provide the bare bones needed to get started. For more
  29. information about how to write a plugin, we recommend looking at the
  30. {es-repo}tree/main/plugins/[source code of existing plugins] for inspiration.
  31. [discrete]
  32. ==== Testing your plugin
  33. Use `bin/elasticsearch-plugin install file:///path/to/your/plugin`
  34. to install your plugin for testing. The Java plugin is auto-loaded only if it's in the
  35. `plugins/` directory.
  36. [discrete]
  37. [[plugin-authors-jsm]]
  38. ==== Java Security permissions
  39. Some plugins may need additional security permissions. A plugin can include
  40. the optional `plugin-security.policy` file containing `grant` statements for
  41. additional permissions. Any additional permissions will be displayed to the user
  42. with a large warning, and they will have to confirm them when installing the
  43. plugin interactively. So if possible, it is best to avoid requesting any
  44. spurious permissions!
  45. If you are using the {es} Gradle build system, place this file in
  46. `src/main/plugin-metadata` and it will be applied during unit tests as well.
  47. The Java security model is stack-based, and additional
  48. permissions are granted to the jars in your plugin, so you have to
  49. write proper security code around operations requiring elevated privileges.
  50. You might add a check to prevent unprivileged code (such as scripts)
  51. from gaining escalated permissions. For example:
  52. [source,java]
  53. --------------------------------------------------
  54. // ES permission you should check before doPrivileged() blocks
  55. import org.elasticsearch.SpecialPermission;
  56. SecurityManager sm = System.getSecurityManager();
  57. if (sm != null) {
  58. // unprivileged code such as scripts do not have SpecialPermission
  59. sm.checkPermission(new SpecialPermission());
  60. }
  61. AccessController.doPrivileged(
  62. // sensitive operation
  63. );
  64. --------------------------------------------------
  65. Check https://www.oracle.com/technetwork/java/seccodeguide-139067.html[Secure Coding Guidelines for Java SE]
  66. for more information.
  67. [[plugin-descriptor-file-classic]]
  68. ==== The plugin descriptor file for classic plugins
  69. include::plugin-descriptor-file.asciidoc[]