How to Configure OpenHands SQL Server Audit Log

Published
Length
4 min read

Luis Felipe Dias

All posts

To set up an openhands sql server audit log, create a dedicated database user. Then enable native database tracking to record every query the AI agent runs. Teams often connect AI coding agents to databases using shared admin accounts. This broad setup makes it impossible to tell agent queries apart from human actions. If an agent runs a bad command, broad roles let it change or drop tables. Scoping the agent identity first makes your audit trail clear and useful. How to set up an openhands 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.

To set up an openhands sql server audit log, create a dedicated database user. Then enable native database tracking to record every query the AI agent runs. Teams often connect AI coding agents to databases using shared admin accounts. This broad setup makes it impossible to tell agent queries apart from human actions. If an agent runs a bad command, broad roles let it change or drop tables. Scoping the agent identity first makes your audit trail clear and useful.

How to set up an openhands sql server audit log

Start by creating a separate identity for the OpenHands agent in your database. In SQL Server, a database user is the identity of a login when it connects. If the agent needs many databases on an instance, create a SQL user with a login in master. If it only needs one or a few databases, use a contained database user with a password. A contained user does not tie to a login in master. An admin must first turn on contained databases on the server and database. Note that SQL Server offers 13 types of database users.

Next, assign the agent user to a fixed database role that fits its job. You cannot change the permissions assigned to fixed database roles. Every role, including the public role, has basic connect rights. If OpenHands only needs to inspect data, place it in the data reader role. Members of this role can read all data from all user tables and views. You can also use a deny data writer role to block changes. That role cannot add, modify, or delete any table data. Avoid the database owner role for an autonomous agent. That role can run all maintenance tasks and even drop the database.

Once the identity and role are ready, turn on native server and database auditing. Configure the audit rules to watch the specific user account assigned to OpenHands. Set the audit spec to log select, insert, update, and delete actions. Direct these audit records to a safe file target or the system security log. Now every statement the agent runs gets written down with a timestamp and user name.

Why native roles and audit logs fall short for AI agents

Native roles and audit logs solve the first part of database safety. They decide who can log in and record what happened after the fact. A dedicated user and a read-only role stop an agent from dropping tables. The native log gives you a trail to check after an incident occurs.

Still, this setup leaves a major operational gap during live agent runs. Fixed roles are all-or-nothing inside a database. A member of the data reader role can read every user table and view. The agent might query tables that hold emails, phone numbers, card numbers, or national IDs. Native roles do not rewrite matched fields in query results on the fly. You would have to build and maintain custom views for every sensitive table.

Audit Log Integrity + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Also, an audit log is passive. It writes down a bad query only after the database runs it. If OpenHands needs write rights to fix data, the data writer role is wide open. Members of that role can add, delete, or change data in all user tables. Native setup decides who logs in, not what individual statements do in flight. It cannot pause a risky delete command and ask a human to approve it first.

Adding statement-level controls for autonomous agents

To run AI agents safely, teams pair native database roles with active statement controls. Before a query reaches the server, each statement should be checked against clear rules. This lets you block destructive commands while still allowing safe updates. You can also apply data masking in flight. Masking rewrites matched fields like emails or card numbers in results before the agent reads them. Combining native user scoping with real-time query checks keeps both your data and audit trail clean.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev is an open-source proxy that sits next to SQL Server as a sidecar for your SQL Server. It inspects TDS batches and parameterized queries in real time.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused with your message. Matched sensitive fields in supported result columns are masked in memory, and each decision is logged per listener. Check out the code on GitHub.

Frequently asked questions

What SQL Server role should I give an OpenHands agent?

Use the fixed data reader role if the agent only needs to read data. Add the deny data writer role to make sure it cannot add, change, or delete rows. Never give an AI agent the database owner role, because that role can drop the database.

Should I use a standard login or a contained user for OpenHands?

Use a contained database user with a password if OpenHands only accesses one or a few databases. An admin must enable contained databases on the server and database first. If the agent needs many databases on one instance, use a login in master instead.

Does the SQL Server data reader role hide sensitive columns from AI agents?

No, members of the fixed data reader role can read all data from all user tables and views. You cannot change the permissions of fixed roles to hide specific columns. To protect fields like phone numbers or national IDs, you need data masking that rewrites results.

The query runs. The emails stay hidden.