How to Configure Mastra ClickHouse Data Masking
You set up mastra clickhouse data masking by limiting columns or rewriting query results. This approach keeps sensitive fields out of your AI agent context. Teams often give an AI workflow full read rights to a database. That broad role lets agents pull raw emails and phone numbers into prompts. When an agent runs a wide query, private records enter external model logs. How native mastra clickhouse data masking works in SQL ClickHouse manages users, roles, row policies, settings profiles, and
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 clickhouse data masking by limiting columns or rewriting query results. This approach keeps sensitive fields out of your AI agent context. Teams often give an AI workflow full read rights to a database. That broad role lets agents pull raw emails and phone numbers into prompts. When an agent runs a wide query, private records enter external model logs.
How native mastra clickhouse data masking works in SQL
ClickHouse manages users, roles, row policies, settings profiles, and quotas as SQL entities. To turn on SQL access control, you set up a storage directory. You also need at least one admin user with access management turned on. That admin can only grant rights that they already hold themselves. Creating a new user takes the create user privilege in the database. During setup, you pick the login method and allowed host locations. You can also assign default roles and specific user settings right away.
Once the user exists for your Mastra workflow, you limit what it reads. ClickHouse lets you grant read rights on single columns in a table. If you grant select rights on two safe columns, the agent reads those. Any query that asks for a third restricted column will fail right away. A full wildcard select query also fails and returns no rows at all. Wildcard queries only work when the table holds just the allowed columns. Since version 24.10, a trailing asterisk grants rights by table name prefix. Teams also build custom SQL views that format card numbers or national IDs. Then they grant the Mastra user read rights on those views only.
What native column grants solve and what they leave open
Native column grants and roles control which account can log into ClickHouse. They do a great job of blocking access to whole columns on disk. If a column holds only phone numbers, dropping it from grants works well. Still, database roles only decide who logs in and which objects they touch. They do not inspect what individual statements or agent requests do in flight.
AI agents in Mastra often build dynamic queries to answer user questions. When an agent runs a wildcard query, ClickHouse rejects the whole statement. That breaks the agent workflow instead of returning safe, redacted data. Also, free-text log columns and JSON blobs mix safe facts with emails. Native column grants must block the whole text column or allow all of it. Maintaining hundreds of custom masking views across changing tables takes constant schema work. Every time a developer adds a table, someone must update views and grants.
Data Masking (Static) + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Why runtime query handling helps AI workflows
AI tools work best when queries run without breaking on strict column rules. Instead of failing on wildcard selects, runtime masking rewrites matched fields in results. The database returns the rows, and the runtime step masks card numbers in flight. Emails, phone numbers, and national IDs get replaced before reaching the Mastra agent. This keeps agent queries working while rewriting sensitive values in the payload.
Check ClickHouse queries and result columns on the wire
ClickHouse users and row policies decide who connects. They do not check each statement on the wire or redact sensitive string columns in query results. With hoop.dev, you run an open-source proxy, a sidecar for your ClickHouse. It reads ClickHouse's native TCP protocol before queries run while ClickHouse stays in charge of login and grants.
Multi-statement queries and table mutations are split and checked by hoop.dev guardrails. Banned actions are refused with a native ClickHouse error. On returned rows, hoop.dev data masking rewrites String and FixedString columns that match your rules. The audit trail logs each query, table, and verdict. See the MIT-licensed source on GitHub.
Frequently asked questions
What happens when a Mastra agent runs a wildcard query on restricted ClickHouse columns?
ClickHouse refuses the wildcard query and returns no data at all. The query only works if the user has grants for every single column.
How do you turn on SQL-driven access control in ClickHouse?
You configure the access control storage directory on the ClickHouse server. You also enable access management and named collection control for an admin user.
Can native ClickHouse column grants mask an email inside a JSON text column?
No, column grants only allow or block the entire column as one unit. Rewriting an email inside unstructured text requires view expressions or runtime result masking.
Related guides
In this post