Elasticsearch Securing a search engine while maintaining usability
Alexander Reelsen @spinscale alex@elastic.co
Slide 2
Elasticsearch in 10 seconds Search Engine (FTS, Analytics, Geo), real-time Distributed, scalable, highly available, resilient Interface: HTTP & JSON Centrepiece of the Elastic Stack (Kibana, Logstash, Beats, APM, ML, App Search, Enterprise Search) Uneducated conservative guess: Tens of thousands of clusters worldwide, hundreds of thousands of instances
Slide 3
Agenda Security: Feature or non-functional requirement? Security Manager Production Mode vs. Development Mode Plugins Scripting language: Painless
Slide 4
Security Feature or non-functional requirement?
Slide 5
Software has to be secure! O RLY? Defensive programming Do not persist specific data (PCI DSS) Not exploitable (pro tip: not gonna happen) No unintended resource access (directory traversal) Least privilege principle Reduced impact surface (DoS)
https://www.theregister.co.uk/2017/03/26/miele_joins_internetofst_hall_of_shame/
Security as a non-functional requirement
Slide 6
The project management triangle Time
Budget
Scope
Slide 7
The security triangle Security
Functionality
Ease-of-use
Slide 8
The security triangle Security
Do not believe in triangles Functionality
Ease-of-use
Slide 9
Security as a feature Authentication Authorization (LDAP, users, PKI) TLS transport encryption Audit logging SSO/SAML/Kerberos
Slide 10
Security or safety or resiliency? Integrity checks Preventing OOMEs Prevent deep pagination Do not expose credentials in cluster state/REST APISs Stop writing data before running out of disk space Unable to call System.exit
Slide 11
„[T]HERE ARE KNOWN KNOWNS; THERE ARE THINGS WE KNOW WE KNOW. WE ALSO KNOW THERE ARE KNOWN UNKNOWNS; THAT IS TO SAY WE KNOW THERE ARE SOME THINGS WE DO NOT KNOW. BUT THERE ARE ALSO UNKNOWN UNKNOWNS – THERE ARE THINGS WE DO NOT KNOW WE DON’T KNOW.“
Donald Rumsfeld, former secretary of defense, IT Security Expert
Slide 12
„[T]HERE ARE KNOWN KNOWNS; THERE ARE THINGS WE KNOW WE KNOW. WE ALSO KNOW THERE ARE KNOWN UNKNOWNS; THAT IS TO SAY WE KNOW THERE ARE SOME THINGS WE DO NOT KNOW. BUT THERE ARE ALSO UNKNOWN UNKNOWNS – THERE ARE THINGS WE DO NOT KNOW WE DON’T KNOW.“
Donald Rumsfeld, former secretary of defense, IT Security Expert
Slide 13
„[T]HERE ARE KNOWN KNOWNS; THERE ARE THINGS WE KNOW WE KNOW. WE ALSO KNOW THERE ARE KNOWN UNKNOWNS; THAT IS TO SAY WE KNOW THERE ARE SOME THINGS WE DO NOT KNOW. BUT THERE ARE ALSO UNKNOWN UNKNOWNS – THERE ARE THINGS WE DO NOT KNOW WE DON’T KNOW.“
Donald Rumsfeld, former secretary of defense, IT Security Expert
Slide 14
„[T]HERE ARE KNOWN KNOWNS; THERE ARE THINGS WE KNOW WE KNOW. WE ALSO KNOW THERE ARE KNOWN UNKNOWNS; THAT IS TO SAY WE KNOW THERE ARE SOME THINGS WE DO NOT KNOW. BUT THERE ARE ALSO UNKNOWN UNKNOWNS – THERE ARE THINGS WE DO NOT KNOW WE DON’T KNOW.“
Donald Rumsfeld, former secretary of defense, IT Security Expert
Slide 15
Security Manager Have you ever called System.setSecurityManager()?
Slide 16
Introduction Sandbox your java application Prevent certain calls by your application Policy file grants permissions FilePermission (read, write) SocketPermission (connect, listen, accept) URLPermission, PropertyPermission, …
Drawbacks Hardcoded policies before startup DNS lookups are cached forever by default Forces you to think about dependencies! Many libraries are not even tested with the security manager, unknown code paths may be executed No OOM protection! No stack overflow protection! Granularity No protection against java agents
Slide 22
Production mode vs Development mode Annoying you now instead of devastating you later
Slide 23
Is your dev setup equivalent to production? Development environments are rarely setup like production ones How to ensure certain preconditions in production but not for development? What is a good indicator?
Slide 24
Mode check
Slide 25
Bootstrap checks
Slide 26
Reducing impact Bad things have less bad results
Slide 27
Reducing impact Least privilege principle Do not run as root No chance of forking a process Do not expose sensitive settings Security Manager
Slide 28
Do not run as root
Slide 29
Seccomp - prevent process forks Security manager could fail Elasticsearch should still not be able to fork processes One way transition to tell the operating system to deny execve, fork, vfork, execveat system calls Works on Linux, Windows, Solaris, BSD, osx
Slide 30
Mark sensitive settings
Slide 31
Register all your settings
Slide 32
Security Manager in Elasticsearch Initialization required before starting security manager Elasticsearch needs to read its configuration file first to find out about the file paths Native code needs to be executed first Solution: Start with empty security manager, bootstrap, apply secure security manager
Slide 33
Security Manager in Elasticsearch Special security manager is used Does not set exitVM permissions, only a few special classes are allowed to call Thread & ThreadGroup security is enforced Also SpecialPermission was added, a special marker permission to prevent elevation by scripts
Slide 34
Security Manager in Elasticsearch ESPolicy allows for loading from files plus dynamic configuration (from the ES configuration file) Bootstrap check for java.security.AllPermission
Slide 35
Plugins … remaining secure
Slide 36
Plugins in 60 seconds plugins are just zip files each plugin can have its own jars/dependencies each plugin is loaded with its own classloader each plugin can have its own security permissions ES core loads a bunch of code as modules (plugins that ship with Elasticsearch)
Slide 37
Sample permissions
Slide 38
Sample permissions
Slide 39
Sample permissions
Slide 40
Introducing Painless A scripting language for Elasticsearch
Slide 41
Scripting: Why and how? Expression evaluation without needing to write java extensions for Elasticsearch
Node ingest script processor Search queries (dynamic requests & fields) Aggregations (dynamic buckets) Templating (Mustache)
Slide 42
Scripting in Elasticsearch MVEL Groovy Expressions Painless
Slide 43
Painless - a secure scripting language Hard to take an existing programming language and make it secure, but remain fast Sandboxing Whitelisting over blacklisting, per method Opt-in to regular expressions Prevent endless loops Detect self references to prevent stack overflows
Slide 44
Summary Security is hard - let’s go shopping!
Slide 45
Summary Not using the Security Manager - what’s your excuse? Scripting is important, is your implementation secure? Use operating system features! If you allow for plugins, remain secure! If you remove features, have alternatives!
Slide 46
Thanks for listening! Questions?
Alexander Reelsen @spinscale alex@elastic.co
Pagination: Request
N
C
Find the first 10 results for Elasticsearch
Slide 50
Pagination: Request
N
C
Find the first 10 results for Elasticsearch
Slide 51
Pagination: Request
N
N
N
C
N
N
Find the first 10 results for Elasticsearch
Slide 52
Pagination: Query Phase
N
N
SortedPriorityQueue size = 50
N
C
N
N
Each node returns 10 results, create real top 10 out of 50
Slide 53
Pagination: Fetch phase
N
N
N
C
N
N
ask for the real top 10
Slide 54
Pagination: Query Phase
N
N
N
C
N
N
return real top 10
Slide 55
Pagination: Query
N
N
N
C
N
N
Find the 10 results starting at position 90
Slide 56
Pagination: Query Phase
N
N
SortedPriorityQueue size = 500
N
C
N
N
Each node returns 100 results, create real top 90-100 out of 500
Slide 57
Pagination: Query
N
N
N
C
N
N
Find the 10 results starting at position 99990
Slide 58
Pagination: Query Phase
N
N
SortedPriorityQueue size = 500000
N
C
N
N
Each node returns 100k results
Slide 59
Pagination: Query
1
N
N
C
N
100
Find the 10 results starting at position 99990 over 100 nodes
Slide 60
Pagination: Query
1
N
SortedPriorityQueue size = 10_000_000
N
C
N
100
Each node returns 100k results
Slide 61
Solution: search_after Do not use numerical positions Use keys where you stopped in the inverted index Let the client tell you what the last key was Just specify the last sort value from the last document returned as a starting point
Slide 62
Pagination: search_after
1
N
N
C
N
100
Find the 10 results starting at sort key name foo over 100 nodes
Slide 63
Pagination: search_after
N
N
SortedPriorityQueue size = 1000
N
C
N
N
Each node returns 10 results
Slide 64
Bonus replacing delete by query
Slide 65
delete_by_query removal/replace delete_by_query API was not safe API endpoint was removed extensive documentation was added what to do instead infrastructure for long running background tasks was added delete_by_query was reintroduced using above infra and doing the exact same thing as in the documentation data > convenience!
Slide 66
Thanks for listening! Questions?
Alexander Reelsen @spinscale alex@elastic.co