While Elasticsearch contributors make every effort to prevent scripts from running amok, security is something best done in layers because all software has bugs and it is important to minimize the risk of failure in any security layer. Find below rules of thumb for how to keep Elasticsearch from being a vulnerability.
Do not run as rootedit
First and foremost, never run Elasticsearch as the
root user as this would
allow any successful effort to circumvent the other security layers to do
anything on your server. Elasticsearch will refuse to start if it detects
that it is running as
root but this is so important that it is worth double
and triple checking.
Do not expose Elasticsearch directly to usersedit
Do not expose Elasticsearch directly to users, instead have an application
make requests on behalf of users. If this is not possible, have an application
to sanitize requests from users. If that is not possible then have some
mechanism to track which users did what. Understand that it is quite possible
to write a
_search that overwhelms Elasticsearch and brings down
the cluster. All such searches should be considered bugs and the Elasticsearch
contributors make an effort to prevent this but they are still possible.
Do not expose Elasticsearch directly to the Internetedit
Do not expose Elasticsearch to the Internet, instead have an application make requests on behalf of the Internet. Do not entertain the thought of having an application "sanitize" requests to Elasticsearch. Understand that it is possible for a sufficiently determined malicious user to write searches that overwhelm the Elasticsearch cluster and bring it down. For example:
* Users type text into a search box and the text is sent directly to a
Match Query, Match Phrase Query,
Simple Query String Query, or any of the Suggesters.
* Running a script with any of the above queries that was written as part of
the application development process.
* Running a script with
params provided by users.
* User actions makes documents with a fixed structure.
* Users can write arbitrary scripts, queries,
* User actions make documents with structure defined by users.
Do not weaken script security settingsedit
By default Elasticsearch will run inline, stored, and filesystem scripts for the builtin languages, namely the scripting language Painless, the template language Mustache, and the expression language Expressions. These ought to be safe to expose to trusted users and to your application servers because they have strong security sandboxes. The Elasticsearch committers do not support any non-sandboxed scripting languages and using any would be a poor choice because: 1. This drops a layer of security, leaving only Elasticsearch’s builtin security layers. 2. Non-sandboxed scripts have unchecked access to Elasticsearch’s internals and can cause all kinds of trouble if misused.
Other security layersedit
In addition to user privileges and script sandboxing Elasticsearch uses the Java Security Manager and native security tools as additional layers of security.
As part of its startup sequence Elasticsearch enables the Java Security Manager which limits the actions that can be taken by portions of the code. Painless uses this to limit the actions that generated Painless scripts can take, preventing them from being able to do things like write files and listen to sockets.
Below this we describe the security settings for scripts and how you can change from the defaults described above. You should be very, very careful when allowing more than the defaults. Any extra permissions weakens the total security of the Elasticsearch deployment.
Allowed script types settingedit
By default all script types are allowed to be executed. This can be modified using the
script.allowed_types. Only the types specified as part of the setting will be
allowed to be executed. To specify no types are allowed, set
Allowed script contexts settingedit
By default all script contexts are allowed to be executed. This can be modified using the
script.allowed_contexts. Only the contexts specified as part of the setting will
be allowed to be executed. To specify no contexts are allowed, set