Skip to content

Commit b9ad986

Browse files
Adam Lockeelasticmachine
andauthored
[DOCS] Add ES security principles (#76850)
* [DOCS] Add ES security principles * Incorporating review feedback * More changes from review feedback * Fix cross-link to Painless guide * Clarify callout text * Add information about elasticsearch user * Minor wording edits * Consolidate Java Security Manager description, plus other edits * Clarify not running as root Co-authored-by: Elastic Machine <[email protected]>
1 parent ead0020 commit b9ad986

File tree

5 files changed

+100
-87
lines changed

5 files changed

+100
-87
lines changed

docs/reference/redirects.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
The following pages have moved or been deleted.
55

6+
[role="exclude",id="modules-scripting-other-layers"]
7+
=== Other security layers
8+
9+
Refer to <<modules-scripting-security>>.
10+
611
[role="exclude",id="grok-basics"]
712
=== Grok basics
813

Lines changed: 30 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,63 @@
11
[[modules-scripting-security]]
22
== Scripting and security
3+
Painless and {es} implement layers of security to build a defense in depth
4+
strategy for running scripts safely.
35

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.
109

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.
4615

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
6617
{wikipedia}/Seccomp[seccomp] in Linux,
6718
https://www.chromium.org/developers/design-documents/sandbox/osx-sandboxing-design[Seatbelt]
6819
in macOS, and
6920
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.
7123

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>>.
7629

7730
[[allowed-script-types-setting]]
7831
[discrete]
7932
=== Allowed script types setting
8033

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`.
8538

8639
IMPORTANT: If you use {kib}, set `script.allowed_types` to `both` or `inline`.
8740
Some {kib} features rely on inline scripts and do not function as expected
8841
if {es} does not allow inline scripts.
8942

90-
For example, to run `inline` scripts but not `stored` scripts, specify:
43+
For example, to run `inline` scripts but not `stored` scripts:
9144

9245
[source,yaml]
9346
----
94-
script.allowed_types: inline <1>
47+
script.allowed_types: inline
9548
----
96-
<1> This will allow only inline scripts to be executed but not stored scripts
97-
(or any other types).
98-
9949

10050
[[allowed-script-contexts-setting]]
10151
[discrete]
10252
=== Allowed script contexts setting
10353

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:
10859

10960
[source,yaml]
11061
----
111-
script.allowed_contexts: score, update <1>
62+
script.allowed_contexts: score, update
11263
----
113-
<1> This will allow only scoring and update scripts to be executed but not
114-
aggs or plugin scripts (or any other contexts).
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[[es-security-principles]]
2+
== {es} security principles
3+
Protecting your {es} cluster and the data it contains is of utmost importance.
4+
Implementing a defense in depth strategy provides multiple layers of security
5+
to help safeguard your system. The following principles provide a foundation
6+
for running {es} in a secure manner that helps to mitigate attacks on your
7+
system at multiple levels.
8+
9+
[discrete]
10+
[[security-run-with-security]]
11+
=== Run {es} with security enabled
12+
Never run an {es} cluster without security enabled. This principle cannot be
13+
overstated. Running {es} without security leaves your cluster exposed to anyone
14+
who can send network traffic to {es}, permitting these individuals to download,
15+
modify, or delete any data in your cluster.
16+
<<configuring-stack-security,Start the {stack} with security enabled>> or
17+
<<manually-configure-security,manually configure security>> to prevent
18+
unauthorized access to your clusters and ensure that internode communication
19+
is secure.
20+
21+
[discrete]
22+
[[security-not-root-user]]
23+
=== Run {es} with a dedicated non-root user
24+
Never try to run {es} as the `root` user, which would invalidate any defense
25+
strategy and permit a malicious user to do *anything* on your server. You must
26+
create a dedicated, unprivileged user to run {es}. By default, the `rpm`, `deb`,
27+
`docker`, and Windows packages of {es} contain an `elasticsearch` user with
28+
this scope.
29+
30+
[discrete]
31+
[[security-protect-cluster-traffic]]
32+
=== Protect {es} from public internet traffic
33+
Even with security enabled, never expose {es} to public internet traffic.
34+
Using an application to sanitize requests to {es} still poses risks, such as
35+
a malicious user writing <<search,`_search`>> requests that could overwhelm an
36+
{es} cluster and bring it down. Keep {es} as isolated as possible, preferably
37+
behind a firewall and a VPN. Any internet-facing applications should run
38+
pre-canned aggregations, or not run aggregations at all.
39+
40+
While you absolutely shouldn't expose {es} directly to the internet, you also
41+
shouldn't expose {es} directly to users. Instead, use an intermediary
42+
application to make requests on behalf of users. This implementation allows you
43+
to track user behaviors, such as can submit requests, and to which specific
44+
nodes in the cluster. For example, you can implement an application that accepts
45+
a search term from a user and funnels it through a
46+
<<query-dsl-simple-query-string-query,`simple_query_string`>> query.
47+
48+
[discrete]
49+
[[security-create-appropriate-users]]
50+
=== Implement role based access control
51+
<<defining-roles,Define roles>> for your users and
52+
<<security-privileges,assign appropriate privileges>> to ensure that users have
53+
access only to the resources that they need. This process determines whether the
54+
user behind an incoming request is allowed to run that request.

x-pack/docs/en/security/index.asciidoc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
[[secure-cluster]]
2-
= Secure the Elastic Stack
2+
= Secure the {stack}
33

44
[partintro]
55
--
66

7-
The Elastic Stack is comprised of many moving parts. There are the {es}
7+
The {stack} is comprised of many moving parts. There are the {es}
88
nodes that form the cluster, plus {ls} instances, {kib} instances, {beats}
9-
agents, and clients all communicating with the cluster.
9+
agents, and clients all communicating with the cluster. To keep your cluster
10+
safe, adhere to the <<es-security-principles,{es} security principles>>.
1011

11-
<<configuring-stack-security,Configure security for the Elastic Stack>> to
12+
<<configuring-stack-security,Start the {stack} with security enabled>> or
13+
<<manually-configure-security,manually configure security>> to
1214
secure {es} clusters and any clients that communicate with your clusters. You
1315
can password protect access to your data as well as enable more advanced
1416
security by configuring Transport Layer Security (TLS). This additional layer
1517
provides confidentiality and integrity protection to your communications with
16-
the Elastic Stack. You can also implement additional security measures, such as
18+
the {stack}. You can also implement additional security measures, such as
1719
role-based access control, IP filtering, and auditing.
1820

1921
Enabling security protects {es} clusters by:
@@ -71,7 +73,7 @@ of your data against tampering, while also providing _confidentiality_ by
7173
encrypting communications to, from, and within the cluster. For even greater
7274
protection, you can increase the <<ciphers,encryption strength>>.
7375

74-
See <<configuring-stack-security,Configure security for the Elastic Stack>>.
76+
See <<configuring-stack-security,Configure security for the {stack}>>.
7577

7678
[discrete]
7779
[[maintaining-audit-trail]]
@@ -90,6 +92,8 @@ See <<enable-audit-logging,Enable audit logging>>.
9092

9193
--
9294

95+
include::es-security-principles.asciidoc[]
96+
9397
include::configuring-stack-security.asciidoc[]
9498

9599
include::security-manual-configuration.asciidoc[]

x-pack/docs/en/security/security-manual-configuration.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[[manually-configure-security]]
12
== Manually configure security
23
++++
34
<titleabbrev>Configure security</titleabbrev>

0 commit comments

Comments
 (0)