How to Configure CrewAI SQL Server Read Only Access
You set up crewai sql server read only access by creating a dedicated database user. Then you assign that user to a read-only database role before your agent connects. Many teams start by giving AI agents a shared admin account during testing. That broad role lets a single bad prompt change rows or drop tables. A dedicated read-only user stops the agent from writing or deleting records. How crewai sql server read only access works in the database SQL Server separates server logins from databa
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 read only access by creating a dedicated database user. Then you assign that user to a read-only database role before your agent connects. Many teams start by giving AI agents a shared admin account during testing. That broad role lets a single bad prompt change rows or drop tables. A dedicated read-only user stops the agent from writing or deleting records.
How crewai sql server read only access works in the database
SQL Server separates server logins from database users. A database user is the identity of a login inside one specific database. When an account needs many databases, admins create a login in the master database. Then they map that login to a user in each target database.
For one or a few databases, you can use a contained database user instead. This user has a password inside the target database and skips the master login. An admin must enable contained databases on the server and target database first. SQL Server supports thirteen different types of database users for various login needs.
Once the user exists, you must restrict what it can do. SQL Server provides fixed database roles with preset rights that cannot be changed. Every role, including the public role, includes basic permission to connect. The data reader role lets members read all data from all user tables. It also lets them read all user views in that database.
To lock down the agent further, you can pair roles together. The deny data writer role blocks the user from adding or changing data. It also blocks the user from deleting rows in any user table. Avoid the database owner role for any AI agent workflow. That owner role allows full maintenance and can even drop the entire database.
Why native roles are not enough for AI agents
CrewAI agents use language models to write and run SQL queries on their own. Native database roles check who logs in and which tables they can read. They do not inspect what each generated query does while it runs.
A read-only role still lets an agent read every column in every user table by default. If a table holds sensitive data, the agent pulls those raw values into memory. Those values then go straight to the model provider in the next prompt. Masking rules can rewrite emails, phone numbers, card numbers, and national IDs in results.
Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static database users also force teams to store passwords in app config files. If an agent host leaks its settings, anyone can use that database password. Also, database logs only show that the shared agent user ran a query. They do not show which task or human user triggered that specific agent run.
Steps to harden your agent database setup
Start by creating a separate database user just for your CrewAI tasks. Never reuse an app account that holds data writer or owner rights. Assign the data reader role and add the deny data writer role for safety.
If your agent only needs three tables, do not use the broad reader role. Grant read rights on only those three tables or build custom views instead. Views let you leave out columns that hold private customer details. Finally, set query timeouts in your database tool so bad joins cannot freeze the server.
Add runtime guardrails beside SQL Server
Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev runs beside the database as a sidecar for your SQL Server and checks TDS traffic without changing how clients log in.
With hoop.dev SQL Server controls, rules refuse banned statements before they run and can hold risky queries for human review. Matched sensitive values in supported result columns are masked before they reach the client. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.
Frequently asked questions
Can a fixed read-only role hide specific columns from an agent?
No, the built-in data reader role grants read rights on all user tables and views. To hide columns, you must grant table rights one by one or use custom views.
Should I use a master login or a contained user for CrewAI?
Use a contained database user if the agent only reads one or two databases. Use a login in the master database if the agent reads across many databases.
What happens if an agent runs a delete command with read-only roles?
SQL Server rejects the statement right away and returns a permission error to the agent. The data stays safe because the user lacks write rights and holds a deny role.
Related guides
In this post