How to Configure Mastra Supabase Data Masking

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mastra supabase data masking by creating a limited database role and redacting results. This setup keeps raw emails, phone numbers, card numbers, and national IDs out of agent outputs. Many teams connect their AI agents to the database with the default admin password. That broad role lets an agent read every table and expose private user rows. How native mastra supabase data masking works in Postgres Every project starts with a default postgres role that holds admin rights. The ven

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 data masking by creating a limited database role and redacting results. This setup keeps raw emails, phone numbers, card numbers, and national IDs out of agent outputs. Many teams connect their AI agents to the database with the default admin password. That broad role lets an agent read every table and expose private user rows.

How native mastra supabase data masking works in Postgres

Every project starts with a default postgres role that holds admin rights. The vendor does not grant full superuser status to prevent destructive database actions. Even so, the vendor warns against giving this main admin password to outside services. You should create a fresh database user for your Mastra agent instead.

Each project also includes built-in roles like anon for public requests. To mask fields inside the database, teams build custom views over their raw tables. These views replace sensitive text like card numbers or emails with placeholder strings. You then grant your agent role permission to read the view, not the base table.

When the Mastra workflow runs a query, it logs in with that restricted role. The database checks the role permissions before it returns any rows to the app. If the agent asks for the base table, the database blocks the query right away. If the agent queries the safe view, the database returns the pre-masked text.

Why database roles and views are only half the fix

Database roles and views control which tables a user or agent can read at login. They work well when your agent only runs fixed queries against known tables. Still, AI agents often write dynamic queries or call shared backend tools during a run. Maintaining separate masked views for every table and column creates heavy work for your team.

Schema changes also break custom views if an engineer adds a new column with phone numbers. A forgotten grant or a shared backend role can still return raw national IDs. Also, queries run in the web dashboard execute as the main postgres admin role. Native roles decide who logs in, not what individual queries return in flight.

Data Masking (Static) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Inspecting queries and masking results in flight

Teams need a way to inspect query results before they reach the Mastra agent or user. Runtime masking checks the data as it leaves the database and rewrites matched fields in results. This approach catches emails, phone numbers, card numbers, and national IDs across all tables at once. You do not have to rebuild database views every time your app schema changes.

Centralizing your access rules also helps when humans and agents share the same data store. You can log every query statement and apply redaction rules based on who is asking. This keeps your database schema clean while protecting private fields across every query path.

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 my Mastra agent the default postgres password?

No, the default postgres password has admin rights across the database. The vendor advises creating a separate database user for each external service or agent.

What types of data can runtime masking rewrite in query results?

Masking rules detect and rewrite structured fields like emails, phone numbers, card numbers, and national IDs. The system replaces those matched values in the query results before the client reads them.

How do dashboard queries differ from agent queries in Supabase?

Queries run inside the project dashboard execute under the main postgres admin role. They also carry a dashboard source comment, whereas agents should use a dedicated limited user.

The query runs. The emails stay hidden.