How to Configure Mastra Supabase Read Only Access
You set up mastra supabase read only access by creating a dedicated Postgres user. You grant that user select permissions on only the tables your AI agent needs. Many teams start by giving Mastra the default admin password from project setup. That broad role lets an agent run destructive write queries or read private tables. A dedicated read-only user keeps your database safe from bad agent updates. How mastra supabase read only access works in Postgres Every Supabase project starts with a de
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 mastra supabase read only access by creating a dedicated Postgres user. You grant that user select permissions on only the tables your AI agent needs. Many teams start by giving Mastra the default admin password from project setup. That broad role lets an agent run destructive write queries or read private tables. A dedicated read-only user keeps your database safe from bad agent updates.
How mastra supabase read only access works in Postgres
Every Supabase project starts with a default postgres role. This default role has admin privileges across the database. Supabase does not give out full superuser rights because those allow destructive actions. Still, the password you set at project creation belongs to this admin role. Supabase warns teams never to share this main password with an external service. Instead, you should make a new database user for each service you connect.
When you build an AI agent in Mastra, that agent needs database credentials. You can run standard Postgres commands in the Supabase dashboard to make a role. Queries you run in the dashboard execute as the default postgres admin role. Those dashboard queries also carry a comment tag showing they came from the dashboard. With those admin rights, you create a fresh login role for your Mastra workflow.
Next, you give the new user usage rights on your target database schema. Then you grant select rights on the specific tables the Mastra agent should read. You can also set default privileges so future tables stay readable or locked down. Finally, you pass this new user string to your Mastra database setup. Now the database engine rejects any write, update, or delete commands from the agent.
Why native roles are not enough for AI agents
A read-only Postgres role solves the problem of accidental data changes or deletions. It decides who can log in and which tables they can read. Still, native database roles do not inspect what individual queries do in flight. Once Mastra logs in, it can read every row and column in allowed tables.
Customer tables often mix safe product data with sensitive personal details. If a table holds emails, phone numbers, or card numbers, the agent reads them. Native table grants cannot rewrite those fields on the fly before results return. You would have to maintain complex views for every single agent task.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static database passwords also create secret management work for your engineering team. You have to store the read-only password in your Mastra app environment. If that key leaks, anyone with the string can query your database directly. Standard role setups also lack query-level approval flows when an agent needs extra data. Teams need a way to inspect queries and mask fields in real time.
Best practices for scoping agent database roles
Start by listing the exact tables your Mastra tools need to answer prompts. Never grant select rights across the entire public schema by default. Keep internal auth tables, billing records, and secret keys off the allowed list. If an agent only answers support questions, grant access to ticket tables only.
Give your Mastra database user a clear name so logs stay easy to read. Set a statement timeout on that role so bad queries do not hang. An AI agent might write a slow join across millions of table rows. A strict timeout stops one bad prompt from using up all database memory. Review your role grants whenever you add new tables to your project.
Add query and result controls beside Postgres
Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.
When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.
Frequently asked questions
Why should I avoid using the default postgres role for Mastra?
The default postgres role has admin privileges that allow data edits and table drops. Supabase advises making a separate user for every external service to limit risk.
Can a read-only Supabase role stop Mastra from reading sensitive columns?
Table-level select grants allow reading all columns, including emails, phone numbers, and card numbers by default. To redact fields in results without managing custom views, you need runtime data masking.
Where do I create the read-only user in Supabase?
You run role creation commands inside the Supabase SQL dashboard. Queries in the dashboard run as the postgres admin role, which can create new users.
Related guides
In this post