How to Configure OpenHands MongoDB Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openhands mongodb read only access by giving the agent a read role. That role lets the agent run find actions without changing or dropping data. Many teams give coding agents shared readWrite credentials to speed up initial testing. Broad roles create huge risk when an autonomous agent runs the wrong command. A single bad prompt can make the agent delete collections or corrupt records. How openhands mongodb read only access works in native roles MongoDB controls database access thr

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 openhands mongodb read only access by giving the agent a read role. That role lets the agent run find actions without changing or dropping data. Many teams give coding agents shared readWrite credentials to speed up initial testing. Broad roles create huge risk when an autonomous agent runs the wrong command. A single bad prompt can make the agent delete collections or corrupt records.

How openhands mongodb read only access works in native roles

MongoDB controls database access through role-based rules that grant specific actions on resources. Each role applies to the database where an admin defines it. You can scope custom roles down to an individual collection level. MongoDB Atlas and self-hosted setups use different built-in role lists. Both systems build their roles from the exact same set of privilege actions.

To lock down OpenHands, admins create a dedicated database user for the agent. They assign the built-in read role to that user on a target database. This read role allows access to all non-system collections in that database. It also grants access to the system.js collection. Under the hood, the role enables actions like find, listCollections, and listIndexes. The agent can also run dbStats, collStats, and changeStream actions to inspect state.

The built-in read role leaves out all data modification actions. It blocks insert, update, remove, and dropCollection commands at the database engine level. In contrast, the readWrite role includes every action from the read role. It also adds createCollection, createIndex, dropIndex, and all data writing actions. Removing readWrite permissions stops OpenHands from altering your database state during a task.

What native read roles solve and what they leave open

Native MongoDB read roles solve the problem of accidental writes and schema drops. When OpenHands connects with a read user, the database rejects any write command. This setup protects your stored records from bad code changes or agent mistakes. It is a solid first step for safe agent testing.

Still, database roles only decide who can log in and which actions run. They do not inspect what individual queries return while a session is active. A read role gives OpenHands full read access across every allowed collection. If a collection holds sensitive user records, the agent pulls all of them. Native roles cannot rewrite sensitive fields like emails or phone numbers in results. They also cannot mask card numbers or national IDs before the agent reads them.

Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static credentials also create a key management problem for engineering teams. You have to put a database password inside the OpenHands workspace settings. Anyone with access to that workspace can take the password and reuse it. Database logs only show that the shared agent user ran a find action. They do not link each query back to the human who prompted OpenHands.

Securing agent database sessions beyond static roles

Safe agent workflows need more than a static database role. Teams must control how credentials live inside the agent workspace. Leaving long-lived passwords in config files invites leaks and unmonitored queries. You also need visibility into every query the agent sends during a task.

Field-level data masking is another key piece for safe read access. When OpenHands inspects a collection to debug an issue, it needs document structure. It does not need real customer emails, phone numbers, or card numbers. Rewriting matched fields in query results keeps sensitive values out of model prompts. Pairing native read roles with live query controls gives teams a complete safety net.

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 actions does the MongoDB read role allow for OpenHands?

The read role allows find, listCollections, listIndexes, dbStats, collStats, and changeStream actions. It blocks insert, update, remove, and dropCollection actions on the database.

Can I scope MongoDB read permissions to a single collection?

Yes, MongoDB role-based authorization can grant access down to a collection level. You can build a custom role that grants find actions on one collection.

Does the MongoDB read role hide sensitive fields from OpenHands?

No, the built-in read role grants access to full documents in non-system collections. You need data masking to rewrite emails, phone numbers, or card numbers in results.

The query runs. The emails stay hidden.