How to Configure CrewAI Supabase Read Only Access
You set up crewai supabase read only access by creating a restricted Postgres role. Then you pass that role to your CrewAI database tool instead of the default admin login. Many teams test agents with the default admin password they set at project creation. That setup lets an AI agent edit or delete production tables if a prompt goes wrong. Giving the agent a read-only database user stops write commands at the database engine. How crewai supabase read only access works in Postgres Every Supab
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 crewai supabase read only access by creating a restricted Postgres role. Then you pass that role to your CrewAI database tool instead of the default admin login. Many teams test agents with the default admin password they set at project creation. That setup lets an AI agent edit or delete production tables if a prompt goes wrong. Giving the agent a read-only database user stops write commands at the database engine.
How crewai supabase read only access works in Postgres
Every Supabase project comes with a default postgres role that holds admin rights. The platform does not grant full superuser status because superusers can run destructive operations. Even so, the default admin role can still drop tables, change schemas, and read every row by default. The project password you create on day one belongs to this admin role. Docs advises that you never share this admin password with an external service. Instead, you should make a dedicated database user for each service or agent.
To lock down your CrewAI agents, you log in through the dashboard and create a fresh role. Queries you run in the dashboard execute as the admin role. You grant the new agent role permission to connect to the database. Next, you grant usage on the target schema, which is usually the public schema. Finally, you grant select rights on the specific tables the agent needs to read. You also set default privileges so future tables in that schema allow select queries too.
Once the role exists, you put its username and password into your CrewAI environment variables. Your CrewAI tasks use database tools to turn natural language questions into SQL queries. When the agent runs a query, Postgres checks the permissions of that dedicated role. If the agent tries to insert, update, or delete data, Postgres blocks the statement right away.
What native database roles solve and what they miss
A dedicated Postgres role solves the biggest risk of text-to-SQL agents. It stops an agent from changing data or dropping tables during a task run. The database engine enforces this rule no matter how the agent formats the SQL string. It also separates the agent login from your main admin password. If you need to cut off the agent, you can revoke its role without breaking other apps.
Still, a static database role only decides who can log in and which tables they can read. It does not inspect what individual queries do while they run in flight. First, a read-only role can still read every column inside an allowed table by default. If a customer table holds emails, phone numbers, card numbers, or national IDs, the agent pulls those values into memory. Those raw fields then travel to the language model provider inside the prompt context.
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.
Second, you still have to store a long-lived database password inside the CrewAI host environment. Anyone who can read the agent host config can take that password and query the database from anywhere. Third, native Postgres roles do not link individual SQL statements back to a specific agent task or human user. Database logs only show that the shared agent role ran a select query. Teams still need a way to mask sensitive fields in results and track every query by identity.
Best practices for scoping agent database permissions
Start by limiting the agent role to the exact tables required for its job. Do not grant select rights across the entire public schema if the agent only checks order status. If an agent only needs summary numbers, create a Postgres view that hides sensitive columns. Then grant the agent role select access on that view instead of the base table.
You should also set a statement timeout on the dedicated Postgres role. AI agents often write slow queries with bad joins or missing filters. A strict timeout stops a single bad select query from locking up database CPU and memory. Combining table scoping with statement timeouts keeps your database fast and safe during heavy agent runs.
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 is an open-source proxy that sits beside Postgres, RDS, or Aurora as a sidecar for your Postgres. Clients and agent tools keep their credentials and point their connection string at the listener.
On each query, hoop.dev guardrails refuse disallowed drops, deletes, or table reads before they run. Next, hoop.dev data masking rewrites sensitive fields in returned rows that match your rules. 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
Why should I not use the default postgres role for CrewAI?
The default postgres role has admin rights across your project. If a CrewAI agent uses this role, a bad prompt could delete rows or drop tables. Supabase advises making a separate user for each external service.
Does a read-only role hide sensitive columns from AI agents?
No, standard table select grants let the agent read every column in that table by default. Without data masking that rewrites matched fields in results, emails and phone numbers go straight to the model.
How do I stop CrewAI from running slow read queries on Supabase?
You can attach a statement timeout directly to the read-only role in Postgres. If the agent generates a heavy query that runs too long, the database cancels it right away.
Related guides
In this post