How to Configure Claude Code MariaDB Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code mariadb least privilege by creating a read-only database user. Then you pass that restricted user to your Model Context Protocol server or shell session. Many engineering teams start by reusing an admin account or a local developer login. That broad role lets the AI coding agent change rows, drop tables, or read private user records. A tight permission model stops bad queries before they break your data. How claude code mariadb least privilege works Claude Code reaches

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 claude code mariadb least privilege by creating a read-only database user. Then you pass that restricted user to your Model Context Protocol server or shell session. Many engineering teams start by reusing an admin account or a local developer login. That broad role lets the AI coding agent change rows, drop tables, or read private user records. A tight permission model stops bad queries before they break your data.

How claude code mariadb least privilege works

Claude Code reaches external databases in two main ways. First, it connects to data sources through Model Context Protocol servers. Vendor docs show database queries as a core MCP use case. They advise using a read-only database user in the connection string. This stops the queries the agent runs from changing your data. You also must verify you trust each MCP server before you use it.

Second, the agent can run shell commands through its built-in Bash tool. In Manual mode, the Bash tool asks for human approval before running most commands. Only a small built-in list of safe read commands runs without a prompt. If a developer approves a database client command, the agent uses the local credentials.

In MariaDB, you enforce least privilege by creating a dedicated role for the agent. You grant that user select rights only on the specific tables it needs. You leave out insert, update, delete, and schema change rights. When the agent connects via MCP or Bash, MariaDB checks every query against those grants. If the agent tries to write data, the database rejects the statement right away.

How to scope MariaDB roles for AI coding agents

Start by listing the exact schemas the agent needs to inspect. Most coding tasks only require schema metadata or sample rows from non-sensitive tables. Create a dedicated MariaDB account just for the agent workflow. Never share this login with web apps or human admins.

Next, grant select permissions at the table or column level. MariaDB lets you restrict select rights to safe columns inside a table. Keep the agent away from tables that hold passwords, billing records, or secret keys. You can also set database resource limits on that user account. Query time limits and connection caps keep a bad prompt from locking up your server.

Least Privilege Principle + Claude Code Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Where native database roles fall short

Native MariaDB grants solve a big part of the risk. They decide who can log in and which tables they can read. Still, static database grants cannot inspect what happens inside an allowed select query in flight.

A read-only user can still pull thousands of rows from a customer table. If that table holds emails, phone numbers, card numbers, or national IDs, the agent reads them. Those raw values then flow into the model context and external logs. Also, storing connection strings on engineer laptops creates secret sprawl. Teams have to rotate passwords by hand when someone leaves or changes roles. Static grants also give weak audit logs when many developers share one read-only login. You see the shared database user in the log, not the person who ran the prompt.

Add wire guardrails and masking beside MySQL

Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev sits inline in the wire protocol beside the database as a sidecar for your MySQL. On every production query an agent or engineer sends, hoop.dev decides to pass, mask, block, or escalate it for human review.

With hoop.dev MySQL support, guardrails refuse bad queries before they run or hold risky calls for approval, while data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.

Frequently asked questions

How does Claude Code connect to a MariaDB database?

It connects through a Model Context Protocol server or by running database CLI tools in Bash. Vendor docs recommends using a read-only database user in the MCP connection string.

Why is a read-only MariaDB user not enough for AI agents?

A read-only role still lets the agent read sensitive columns across allowed tables. Without field masking, emails, phone numbers, and card numbers enter the model prompt context.

Does Claude Code run database shell commands without asking?

No, in Manual mode the Bash tool requires user approval for database commands. Only a small built-in set of basic read-only shell commands runs without approval.

The query runs. The emails stay hidden.