How to Configure Mastra ClickHouse Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mastra clickhouse credentials by making a limited database user and passing its details to your agent. Always pair this user with strict read roles and column rules to keep your data safe. Many engineering teams start by sharing a single admin account across all their AI agents. This shortcut moves fast at first, but broad permissions put your database at risk. An agent with full rights can read secret tables or drop live data by mistake. Building a dedicated role stops these broad pe

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 credentials by making a limited database user and passing its details to your agent. Always pair this user with strict read roles and column rules to keep your data safe. Many engineering teams start by sharing a single admin account across all their AI agents. This shortcut moves fast at first, but broad permissions put your database at risk. An agent with full rights can read secret tables or drop live data by mistake. Building a dedicated role stops these broad permissions before your agent runs its first query.

How to set up mastra clickhouse credentials

ClickHouse treats users, roles, row rules, settings profiles, and quotas as SQL access items. Before you make a new user for Mastra, you must turn on SQL access control. This step needs a storage folder on the server and an admin user with management rights. Once that is ready, an admin with the right privilege can create a new user with SQL. A user can only hand out the rights that they already hold themselves.

When you create the account for your Mastra app, you define how it logs in. You can also lock down which host machines the user can log in from. During this step, you attach default roles and specific user settings to the account. After the database user exists, you store those login details in your Mastra app runtime. Your Mastra workflows and tools then read those values to log in and run analytical queries.

Scoping table and column permissions for AI agents

Giving your Mastra agent a dedicated login is only the first step. You also need to limit what tables and columns that user can read. In ClickHouse, you can grant read rights on specific columns instead of the whole table. If you grant read access on just two columns, the agent can only query those two fields. Any query that asks for other columns will fail right away.

This column rule also blocks wildcard queries that ask for every column at once. A wildcard query returns no data at all unless the table only has the allowed columns. If your database has many similar tables, you can grant rights using a name prefix. Using a trailing star lets you grant access across matching table names in one step. This keeps your setup clean when your agent needs to read across partitioned analytics tables.

Ephemeral Credentials + ClickHouse Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native credentials solve and what keeps the session active

Native database roles and column grants solve the basic problem of who can log in. They also set hard walls around which tables and columns a Mastra agent can touch. This stops an AI workflow from reading forbidden tables or changing records it should only read. For static apps with fixed queries, native database roles handle most day-to-day security needs well.

Still, AI agents build and run new SQL queries on the fly based on user prompts. Native credentials check who logs in, but they do not inspect individual queries in flight. Once an agent logs in, it holds those static keys for as long as they stay valid. If an allowed text column holds emails, phone numbers, or card numbers, the query returns them raw. Native roles also cannot pause a risky query for human approval before it hits the server.

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

Why did my Mastra agent fail when running a wildcard select query?

ClickHouse blocks wildcard queries when a user only has read rights on specific columns. Update your Mastra tool to ask for the exact allowed column names instead of using a star.

Who can create new mastra clickhouse credentials in the database?

Only an existing database user with user creation rights and access management enabled can make new users. Also, that admin can only grant table rights that they already hold themselves.

Can native column grants hide emails or card numbers inside a text column?

No, native column grants are all-or-nothing for each column you allow the agent to read. If you grant read access to a column, the database returns all values in that field as raw text.

The query runs. The emails stay hidden.