How to Configure Vercel AI SDK CockroachDB Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up vercel ai sdk cockroachdb permissions by creating a custom database role. Then you grant that role read or write rights on specific tables. Many teams start by giving the app a default admin database user. This shortcut helps builders test tool calls fast during early project work. Still, broad grants let language models read private rows or drop production tables. How to set up vercel ai sdk cockroachdb permissions First, you create a dedicated SQL user inside your CockroachDB clu

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 vercel ai sdk cockroachdb permissions by creating a custom database role. Then you grant that role read or write rights on specific tables. Many teams start by giving the app a default admin database user. This shortcut helps builders test tool calls fast during early project work. Still, broad grants let language models read private rows or drop production tables.

How to set up vercel ai sdk cockroachdb permissions

First, you create a dedicated SQL user inside your CockroachDB cluster. You should avoid using the root user or a shared developer account. Next, you build a role that holds only the needed table privileges. If your AI agent only answers questions, grant it select rights only. You can limit this role to specific schemas and safe public tables.

After you set up the database role, you wire up the app. The Vercel AI SDK uses server functions and tool definitions to run queries. Your app reads the database connection string from a secret store at startup. When a user sends a prompt, the model picks a database tool. The server code then runs the SQL query using that restricted role.

You can also use row-level security to filter rows by user identity. The app passes a tenant value into the database session before running queries. CockroachDB then checks its policy rules before returning any matching table rows. This setup keeps one customer from asking the model for another customer's records.

Why static database roles are not enough for AI tools

Native database roles do a good job of stopping basic schema mistakes. A read-only role stops an AI tool from deleting a table by mistake. Schema grants also keep the app out of internal billing or system tables. These controls decide which database user can log in and touch a table.

Still, static grants cannot inspect what an individual query does in flight. A model with select rights on a customer table can still read everything. It can pull emails, phone numbers, card numbers, or national IDs into context. Once those fields reach the model, they can leak into chat responses. Masking rewrites matched fields in results before the app processes the output.

AI Agent Permissions: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Database roles also lack human approval steps for risky write actions. Sometimes an AI agent needs update rights to fix a stuck customer order. If you grant update privileges on that table, every prompt gets that power. A bad prompt could change thousands of rows in a single run. Teams also struggle to link a slow SQL query to a specific user. Every request from the app shares the same static database role in logs.

Managing credentials and query checks for AI agents

Storing long-lived database passwords in app settings creates another risk for teams. If an attacker steals those keys, they gain full access to that role. Rotating those secrets takes coordination across both the database and the hosting platform. Teams need a way to check queries and mask sensitive fields at runtime. They also need audit logs that tie each query to the real caller.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should I give the Vercel AI SDK a read-only CockroachDB role?

Yes, start with a read-only role on the exact tables the model needs. Only add write permissions to specific tables when a tool requires updates.

Can CockroachDB roles stop an AI model from reading private columns?

CockroachDB supports table and view grants, so you can expose limited views. Still, dynamic data masking is simpler when many tools query the same tables.

How do I track which user triggered an AI database query?

A shared connection string hides individual app users inside standard database logs. You need identity-linked logging to tie each SQL statement to the original caller.

The query runs. The emails stay hidden.