How to Configure Codex SQL Server Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up codex sql server permissions by creating a restricted database user. Then you assign that user to a read-only database role. Teams often connect AI coding agents to databases using shared admin keys. This shortcut gives the agent full power to change or drop tables. A dedicated account with strict role rules limits what the agent can do. How codex sql server permissions work SQL Server separates server logins from individual database users. A login lets a person or agent enter the

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 codex sql server permissions by creating a restricted database user. Then you assign that user to a read-only database role. Teams often connect AI coding agents to databases using shared admin keys. This shortcut gives the agent full power to change or drop tables. A dedicated account with strict role rules limits what the agent can do.

How codex sql server permissions work

SQL Server separates server logins from individual database users. A login lets a person or agent enter the server instance. That login lives in the master database on the server. When an agent needs many databases, teams create a login in master first. Then they map a database user to that login inside each database.

Teams also have another option for single database access. You can create a contained database user with its own password. This user connects straight to one database without a login in master. An admin must turn on contained databases on the server and database first. Microsoft offers thirteen distinct types of database users for different needs.

Once the user exists, you assign it to a fixed database role. Every database role, including the public role, allows basic connection rights. You cannot change the built-in rules of fixed database roles. To let an agent inspect tables, you add it to the data reader role. Members of this role can read all data from all user tables. They can also read data from all views in that database.

How to lock down write actions

Wait before you add the agent to the data writer role. Members of the data writer role can add, change, or delete table data. You should also avoid the database owner role for AI agents. The owner role can change settings, run maintenance, and drop the whole database.

You can add extra safety with deny roles in SQL Server. The deny data writer role blocks a user from changing any table data. It stops all inserts, updates, and deletes across the database. The deny data reader role blocks a user from reading user tables and views. It also hides metadata about those tables and views from the user. Pairing the data reader role with the deny data writer role is practice. Wait, let us rephrase that without banned words: Pairing the data reader role with the deny data writer role works well. This setup ensures the agent can read rows but never change them.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native database roles leave open

Native roles control who logs in and which tables they can read. They do not inspect what individual queries do while running in flight. A read-only user can still pull every row from a sensitive user table by default. If a table holds emails, phone numbers, or card numbers, the agent gets them. The data reader role gives access to all user tables at once. It does not rewrite matched fields like national IDs in query results.

Static database passwords also create a risk when stored on developer laptops. Anyone who finds the connection string can log in with those same rights. Native roles also do not require a human check before a query runs. Teams need a way to inspect queries and mask sensitive fields in results.

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, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Should I use a server login or a contained user for Codex?

Use a server login in master if the agent needs many databases. Use a contained database user if it only needs one or a few databases. Contained users must be turned on at the server and database level first.

Can I edit the rules inside a fixed database role?

No, SQL Server does not let you change permissions on fixed roles. Instead, you combine roles like data reader and deny data writer on the user. You can also grant or deny permissions on specific tables if needed.

Does a read-only role hide sensitive columns from an AI agent?

No, the fixed data reader role lets the user read all user tables. The agent will still get emails, phone numbers, and card numbers in results. You need data masking to rewrite those matched fields before they return.

The query runs. The emails stay hidden.