Skip to content

Commit 495bee7

Browse files
alex-spiesalbertzaharovits
authored andcommitted
Aggs: Scripted metric allow list docs (#109635)
* Document new settings * Mention agg allow list in scripting security doc
1 parent 03444d5 commit 495bee7

File tree

2 files changed

+92
-8
lines changed

2 files changed

+92
-8
lines changed

docs/reference/modules/indices/search-settings.asciidoc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ a single response. Defaults to 65,536.
3333
+
3434
Requests that attempt to return more than this limit will return an error.
3535

36+
[[search-settings-only-allowed-scripts]]
37+
`search.aggs.only_allowed_metric_scripts`::
38+
(<<cluster-update-settings,Dynamic>>, boolean)
39+
Configures whether only explicitly allowed scripts can be used in
40+
<<search-aggregations-metrics-scripted-metric-aggregation,scripted metrics aggregations>>.
41+
Defaults to `false`.
42+
+
43+
Requests using scripts not contained in either
44+
<<search-settings-allowed-inline-scripts,`search.aggs.allowed_inline_metric_scripts`>>
45+
or
46+
<<search-settings-allowed-stored-scripts,`search.aggs.allowed_stored_metric_scripts`>>
47+
will return an error.
48+
49+
[[search-settings-allowed-inline-scripts]]
50+
`search.aggs.allowed_inline_metric_scripts`::
51+
(<<cluster-update-settings,Dynamic>>, list of strings)
52+
List of inline scripts that can be used in scripted metrics aggregations when
53+
<<search-settings-only-allowed-scripts,`search.aggs.only_allowed_metric_scripts`>>
54+
is set to `true`.
55+
Defaults to an empty list.
56+
+
57+
Requests using other inline scripts will return an error.
58+
59+
[[search-settings-allowed-stored-scripts]]
60+
`search.aggs.allowed_stored_metric_scripts`::
61+
(<<cluster-update-settings,Dynamic>>, list of strings)
62+
List of ids of stored scripts that can be used in scripted metrics aggregations when
63+
<<search-settings-only-allowed-scripts,`search.aggs.only_allowed_metric_scripts`>>
64+
is set to `true`.
65+
Defaults to an empty list.
66+
+
67+
Requests using other stored scripts will return an error.
68+
3669
[[indices-query-bool-max-nested-depth]]
3770
`indices.query.bool.max_nested_depth`::
3871
(<<static-cluster-setting,Static>>, integer) Maximum nested depth of queries. Defaults to `30`.

docs/reference/scripting/security.asciidoc

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,37 @@ security in a defense in depth strategy for scripting.
99

1010
The second layer of security is the https://www.oracle.com/java/technologies/javase/seccodeguide.html[Java Security Manager]. As part of its startup
1111
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
1414
from doing things like writing files and listening to sockets.
1515

1616
{es} uses
1717
{wikipedia}/Seccomp[seccomp] in Linux,
1818
https://www.chromium.org/developers/design-documents/sandbox/osx-sandboxing-design[Seatbelt]
1919
in macOS, and
2020
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
2222
running other processes.
2323

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+
2430
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
2632
{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
2834
<<es-security-principles,{es} security principles>>.
2935

3036
[[allowed-script-types-setting]]
3137
[discrete]
3238
=== Allowed script types setting
3339

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
3743
running, set `script.allowed_types` to `none`.
3844

3945
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:
6167
----
6268
script.allowed_contexts: score, update
6369
----
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

Comments
 (0)