How to Configure MongoDB Atlas Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mongodb atlas least privilege by mapping database users to scoped roles. Each role grants specific actions on one database or one collection. Many teams start by giving developers broad database permissions to move fast. Broad permissions let one bad query or stolen key change or delete production data. Scoping permissions down to exact databases and collections limits that blast radius. How mongodb atlas least privilege works with native roles MongoDB uses role-based control to ma

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 mongodb atlas least privilege by mapping database users to scoped roles. Each role grants specific actions on one database or one collection. Many teams start by giving developers broad database permissions to move fast. Broad permissions let one bad query or stolen key change or delete production data. Scoping permissions down to exact databases and collections limits that blast radius.

How mongodb atlas least privilege works with native roles

MongoDB uses role-based control to manage what database users can do. A role grants permission to run specific actions on a defined resource. You define a role on a target database, and it applies there. Roles can also scope permissions down to a single collection. MongoDB Atlas offers its own built-in roles for cloud database users. These differ from self-hosted roles, yet both use the same privilege actions.

For daily read tasks, teams assign the built-in read role on one database. The read role lets a user read all non-system collections in that database. It permits actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream. It blocks data changes by leaving out insert, update, remove, and dropCollection. When an app or engineer must change records, teams use the readWrite role. The readWrite role includes all read actions plus data modification permissions. It adds insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection.

Scoping custom roles to specific collections

Built-in database roles apply to every non-system collection in that database. Sometimes a service or analyst only needs one or two collections. In those cases, a database-wide role still grants too much reach. You can build custom roles that pair exact actions with single collections. For example, a reporting user can get find permission on orders only. That user cannot read the payments or users collections in the same database.

Splitting roles by task keeps day-to-day work safer for the whole team. You can give an app its own role for one collection. You can give analysts a separate read role on non-sensitive collections. When each user has a narrow role, mistakes stay small and contained. Auditing also gets simpler because each role maps to a clear job.

Least Privilege Principle + MongoDB Authentication & Authorization: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what they leave open

Native roles solve the problem of who can log in and touch collections. They stop a read-only user from dropping a collection or deleting documents. They also keep a service scoped to its own database or collection. This forms a strong base for database security across your cloud clusters.

Still, collection roles cannot inspect what happens inside an allowed action in flight. A user with find permission on customers can read every field in every document. Native roles do not rewrite emails, phone numbers, card numbers, or national IDs. If an engineer needs to debug an order, they see raw customer fields too. Also, static roles stay active all day once you assign them to a user. A user with readWrite permission can run a wide update without a peer check. Native roles decide who enters the collection, not what each query returns or changes.

Add command guardrails and field masking beside MongoDB

Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.

Frequently asked questions

What is the lowest level of permission in MongoDB?

MongoDB roles can grant permissions down to the collection level inside a database. Native roles do not restrict permissions to individual documents or specific fields by themselves.

What is the difference between read and readWrite roles?

The read role allows queries like find and listCollections on non-system collections. The readWrite role adds change actions like insert, update, remove, and dropCollection.

Why do read-only roles still expose sensitive data?

The find action returns full documents from any collection the role can read. Without field masking, queries return raw emails, phone numbers, card numbers, and national IDs.

The query runs. The emails stay hidden.