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