How to Configure CrewAI SQL Server Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up crewai sql server permissions by creating a dedicated database user. Then you assign that user to a read-only database role. Teams often give an AI agent a broad admin login to move fast. That mistake lets a bad prompt alter tables or drop the whole database. A safe setup limits what the agent can read and write from day one. How crewai sql server permissions work SQL Server separates server logins from database users. A database user is the identity of a login inside one database.

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 crewai sql server permissions by creating a dedicated database user. Then you assign that user to a read-only database role. Teams often give an AI agent a broad admin login to move fast. That mistake lets a bad prompt alter tables or drop the whole database. A safe setup limits what the agent can read and write from day one.

How crewai sql server permissions work

SQL Server separates server logins from database users. A database user is the identity of a login inside one database. When an agent needs many databases on an instance, teams create a login in master. Then they map a SQL user to that login.

For one or a few databases, you can use a contained database user. This user has a password and does not tie to a login in master. An admin must enable contained databases on the server and database first. SQL Server offers thirteen types of database users in total.

After you make the user, you assign database roles. All roles, including the public role, have permission to connect. The fixed datareader role lets a user read all data from all user tables. It also lets the user read all views.

The fixed datawriter role lets a user add, delete, or change data in tables. You cannot change the permissions built into these fixed database roles. If an agent must never write data, add it to the deny datawriter role. That role blocks the user from adding, changing, or deleting any table data.

Never give an AI agent the database owner role. Members of that role can run all maintenance tasks and drop the database. Instead, create a custom role if the fixed datareader role is too broad. Grant select rights only on the specific tables and views the agent needs.

What native database roles solve and what they miss

Native SQL Server roles solve the first half of the security problem. They verify who logs in and which tables that account can touch. A contained user with a deny datawriter role stops accidental table drops. It also blocks the agent from deleting rows during a bad run.

Kubernetes API Server Access + AI Agent Permissions: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static roles do not check what individual queries do in flight. An agent with the datareader role can still read every column in allowed tables by default. If a table holds emails, phone numbers, or card numbers, the query pulls them. The database sends those raw values straight into the agent memory and prompt logs.

Static database users also force teams to put passwords in app config files. Anyone who reads the agent environment can copy that database password. Native roles cannot pause a risky query for human review before it runs. They also cannot mask national IDs in query results on the fly.

Steps to lock down agent database accounts

Start by listing the exact tables your CrewAI tasks need to read. Decide if the agent needs one database or many databases on the server. Pick a contained database user when the agent only touches one database. Create a dedicated user for the agent rather than sharing a human login.

Assign the deny datawriter role so the agent cannot change any rows. If the datareader role shows too many tables, build a custom role instead. Grant read access only to safe views that leave out sensitive columns. Use the deny datareader role if you must block all table and view reads.

Test the agent login by running a sample read task and a write task. Check that the database blocks the write task right away. Review your database logs often to see which queries the agent sends.

Check SQL Server batches and results on the wire

SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server. It reads plain batches and parameterized queries on the TDS wire while passing Windows login through untouched.

Before a batch hits the server, hoop.dev guardrails check the statement against your rules. Disallowed actions get a native TDS error with your message. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns that match your rules. Every query and decision is logged. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Should I give a CrewAI agent the fixed datareader role?

Only use the fixed datareader role if every user table and view is safe. That role lets the agent read all data across all user tables. If some tables hold secrets, grant select rights on specific views instead.

What is the difference between a login in master and a contained user?

A login in master works well when a user needs many databases. A contained user lives inside one database and has its own password. An admin must turn on contained databases on the server and database first.

How do I make sure an agent can never modify SQL Server data?

Do not add the agent user to the datawriter or owner roles. Add the user to the fixed deny datawriter role instead. That role stops the account from adding, changing, or deleting data in user tables.

The query runs. The emails stay hidden.