How to Configure OpenHands MongoDB Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up an openhands mongodb audit log, enable database auditing and assign a dedicated role to the agent. This setup tracks which database user logs in and records the actions that user runs. Many teams give autonomous coding agents broad database credentials to speed up early testing. Broad roles let an agent drop collections, modify records, or pull sensitive data without clear attribution. When every developer and agent shares one login, your audit trail loses its value. How an openhands

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 mongodb audit log, enable database auditing and assign a dedicated role to the agent. This setup tracks which database user logs in and records the actions that user runs. Many teams give autonomous coding agents broad database credentials to speed up early testing. Broad roles let an agent drop collections, modify records, or pull sensitive data without clear attribution. When every developer and agent shares one login, your audit trail loses its value.

How an openhands mongodb audit log works with database roles

MongoDB controls access through role-based rules that grant specific actions on defined resources. A role applies to a target database and can limit access down to the collection level. Note that MongoDB Atlas users have different built-in roles than self-hosted database users. Still, both setups build their roles from the same core set of privilege actions.

When you set up an agent like OpenHands, you should create a dedicated database user for it. For safe exploration, teams assign the built-in read role to that agent user. The read role lets the agent run find, listCollections, listIndexes, dbStats, collStats, and changeStream actions. It applies to all non-system collections in that database, plus the system.js collection. It does not permit insert, update, remove, or dropCollection actions.

If your agent must change data, teams often switch the user to the readWrite role. The readWrite role includes every action in the read role plus data modification privileges. Those extra actions include insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection. Once the agent has its own user and role, the database audit log records its events. You can see when the agent user logs in and which collections it touches.

What native roles solve and what they leave open

Native database roles and audit logs solve the basic problem of account separation. By giving OpenHands a read role, you stop the agent from running dropCollection or remove commands. The native audit log proves that a specific database account ran a find action at a set time. This helps compliance teams verify that read-only accounts did not alter production tables.

Still, native setup rules only decide who logs in and which collection they can reach. They do not inspect what individual statements or requests do while in flight. A read role still lets OpenHands pull every document from a sensitive customer collection. If those documents hold emails, phone numbers, card numbers, or national IDs, the agent gets them all. Data masking that rewrites matched fields in results is not part of a basic read role.

Audit Log Integrity + MongoDB Authentication & Authorization: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native logs also struggle to link a database query back to the human who prompted the agent. And if an agent needs readWrite access for one small task, it also gets dropCollection rights. Native roles cannot pause a risky update command to ask a human for approval first.

Why runtime command checks matter for autonomous agents

Autonomous agents work fast and generate queries without human review before each step. Relying only on static database roles leaves a wide gap between full denial and total trust. Teams need a way to check every command right before the database runs it. They also need to tie each database event to the exact user and agent session. Recording the full context of each query turns a basic log into a clear audit trail.

Check MongoDB commands and documents on the wire

MongoDB roles and SCRAM login decide who opens a session. They do not check single commands or redact sensitive fields inside returned documents. With hoop.dev, you run an open-source proxy, a sidecar for your MongoDB. It reads the MongoDB wire protocol and checks commands and bulk writes as JSON while passing login through untouched.

Before a command runs, hoop.dev guardrails check its effect and refuse banned drops or writes with MongoDB error code 13. On the way back, hoop.dev data masking rewrites sensitive fields in returned documents that match your rules. Every command and verdict is logged. See the open-source code on GitHub.

Frequently asked questions

What is the safest MongoDB role to give an OpenHands agent?

Start with the built-in read role on a single target database. This role allows find and listCollections actions while blocking insert, update, remove, and dropCollection actions. You can also scope custom roles down to specific collections if the agent needs less access.

Does the MongoDB readWrite role allow an agent to drop collections?

Yes, the built-in readWrite role includes the dropCollection and dropIndex privilege actions. It also allows insert, update, remove, createCollection, and createIndex actions across non-system collections. Avoid giving an autonomous agent full readWrite access on critical databases without extra safeguards.

Why is a dedicated database user required for an openhands mongodb audit log?

Database audit logs record events based on the database user account that runs the command. If OpenHands shares credentials with developers or apps, you cannot tell which queries the agent ran. A dedicated user ensures that all agent activity stands out in your log files.

Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.

The query runs. The emails stay hidden.