How to Configure Elasticsearch Row Level Security
You set up elasticsearch row level security by adding a query filter to a role. This native rule checks each document and returns only matching records to the user. Many teams start by giving apps and engineers broad read roles on whole indices. Over time, shared indices grow to hold private data from many customers or regions. When roles stay too broad, one query can expose records meant for another team. How elasticsearch row level security works in practice In a search cluster, a row is a
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up elasticsearch row level security by adding a query filter to a role. This native rule checks each document and returns only matching records to the user. Many teams start by giving apps and engineers broad read roles on whole indices. Over time, shared indices grow to hold private data from many customers or regions. When roles stay too broad, one query can expose records meant for another team.
How elasticsearch row level security works in practice
In a search cluster, a row is a single JSON document inside an index. The built-in security tool calls this feature document level security. You set it up by linking a search query to a specific user role. When a person or app logs in, the cluster checks their assigned role first. It then runs the role query in the background before returning any search results. Only documents that match the hidden role filter appear in the final response.
Teams often use user attributes to keep the number of roles small and tidy. Instead of making a hundred roles for a hundred tenants, you make one role. That single role reads a tag from the login profile, like a region code. The cluster injects that tag into the filter rule every time a query runs. This design works well for multi-tenant apps and regional support teams. Each group works inside the same index without reading records owned by other groups.
What native document filters solve and what they miss
Native document rules do a great job of splitting shared indices along clear boundaries. They stop a support agent in one region from pulling records for another region. Still, these rules only decide which documents a role can read after login. They do not inspect what an engineer or script does inside an allowed slice.
Even inside an allowed document, fields can hold emails, phone numbers, or card numbers. You can pair row rules with field rules, but managing both across clusters hurts. Every new index or schema change forces the security team to update role definitions. Also, native roles often rely on static keys or long-lived passwords stored on laptops. If a key leaks, the attacker gets every document that role allows.
Row-Level Security + Elasticsearch Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing query risks and sensitive fields across clusters
Static role filters also cannot stop risky queries before they hit the search engine. An engineer with valid read rights can still run a heavy wildcard search. That single request can spike memory use and slow down the whole cluster. Native role rules also do not ask a teammate to approve a rare query.
Teams also need to protect private data inside the documents a role can read. Masking rewrites matched fields in results, such as emails, phone numbers, and national IDs. This lets engineers debug production issues with real documents while keeping sensitive strings safe. Centralizing these checks keeps audit logs clean and removes static keys from user machines.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.
Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Does elasticsearch row level security work with write operations?
No, native document filters only apply to read and search requests on an index. If a role has write rights, the user can still overwrite filtered documents.
Do document filters slow down search queries?
Yes, complex filter rules add work to every search request and use extra cache. Simple term checks on indexed fields run much faster than deep nested queries.
How is row level security different from field level security?
Row rules hide whole JSON documents when they do not match a role query. Field rules keep the document in results but hide specific keys inside that document.
Related guides
In this post