How to Configure Opensearch Row Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up opensearch row level security by linking a search filter to a role. This document rule limits which records a logged-in user can read from an index. Many teams start by giving engineers full index read rights during early builds. Broad roles let any user read sensitive customer rows across shared indices. Teams then add document rules so each role only sees matching records. How opensearch row level security works In OpenSearch, this feature is often called document level security.

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 opensearch row level security by linking a search filter to a role. This document rule limits which records a logged-in user can read from an index. Many teams start by giving engineers full index read rights during early builds. Broad roles let any user read sensitive customer rows across shared indices. Teams then add document rules so each role only sees matching records.

How opensearch row level security works

In OpenSearch, this feature is often called document level security. It works inside the built-in security plugin at query time. First, an admin creates a role inside the cluster security settings. Next, the admin picks an index pattern that the role can read. Then, the admin attaches a query filter to that role definition.

This filter acts like a permanent search rule for that specific role. When a user logs in, OpenSearch checks their assigned roles first. If the user runs a search, the cluster merges their query with the role filter. The user only gets back documents that match both queries at once. Other rows in the same index stay hidden from the search response.

Teams can also use user attributes inside these role filters. For example, an identity provider can send a department name during login. The role filter then checks that attribute against a field in each document. This setup lets one role serve many teams without making dozens of separate roles. Admins manage one dynamic rule instead of updating rules for every new hire.

What native document filters solve and what they miss

Native document rules work well when every user has a unique cluster login. They let multiple teams share one large index without reading each other's rows. Support staff can view regional tickets while billing staff view payment logs. You do not need to duplicate data into separate indices for each team.

Still, native filters only check who logs in at the cluster level. Many engineering teams use shared service accounts for backend apps or debugging tools. When five engineers share one admin role, native filters treat them as one person. You cannot tell which engineer ran a heavy query or exported customer rows.

Row-Level Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static role filters also do not inspect what individual queries do in flight. A user with read rights on a document sees every field inside that document. If that record holds emails, phone numbers, or card numbers, the raw values return. You must add separate field rules for every index to hide those columns. Managing both row rules and field rules across hundreds of indices gets hard fast. One mistake in a role filter can expose private rows to the wrong group.

Best practices for managing document rules at scale

Keep your role filters simple so cluster search speed stays fast. Complex filters with many wildcards slow down every search that hits the index. Test each new role with a non-admin account before you give it to users. Check that aggregation queries also follow the document boundaries you set up.

Avoid mixing permissive and strict document rules on the same user account. When a user has two roles on one index, OpenSearch combines the filters. This union can let a user read more rows than you planned. Map each user to a clear set of roles with clear boundaries. Review your role mappings every quarter to remove old accounts and unused index rules.

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 opensearch row level security work on write operations?

No, native document rules mainly filter read and search requests on an index. If a role has write permissions, the user could still overwrite hidden documents. Give document-filtered roles read-only rights to keep your index data safe.

What happens when a user has two roles with different filters?

OpenSearch combines the document filters from both roles using an OR condition. The user can read any document that matches either role rule. Keep sensitive roles separate so users do not gain extra read rights by mistake.

Can document filters hide sensitive fields inside a matching row?

No, a document filter returns the entire record if it matches the rule. To hide specific fields like national IDs or emails, you need field level masking. Many teams combine row filters with field rules to protect private data.

The query runs. The emails stay hidden.