|
1 | 1 | [[modules-scripting-security]] |
2 | 2 | == Scripting and security |
| 3 | +Painless and {es} implement layers of security to build a defense in depth |
| 4 | +strategy for running scripts safely. |
3 | 5 |
|
4 | | -While Elasticsearch contributors make every effort to prevent scripts from |
5 | | -running amok, security is something best done in |
6 | | -{wikipedia}/Defense_in_depth_(computing)[layers] because |
7 | | -all software has bugs and it is important to minimize the risk of failure in |
8 | | -any security layer. Find below rules of thumb for how to keep Elasticsearch |
9 | | -from being a vulnerability. |
| 6 | +Painless uses a fine-grained allowlist. Anything that is not part of the |
| 7 | +allowlist results in a compilation error. This capability is the first layer of |
| 8 | +security in a defense in depth strategy for scripting. |
10 | 9 |
|
11 | | -[discrete] |
12 | | -=== Do not run as root |
13 | | -First and foremost, never run Elasticsearch as the `root` user as this would |
14 | | -allow any successful effort to circumvent the other security layers to do |
15 | | -*anything* on your server. Elasticsearch will refuse to start if it detects |
16 | | -that it is running as `root` but this is so important that it is worth double |
17 | | -and triple checking. |
18 | | - |
19 | | -[discrete] |
20 | | -=== Do not expose Elasticsearch directly to users |
21 | | -Do not expose Elasticsearch directly to users, instead have an application |
22 | | -make requests on behalf of users. If this is not possible, have an application |
23 | | -to sanitize requests from users. If *that* is not possible then have some |
24 | | -mechanism to track which users did what. Understand that it is quite possible |
25 | | -to write a <<search, `_search`>> that overwhelms Elasticsearch and brings down |
26 | | -the cluster. All such searches should be considered bugs and the Elasticsearch |
27 | | -contributors make an effort to prevent this but they are still possible. |
28 | | - |
29 | | -[discrete] |
30 | | -=== Do not expose Elasticsearch directly to the Internet |
31 | | -Do not expose Elasticsearch to the Internet, instead have an application |
32 | | -make requests on behalf of the Internet. Do not entertain the thought of having |
33 | | -an application "sanitize" requests to Elasticsearch. Understand that it is |
34 | | -possible for a sufficiently determined malicious user to write searches that |
35 | | -overwhelm the Elasticsearch cluster and bring it down. For example: |
36 | | - |
37 | | -Good: |
38 | | - |
39 | | -* Users type text into a search box and the text is sent directly to a |
40 | | -<<query-dsl-match-query>>, <<query-dsl-match-query-phrase>>, |
41 | | -<<query-dsl-simple-query-string-query>>, or any of the <<search-suggesters>>. |
42 | | -* Running a script with any of the above queries that was written as part of |
43 | | -the application development process. |
44 | | -* Running a script with `params` provided by users. |
45 | | -* User actions makes documents with a fixed structure. |
| 10 | +The second layer of security is the https://www.oracle.com/java/technologies/javase/seccodeguide.html[Java Security Manager]. As part of its startup |
| 11 | +sequence, {es} enables the Java Security Manager to limit the actions that |
| 12 | +portions of the code can take. <<modules-scripting-painless,Painless>> uses |
| 13 | +the Java Security Manager as an additional layer of defense to prevent scripts |
| 14 | +from doing things like writing files and listening to sockets. |
46 | 15 |
|
47 | | -Bad: |
48 | | - |
49 | | -* Users can write arbitrary scripts, queries, `_search` requests. |
50 | | -* User actions make documents with structure defined by users. |
51 | | - |
52 | | -[discrete] |
53 | | -[[modules-scripting-other-layers]] |
54 | | -=== Other security layers |
55 | | -In addition to user privileges and script sandboxing Elasticsearch uses the |
56 | | -https://www.oracle.com/java/technologies/javase/seccodeguide.html[Java Security Manager] |
57 | | -and native security tools as additional layers of security. |
58 | | - |
59 | | -As part of its startup sequence Elasticsearch enables the Java Security Manager |
60 | | -which limits the actions that can be taken by portions of the code. Painless |
61 | | -uses this to limit the actions that generated Painless scripts can take, |
62 | | -preventing them from being able to do things like write files and listen to |
63 | | -sockets. |
64 | | - |
65 | | -Elasticsearch uses |
| 16 | +{es} uses |
66 | 17 | {wikipedia}/Seccomp[seccomp] in Linux, |
67 | 18 | https://www.chromium.org/developers/design-documents/sandbox/osx-sandboxing-design[Seatbelt] |
68 | 19 | in macOS, and |
69 | 20 | https://msdn.microsoft.com/en-us/library/windows/desktop/ms684147[ActiveProcessLimit] |
70 | | -on Windows to prevent Elasticsearch from forking or executing other processes. |
| 21 | +on Windows as additional security layers to prevent {es} from forking or |
| 22 | +running other processes. |
71 | 23 |
|
72 | | -Below this we describe the security settings for scripts and how you can |
73 | | -change from the defaults described above. You should be very, very careful |
74 | | -when allowing more than the defaults. Any extra permissions weakens the total |
75 | | -security of the Elasticsearch deployment. |
| 24 | +You can modify the following script settings to restrict the type of scripts |
| 25 | +that are allowed to run, and control the available |
| 26 | +{painless}/painless-contexts.html[contexts] that scripts can run in. To |
| 27 | +implement additional layers in your defense in depth strategy, follow the |
| 28 | +<<es-security-principles,{es} security principles>>. |
76 | 29 |
|
77 | 30 | [[allowed-script-types-setting]] |
78 | 31 | [discrete] |
79 | 32 | === Allowed script types setting |
80 | 33 |
|
81 | | -Elasticsearch supports two script types: `inline` and `stored` (<<modules-scripting-using>>). |
82 | | -By default, {es} is configured to run both types of scripts. |
83 | | -To limit what type of scripts are run, set `script.allowed_types` to `inline` or `stored`. |
84 | | -To prevent any scripts from running, set `script.allowed_types` to `none`. |
| 34 | +{es} supports two script types: `inline` and `stored`. By default, {es} is |
| 35 | +configured to run both types of scripts. To limit what type of scripts are run, |
| 36 | +set `script.allowed_types` to `inline` or `stored`. To prevent any scripts from |
| 37 | +running, set `script.allowed_types` to `none`. |
85 | 38 |
|
86 | 39 | IMPORTANT: If you use {kib}, set `script.allowed_types` to `both` or `inline`. |
87 | 40 | Some {kib} features rely on inline scripts and do not function as expected |
88 | 41 | if {es} does not allow inline scripts. |
89 | 42 |
|
90 | | -For example, to run `inline` scripts but not `stored` scripts, specify: |
| 43 | +For example, to run `inline` scripts but not `stored` scripts: |
91 | 44 |
|
92 | 45 | [source,yaml] |
93 | 46 | ---- |
94 | | -script.allowed_types: inline <1> |
| 47 | +script.allowed_types: inline |
95 | 48 | ---- |
96 | | -<1> This will allow only inline scripts to be executed but not stored scripts |
97 | | -(or any other types). |
98 | | - |
99 | 49 |
|
100 | 50 | [[allowed-script-contexts-setting]] |
101 | 51 | [discrete] |
102 | 52 | === Allowed script contexts setting |
103 | 53 |
|
104 | | -By default all script contexts are allowed to be executed. This can be modified using the |
105 | | -setting `script.allowed_contexts`. Only the contexts specified as part of the setting will |
106 | | -be allowed to be executed. To specify no contexts are allowed, set `script.allowed_contexts` |
107 | | -to be `none`. |
| 54 | +By default, all script contexts are permitted. Use the `script.allowed_contexts` |
| 55 | +setting to specify the contexts that are allowed. To specify that no contexts |
| 56 | +are allowed, set `script.allowed_contexts` to `none`. |
| 57 | + |
| 58 | +For example, to allow scripts to run only in `scoring` and `update` contexts: |
108 | 59 |
|
109 | 60 | [source,yaml] |
110 | 61 | ---- |
111 | | -script.allowed_contexts: score, update <1> |
| 62 | +script.allowed_contexts: score, update |
112 | 63 | ---- |
113 | | -<1> This will allow only scoring and update scripts to be executed but not |
114 | | -aggs or plugin scripts (or any other contexts). |
0 commit comments