How to Configure Mastra Supabase Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a mastra supabase audit log by creating a dedicated database role for your agent and enabling statement tracking in Postgres. This setup records which database user ran a query and when the action took place. Many teams start by giving their AI agents the default postgres admin password. Supabase gives every project this default admin role at creation. This role holds broad privileges across the database. When an agent uses this shared admin role, your logs cannot tell agent queries

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 mastra supabase audit log by creating a dedicated database role for your agent and enabling statement tracking in Postgres. This setup records which database user ran a query and when the action took place.

Many teams start by giving their AI agents the default postgres admin password. Supabase gives every project this default admin role at creation. This role holds broad privileges across the database. When an agent uses this shared admin role, your logs cannot tell agent queries apart from human edits. A bad prompt or agent bug can also alter tables or read sensitive rows across the whole database.

How a mastra supabase audit log works with database roles

A clean setup starts with role separation inside your database. Supabase warns against giving the default postgres password to any external service. Instead, you should create a fresh database user just for your Mastra app. Every query you run in the Supabase dashboard executes as the default postgres role. Dashboard queries also carry a comment tag showing they came from the dashboard.

When your agent uses its own database role, Postgres records that specific role name in its log entries. You also need to restrict what tables this agent role can read or write. Supabase projects include built-in roles like anon and authenticated for standard app traffic. For backend agent workflows, a custom role with strict table grants keeps the agent inside a safe boundary. You then turn on database logging so Postgres writes statement records to your log storage. This lets your team check what queries the agent ran during a task.

What native roles solve and what they leave open

Creating a separate database role for Mastra solves basic identity tracking at the database level. Your team can filter database logs by role name to spot agent activity. It also stops you from sharing the main admin password across multiple apps. If you need to cut off the agent, you can revoke its role without breaking other services.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, database roles only decide who can log in and which tables they can touch. They do not inspect or control individual statements while queries run in flight. Once the agent logs in, it can still pull bulk rows from any allowed table. Standard database logs also do not mask sensitive fields like emails, phone numbers, card numbers, or national IDs. If an agent queries a customer table, raw values flow straight back into the agent context. Native role grants also cannot pause a risky delete statement to ask a human for approval first.

Why agent workflows need statement-level controls

AI agents build and run queries on the fly based on user prompts. Static table grants cannot predict every query shape an agent might try to run. A safe agent setup needs to check each statement before it reaches the database engine. It also needs to rewrite matched fields like emails or card numbers in query results. Pairing database role separation with statement-level checks gives your team clear logs and tight data safety.

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

Should I give Mastra the default Supabase postgres password?

No, you should never share the default postgres password with external apps or agents. Supabase recommends creating a separate database user for each service so you can limit its permissions.

How can I tell dashboard queries apart from Mastra queries in logs?

Queries run inside the Supabase dashboard execute under the postgres role and include a dashboard source comment. When Mastra uses its own dedicated role, its queries show that custom role name in your logs.

Does a Supabase database role hide sensitive columns from AI agents?

A database role only controls which tables or columns a user can query at all. To mask values like emails, phone numbers, or card numbers inside results, you need dynamic data masking in flight.

The query runs. The emails stay hidden.