security.asciidoc 4.6 KB

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