How to Configure Vitess Row Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up vitess row level security by combining shard routing rules, SQL views, and tablet access controls. Since the MySQL engine underneath lacks native row policies, teams enforce row limits through query rules and scoped views. Many teams start by giving developers and apps broad read roles across keyspaces. When roles stay too wide, one bad query can read or change rows meant for other tenants. How vitess row level security works in practice Vitess sits in front of MySQL shards and rou

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 vitess row level security by combining shard routing rules, SQL views, and tablet access controls. Since the MySQL engine underneath lacks native row policies, teams enforce row limits through query rules and scoped views. Many teams start by giving developers and apps broad read roles across keyspaces. When roles stay too wide, one bad query can read or change rows meant for other tenants.

How vitess row level security works in practice

Vitess sits in front of MySQL shards and routes queries through stateless query routers and tablet servers. To build vitess row level security, admins rely on three built-in mechanisms working together. First, you route tenant queries using primary vindexes, which map specific row keys to dedicated shards. If a tenant lives on one shard, you can scope a user account to that keyspace shard.

Second, tablet servers include a table ACL system and a query rules engine. Table ACLs check the caller username and allow or reject read, write, or admin tasks per table. Query rules inspect incoming SQL patterns, bind variables, or user names before the tablet runs the statement. You can write a query rule that blocks any statement missing a required tenant filter column.

Third, teams create SQL views inside the underlying MySQL instances for human analysts and support staff. The view filters rows based on the current database user or a joined permission table. You then block direct access to the base table and grant read access only on the filtered view. Together, shard routing, query rules, and SQL views mimic row policies across a distributed database cluster.

How to set up tablet rules and filtered views

Start by mapping out which users and apps need access to specific tenant or regional rows. Define your vschema so every multi-tenant table shares a clear sharding key, such as a tenant ID. Next, configure query rules on the tablet server to reject broad queries that scan across all rows. A strict rule forces every select or update statement to include your sharding key in the filter.

After locking down query shapes, set up table ACL groups for readers, writers, and schema admins. Map each database user to the lowest role needed for their daily work. For staff who run ad-hoc queries, build SQL views that filter out restricted rows by default. Grant those users select rights on the views while revoking access to the raw underlying tables.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native controls solve and what they leave open

Native tablet rules and views stop accidental full-table scans and keep routine app queries inside their shard. They also prevent a basic user account from reading tables outside its assigned group. Still, maintaining custom query rules and views across dozens of shards creates heavy upkeep for platform teams. Every schema change requires you to update view definitions and test regex rules across all tablets.

More importantly, static database roles only check who logs in at the start of a session. When engineers share a common fixing account, every person inherits the same row visibility and write power. Native rules also do not mask sensitive fields like emails, phone numbers, card numbers, or national IDs. If a row matches the view filter, the database returns all columns in plain text to the client. You still need a way to inspect individual queries in flight and rewrite sensitive fields in results.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Does Vitess support native Postgres-style row level security policies?

No, because it runs on MySQL, which lacks native row policy commands on base tables. You must combine SQL views, tablet query rules, and shard routing to filter rows per user.

Can tablet query rules block queries that miss a tenant filter?

Yes, tablet query rules can match statement patterns and reject queries that omit required bind variables. This stops apps and users from running broad reads or updates across all tenants.

How do you protect sensitive columns inside allowed rows?

SQL views can hide entire columns, or you can apply data masking in flight. Masking rewrites matched fields like emails or card numbers in results before they reach the user.

Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.

The query runs. The emails stay hidden.