@@ -9,31 +9,37 @@ security in a defense in depth strategy for scripting.
9
9
10
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
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
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
14
from doing things like writing files and listening to sockets.
15
15
16
16
{es} uses
17
17
{wikipedia}/Seccomp[seccomp] in Linux,
18
18
https://www.chromium.org/developers/design-documents/sandbox/osx-sandboxing-design[Seatbelt]
19
19
in macOS, and
20
20
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684147[ActiveProcessLimit]
21
- on Windows as additional security layers to prevent {es} from forking or
21
+ on Windows as additional security layers to prevent {es} from forking or
22
22
running other processes.
23
23
24
+ Finally, scripts used in
25
+ <<search-aggregations-metrics-scripted-metric-aggregation,scripted metrics aggregations>>
26
+ can be restricted to a defined list of scripts, or forbidden altogether.
27
+ This can prevent users from running particularly slow or resource intensive aggregation
28
+ queries.
29
+
24
30
You can modify the following script settings to restrict the type of scripts
25
- that are allowed to run, and control the available
31
+ that are allowed to run, and control the available
26
32
{painless}/painless-contexts.html[contexts] that scripts can run in. To
27
- implement additional layers in your defense in depth strategy, follow the
33
+ implement additional layers in your defense in depth strategy, follow the
28
34
<<es-security-principles,{es} security principles>>.
29
35
30
36
[[allowed-script-types-setting]]
31
37
[discrete]
32
38
=== Allowed script types setting
33
39
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
40
+ {es} supports two script types: `inline` and `stored`. By default, {es} is
41
+ configured to run both types of scripts. To limit what type of scripts are run,
42
+ set `script.allowed_types` to `inline` or `stored`. To prevent any scripts from
37
43
running, set `script.allowed_types` to `none`.
38
44
39
45
IMPORTANT: If you use {kib}, set `script.allowed_types` to both or just `inline`.
@@ -61,3 +67,48 @@ For example, to allow scripts to run only in `scoring` and `update` contexts:
61
67
----
62
68
script.allowed_contexts: score, update
63
69
----
70
+
71
+ [[allowed-script-in-aggs-settings]]
72
+ [discrete]
73
+ === Allowed scripts in scripted metrics aggregations
74
+
75
+ By default, all scripts are permitted in
76
+ <<search-aggregations-metrics-scripted-metric-aggregation,scripted metrics aggregations>>.
77
+ To restrict the set of allowed scripts, set
78
+ <<search-settings-only-allowed-scripts,`search.aggs.only_allowed_metric_scripts`>>
79
+ to `true` and provide the allowed scripts using
80
+ <<search-settings-allowed-inline-scripts,`search.aggs.allowed_inline_metric_scripts`>>
81
+ and/or
82
+ <<search-settings-allowed-stored-scripts,`search.aggs.allowed_stored_metric_scripts`>>.
83
+
84
+ To disallow certain script types, omit the corresponding script list
85
+ (`search.aggs.allowed_inline_metric_scripts` or
86
+ `search.aggs.allowed_stored_metric_scripts`) or set it to an empty array.
87
+ When both script lists are not empty, the given stored scripts and the given inline scripts
88
+ will be allowed.
89
+
90
+ The following example permits only 4 specific stored scripts to be used, and no inline scripts:
91
+
92
+ [source,yaml]
93
+ ----
94
+ search.aggs.only_allowed_metric_scripts: true
95
+ search.aggs.allowed_inline_metric_scripts: []
96
+ search.aggs.allowed_stored_metric_scripts:
97
+ - script_id_1
98
+ - script_id_2
99
+ - script_id_3
100
+ - script_id_4
101
+ ----
102
+
103
+ Conversely, the next example allows specific inline scripts but no stored scripts:
104
+
105
+ [source,yaml]
106
+ ----
107
+ search.aggs.only_allowed_metric_scripts: true
108
+ search.aggs.allowed_inline_metric_scripts:
109
+ - 'state.transactions = []'
110
+ - 'state.transactions.add(doc.some_field.value)'
111
+ - 'long sum = 0; for (t in state.transactions) { sum += t } return sum'
112
+ - 'long sum = 0; for (a in states) { sum += a } return sum'
113
+ search.aggs.allowed_stored_metric_scripts: []
114
+ ----
0 commit comments