creating-classic-plugins.asciidoc 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. Classic 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. * a plugin with a {es-repo}tree/main/plugins/examples/custom-processor[custom ingest processor]
  26. * adding {es-repo}tree/main/plugins/examples/rest-handler[custom rest endpoints]
  27. * adding a {es-repo}tree/main/plugins/examples/rescore[custom rescorer]
  28. * a script {es-repo}tree/main/plugins/examples/script-expert-scoring[implemented in Java]
  29. These examples provide the bare bones needed to get started. For more
  30. information about how to write a plugin, we recommend looking at the
  31. {es-repo}tree/main/plugins/[source code of existing plugins] for inspiration.
  32. [discrete]
  33. ==== Testing your plugin
  34. Use `bin/elasticsearch-plugin install file:///path/to/your/plugin`
  35. to install your plugin for testing. The Java plugin is auto-loaded only if it's in the
  36. `plugins/` directory.
  37. [discrete]
  38. [[plugin-authors-jsm]]
  39. ==== Java Security permissions
  40. Some plugins may need additional security permissions. A plugin can include
  41. the optional `plugin-security.policy` file containing `grant` statements for
  42. additional permissions. Any additional permissions will be displayed to the user
  43. with a large warning, and they will have to confirm them when installing the
  44. plugin interactively. So if possible, it is best to avoid requesting any
  45. spurious permissions!
  46. If you are using the {es} Gradle build system, place this file in
  47. `src/main/plugin-metadata` and it will be applied during unit tests as well.
  48. The Java security model is stack-based, and additional
  49. permissions are granted to the jars in your plugin, so you have to
  50. write proper security code around operations requiring elevated privileges.
  51. You might add a check to prevent unprivileged code (such as scripts)
  52. from gaining escalated permissions. For example:
  53. [source,java]
  54. --------------------------------------------------
  55. // ES permission you should check before doPrivileged() blocks
  56. import org.elasticsearch.SpecialPermission;
  57. SecurityManager sm = System.getSecurityManager();
  58. if (sm != null) {
  59. // unprivileged code such as scripts do not have SpecialPermission
  60. sm.checkPermission(new SpecialPermission());
  61. }
  62. AccessController.doPrivileged(
  63. // sensitive operation
  64. );
  65. --------------------------------------------------
  66. Check https://www.oracle.com/technetwork/java/seccodeguide-139067.html[Secure Coding Guidelines for Java SE]
  67. for more information.
  68. [[plugin-descriptor-file-classic]]
  69. ==== The plugin descriptor file for classic plugins
  70. include::plugin-descriptor-file.asciidoc[]