How to Configure Gemini CLI SQL Server Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gemini cli sql server read only access by creating a restricted database user. Then you assign that user to a fixed read role before the agent logs in. Many engineering teams start by handing an AI terminal agent their own local database login. That shortcut often grants full owner rights to the tool. An agent with broad rights can alter tables or drop a database by mistake. Scoping the database account down to read permissions is the standard first step. How to set up gemini cli sq

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 gemini cli sql server read only access by creating a restricted database user. Then you assign that user to a fixed read role before the agent logs in. Many engineering teams start by handing an AI terminal agent their own local database login. That shortcut often grants full owner rights to the tool. An agent with broad rights can alter tables or drop a database by mistake. Scoping the database account down to read permissions is the standard first step.

How to set up gemini cli sql server read only access

In SQL Server, a login lets an identity reach the server instance through the master database. A database user represents that login inside one specific database. When an agent needs to query several databases, admins create a standard login in master first. Then they map a database user to that login inside each target database. If the agent only needs one database, a contained database user is another option. A contained user holds its own password and does not tie back to a master login. An admin must enable contained databases on the server and database before using this option.

Once the database user exists, you grant read permissions through fixed database roles. The built-in reader role lets a member read all data from all user tables and views. You cannot change the permissions inside a fixed database role. For extra safety, admins also add the user to the deny writer role. That role blocks the user from adding, changing, or deleting data in any user table. Every role, including the public role, already holds permission to connect to the database. You should never put an AI tool into the database owner role. Members of the owner role can run any maintenance task and even drop the database.

Why native roles are only the first step for AI agents

The Gemini CLI agent runs terminal commands and interacts with external systems using local credentials. When you give it a read-only database user, you stop direct table writes and deletes. This native setup solves the basic problem of accidental data changes during a coding session.

Still, fixed database roles only decide who can log in and which tables they can read. They do not inspect what individual queries do while in flight. A member of the built-in reader role can read every user table and view. That means the agent can still pull sensitive customer columns into its terminal context. Emails, phone numbers, card numbers, and national IDs sit inside those regular user tables. Unless you maintain custom views for every table, the native role returns all rows and columns. A bad query from the agent can also scan massive tables and lock up server resources.

Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing credentials and query risk in local terminals

Running an AI agent from a developer laptop also creates a credential storage problem. To connect to SQL Server, the terminal tool needs a password or connection string on disk. Developers often put these secrets inside local config files or shell variables. Once a password sits on a laptop, any local script or prompt can read it. Rotating those passwords across a whole engineering team takes hours of manual work.

Static database roles also lack fine audit logs for AI actions. When ten engineers share one read-only login for their agents, server logs show one user name. You cannot tell which person or which prompt ran a slow or risky query. Teams need a way to check queries in flight and rewrite matched fields like emails 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

Can I modify the built-in read role in SQL Server to hide specific columns?

No, SQL Server does not let you change the permissions assigned to fixed database roles. Members of the built-in reader role can read all data across all user tables and views.

What is the difference between a standard SQL login and a contained user?

A standard SQL user maps to a server login stored in the master database. A contained database user logs in directly to one database with a password after an admin enables containment.

Why should I add the deny writer role to a read-only agent user?

Adding the deny writer role blocks the user from adding, changing, or deleting table data. This step keeps the account from writing data even if another role grants write rights later.

The query runs. The emails stay hidden.