How to Configure Supabase Row Level Security
You set up supabase row level security by turning it on for each table. Next, you write rules that check the user role before returning rows. Many teams start by turning on table rules for their front-end app traffic. They map rules to built-in roles like the anon role or authenticated role. Problems start when engineers log in with admin accounts to debug live issues. Overly broad roles bypass row checks and expose every record in the table. How supabase row level security works with roles P
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 supabase row level security by turning it on for each table. Next, you write rules that check the user role before returning rows. Many teams start by turning on table rules for their front-end app traffic. They map rules to built-in roles like the anon role or authenticated role. Problems start when engineers log in with admin accounts to debug live issues. Overly broad roles bypass row checks and expose every record in the table.
How supabase row level security works with roles
Postgres uses table policies to filter which rows a given role can read. It also filters which rows a role can add, change, or delete. Every new project comes with a set of built-in roles for requests. For example, the anon role handles requests from users who have not logged in. Once a user logs in, the database switches to the authenticated role. Table policies check the current role and match it against row values.
If no rule matches the request, the database returns zero rows by default. This setup keeps client apps from reading data that belongs to other users. Still, this control depends on which role runs the query at that moment. Every project also includes a default postgres role with full admin privileges. Supabase does not give out true superuser access to prevent destructive database actions. Still, the default postgres role has admin rights across the whole project. Queries you run in the web dashboard execute as this admin postgres role. Because admin roles bypass row rules, dashboard queries see every row right away by default.
Where native row rules leave gaps for teams
Row rules work well when client apps talk directly to the database API. They stop one app user from reading another user's private profile or orders. Yet engineering teams still need direct database sessions to fix bugs and check data. When developers use the shared postgres password, they log in with admin privileges. Supabase warns teams never to share this main password with untrusted third-party services. Instead, the docs suggest making a new database user for each separate service.
Even with separate users, native row rules only check who logs in. They do not inspect what individual queries do while a session is active. If a support engineer needs to read a table, they see all columns. Native row policies filter whole rows, not sensitive text inside a allowed row. A user who passes the row check still gets raw emails and phone numbers. Also, a bad update statement from an authorized role can still change many rows. Row rules alone cannot ask a teammate for approval before running a risky query. They also cannot rewrite sensitive fields like card numbers or national IDs in results.
Row-Level Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Steps to keep direct database sessions safe
First, turn on row level security on every public table in your project. Write clear policies for the anon and authenticated roles based on user IDs. Second, stop sharing the default postgres role password across your engineering team. Create separate database roles for each backend service and team function you run. Grant each custom role only the exact table permissions it needs to work.
Third, avoid using the web dashboard for routine data checks on live tables. Dashboard queries run as the postgres admin role and skip your row policies. Finally, put controls in front of human and script sessions to watch live queries. Checking statements in flight lets you block broad deletes and mask sensitive fields. When masking rewrites matched fields in results, engineers can debug safely without raw PII.
Run guardrails and masking on the Postgres connection
Role grants and firewall rules are needed setup. Setup alone cannot check single SQL statements or mask sensitive rows in a response. By design, hoop.dev sits inline in the Postgres protocol beside Postgres, RDS, or Aurora as a sidecar for your Postgres. On every production query from an engineer or AI agent, hoop.dev decides whether to pass, mask, block, or hold it for approval.
First, hoop.dev guardrails refuse disallowed drops or deletes before they run, and risky statements can pause for human review. Next, hoop.dev data masking rewrites sensitive fields in returned rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and logs every statement and verdict per resource. Check out the project on GitHub.
Frequently asked questions
Does the default postgres role follow row level security rules?
No, the default postgres role has admin privileges and bypasses row level security. Any query you run in the project dashboard also runs as this postgres role.
What happens when I turn on row level security without any policies?
Once you turn it on, the table blocks all access by default. No regular role can read or write rows until you add a matching policy.
Can row level security mask emails or phone numbers inside a row?
No, row level security only decides if a role can access the entire row. To rewrite emails, phone numbers, or card numbers in results, you need query-level masking.
Related guides
In this post