How to Configure MariaDB Row Level Security
You set up mariadb row level security by building filtered views over your base tables. These views check the current user or session variable before returning any rows. Database teams use this setup to keep tenant data separate inside shared tables. When roles are too broad, one query can expose every row in the database by default. Broad table rights also let developers read sensitive columns like emails and card numbers. How to set up mariadb row level security with views The database engi
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 mariadb row level security by building filtered views over your base tables. These views check the current user or session variable before returning any rows. Database teams use this setup to keep tenant data separate inside shared tables. When roles are too broad, one query can expose every row in the database by default. Broad table rights also let developers read sensitive columns like emails and card numbers.
How to set up mariadb row level security with views
The database engine does not have a single switch for row policies. Instead, you build a layer of views on top of your raw tables. First, you add a column to the base table to store an owner value. This value can be a database username, a role name, or a tenant identifier. Next, you revoke direct read and write permissions on the underlying base table. Users must never query the raw table on their own.
Then, you create a view that filters rows by matching that owner column. The view checks the active session user or a custom session variable during execution. You also enable the check option on the view to govern write operations. This setting stops users from inserting or updating rows that belong to other groups. Finally, you grant your team or app permissions to query only the secure view.
How session variables handle multi-tenant app traffic
Most modern web apps do not create a separate database user for every customer. Instead, the app uses a single shared database account to run all queries. To filter rows in this setup, the app sets a session variable after connecting. That variable holds the active tenant or customer ID for the current web request. The secure view reads this session variable and returns only the matching rows.
This pattern works well for standard app traffic when the code runs as expected. Still, any person or script using that shared account can change the session variable. If an engineer logs in with the app role, they can reset the variable. They can also query multiple tenants if they know the other tenant IDs. You must manage how human users and support scripts run queries against production 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 view filters solve and what they leave open
Filtered views work well when every person or service has a distinct database role. They keep standard business reports clean and stop basic cross-tenant reads inside the app. A support analyst with a restricted role will only pull rows for their region. This native setup handles basic data separation without changing how you store tables.
Still, view filters and database roles only check who logs in at the start. They do not inspect what individual statements do in flight during a live session. An engineer with admin rights can still bypass the view and read the base table. If a developer runs a broad select on a permitted view, every column returns. Native view filters do not mask emails, phone numbers, or national IDs in results. Maintaining hundreds of custom views across schema changes also adds heavy manual work for teams.
Add wire guardrails and masking beside MySQL
Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev sits inline in the wire protocol beside the database as a sidecar for your MySQL. On every production query an agent or engineer sends, hoop.dev decides to pass, mask, block, or escalate it for human review.
With hoop.dev MySQL support, guardrails refuse bad queries before they run or hold risky calls for approval, while data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.
Frequently asked questions
Does the database engine support native row policy rules like PostgreSQL?
No, it does not include a built-in policy command for tables. You achieve the same result by combining restricted base tables with filtered SQL views.
How do you stop users from inserting rows for another tenant?
You enable the check constraint option when you define the filtered view. The database then rejects any insert or update that fails the view filter condition.
Can database admins bypass view-based row filters?
Yes, accounts with full table rights can query the base tables directly. You need query inspection and field masking in flight to control privileged human sessions.
Related guides
In this post