How to Configure CrewAI Supabase Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a crewai supabase audit log by creating a dedicated Postgres role for your agent and turning on database statement logging. Then you route every agent tool call through that specific database user so the logs record each query. Most teams start by giving their AI agents the default project password to move fast. That default postgres role has admin rights across the whole database. When an agent uses that admin role, every query blends in with normal dashboard traffic and leaves you w

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 a crewai supabase audit log by creating a dedicated Postgres role for your agent and turning on database statement logging. Then you route every agent tool call through that specific database user so the logs record each query. Most teams start by giving their AI agents the default project password to move fast. That default postgres role has admin rights across the whole database. When an agent uses that admin role, every query blends in with normal dashboard traffic and leaves you with broad risk.

How a crewai supabase audit log works in Postgres

In a CrewAI project, agents use tools to read and write data in external systems. When a tool talks to a Supabase Postgres database, it logs in with a database user and password. Every Supabase project includes a default postgres role with admin rights. Supabase notes that you should never give this password to an external service unless you trust it. Instead, the docs recommend making a new database user for each service or app.

This separate user is the base of a clean audit log. You create a dedicated role for your CrewAI worker and grant it access only to the tables it needs. When you run queries in the Supabase dashboard, the system runs them as the postgres role and adds a source comment. By giving your agent its own role, you separate agent queries from human dashboard work. Postgres audit extensions and statement logs can then record the role name, timestamp, and SQL text for every command the agent sends.

Why role setup is only half the problem

Native database roles and audit logs tell you what happened after the fact. They check who can log in and which tables that role can read or change. Once the agent logs in, Postgres trusts any valid SQL statement that matches those table permissions. Text-to-SQL tools and agent scripts often build queries on the fly from user prompts. Executing arbitrary SQL queries from an agent is a known security risk.

A read-only role stops an agent from dropping a table. However, it does not filter sensitive columns inside an allowed table. If the agent selects a customer table, the query result can still pull raw emails, phone numbers, card numbers, or national IDs into the model context. Native Postgres audit logs also do not tie a SQL query back to the human or service identity that kicked off the CrewAI run. And because database logs write after a query runs, they cannot pause a bad update for human review before it hits your data.

Audit Log Integrity + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Separating agent tasks by database role

Good agent design splits work across specialized roles inside a crew. One agent might only read reports while another agent updates ticket rows. Your database setup should match that split. Do not let all agents share one broad database user across every task. Give your read agent a select-only role on specific tables. Give your write agent a narrow role that can only update the exact columns it owns.

This split makes your audit trail much easier to read during an incident check. You can filter the log by role name to see which agent step ran each SQL query. You can also spot prompt mistakes right away when a read agent tries to run a write command and fails.

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

Should my CrewAI agent use the default Supabase postgres password?

No. The default postgres role has admin rights across the database. Supabase recommends making a separate database user for every external service so you can limit table permissions and track queries by user.

How can I tell dashboard queries apart from CrewAI queries in Supabase?

Queries run inside the Supabase dashboard execute as the default postgres role and include a source dashboard comment. If you give your CrewAI tool its own database role, every agent query logs under that unique role name.

Do Postgres audit logs stop an agent from reading sensitive columns?

No. Audit logs only record queries that run against the database. If the agent role has select access on a table, it can still read emails, phone numbers, or card numbers unless data masking rewrites matched fields in results.

The query runs. The emails stay hidden.