How to Configure MongoDB Encryption at REST
You set up mongodb encryption at rest by turning on storage engine encryption with a master key. This protects data files, indexes, and logs stored on your disks. Teams pair disk encryption with database roles to control who reads data. When roles are too broad, logged-in users still pull sensitive data in plain text. Disk encryption stops physical theft, but it does not filter live queries. How mongodb encryption at rest works with database roles Storage encryption locks down the files sitti
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 encryption at rest by turning on storage engine encryption with a master key. This protects data files, indexes, and logs stored on your disks. Teams pair disk encryption with database roles to control who reads data. When roles are too broad, logged-in users still pull sensitive data in plain text. Disk encryption stops physical theft, but it does not filter live queries.
How mongodb encryption at rest works with database roles
Storage encryption locks down the files sitting on a server volume. When the database writes a document to disk, it scrambles the bytes first. When an authorized user runs a query, the storage engine decrypts those bytes in memory. This means any user with valid database permissions sees unencrypted records in their query results.
To limit who reads decrypted data, teams set up role-based access in MongoDB. A role grants privileges to run sets of actions on specific resources. Each role applies to the database where you define it. Roles can grant permissions down to a single collection. Cloud deployments and self-hosted setups use different built-in roles. Still, both build their roles from the same basic privilege actions.
For daily work, admins assign built-in read or write roles to engineers and apps. The read role lets a user read all non-system collections in a database. It includes actions to find documents, list collections, list indexes, and check stats. It does not let users insert, update, remove, or drop a collection. The readWrite role includes everything in the read role plus data changes. It lets a user insert, update, remove, create collections, manage indexes, and drop collections.
What storage encryption solves and what it leaves open
Turning on disk encryption solves a clear physical security problem. If someone steals a hard drive or copies a raw volume snapshot, they cannot read the files. The data stays scrambled without the encryption key. This satisfies basic storage rules for data protection.
Still, storage encryption and collection roles leave a big operational gap open. Native roles decide who can log in and which collections they can query. They do not inspect what individual queries or commands do in flight. Once a developer logs in with the read role, the database decrypts every document they request.
Encryption at Rest + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
A collection role is all-or-nothing for the documents inside that collection. If a user collection holds emails, phone numbers, card numbers, and national IDs, a read role returns all of them. You cannot use a collection role to hide just the card numbers during a live fixing session. Also, giving a developer the readWrite role for a quick fix grants the ability to drop collections. Native storage encryption does nothing to stop accidental drops or broad data exports by logged-in users.
How to tighten access alongside disk encryption
To keep data safe during daily operations, teams must look beyond the disk layer. Start by scoping every user role to the single database and collection they need. Avoid giving broad roles across the whole cluster when a user only needs one collection. Separate normal read roles from write roles so engineers do not hold drop privileges all day.
Next, think about what happens after the storage engine decrypts a record for a user. Sensitive fields like emails, phone numbers, and card numbers travel back to the client in clear text. Teams need a way to rewrite matched fields in query results before they reach the screen. They also need a way to review write commands before someone drops an index or collection.
Inspect MongoDB wire traffic in flight
Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.
First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.
Frequently asked questions
Does mongodb encryption at rest hide sensitive fields from logged-in users?
No, the database decrypts data in memory for any authorized user. Anyone with the read role on a collection receives full documents in plain text. To hide emails or card numbers from users, you need data masking that rewrites matched fields in results.
How fine-grained are native MongoDB roles?
MongoDB roles grant permissions down to the collection level inside a specific database. They do not filter individual fields or rows inside a collection on their own. If a role grants find access to a collection, the user can read every document in it.
What is the risk of using the readWrite role for debugging?
The readWrite role includes actions that alter or delete structure and data. Beyond inserting and updating records, it allows users to drop indexes and drop entire collections. Assigning it for routine debugging exposes production collections to accidental deletion.
Related guides
In this post