As with any database platform, MongoDB security is of paramount importance to keeping your data safe. MongoDB and other data platforms like Redis and Elasticsearch are often in the news for data breaches because of misconfigured settings in the database. So how do you keep you and your company’s data from being compromised and from becoming another statistic?
We’ll show you five configuration options, as well as others that are required to go along with them, for your MongoDB deployment that will help keep your data secure while allowing use by users and applications with least-privileged access using modern authentication methods, keeping your data encrypted on disk and over the wire, and to see who is accessing your data as well. These configuration options are across the following areas in security: authentication, authorization, encryption, and auditing.
MongoDB security is composed of four main areas of focus, authentication (who), authorization(what), encryption (how), and auditing (when). This section is intended to give you a high-level overview of the different security focus areas for MongoDB.
Authentication is how you identify yourself to MongoDB. There are many ways to authenticate oneself to a MongoDB database, from standard username and password using the SCRAM (Salted Challenge Response Authentication Mechanism) protocol, certificate-based authentication to tying into an identity management solution such as LDAP (Lightweight Directory Access Protocol), Active Directory and Kerberos.
Authorization is how MongoDB determines what you, as an authenticated user, can do. MongoDB supports authorization using the RBAC (Role-Based Access Control) method. MongoDB lets you create roles which are groupings of privileges that any user granted that role can do. MongoDB comes with a comprehensive set of built-in roles as well as giving you the flexibility to create your own custom roles. Common roles like read-only and write are there of course, but also ones useful for monitoring any node, backup and restore, and user administration. Additionally, MongoDB also supports LDAP authorization which allows you to sync LDAP groups with roles to simplify management.
Encryption is how your data can be encrypted while in flight (Transport) and while on disk (At Rest). Transport encryption keeps your data encrypted while it is sent to and from your application to MongoDB. MongoDB supports TLS/SSL encryption for data in-flight using x.509 Certificates, and here’s an example of setting up Transport Encryption. Encryption at Rest keeps your data safe from an external party who might get a copy of your data files as they’ll be completely unreadable in their encrypted form.
Auditing shows you when users connected, when privileges were changed, various admin events, users attempt something they shouldn’t, etc. based on filter criteria you can set. This is helpful in compliance situations where you have to be able to show who was on the database at what time, what privileges they had, when privileges were changed, etc.
Tip: Don’t confuse auditing as a way to track users’ activities in real-time, but rather think of it as a way to create a tamper-proof, append-only log file that you can go back to that shows what was happening and by whom during a specific time.
Tip: Auditing is an expensive operation and will impact performance, be sure that you’re getting value from it and your IT Compliance team is able to actively use it, before setting it up.
So while knowing the important areas of MongoDB Security is great, how do we ensure they are enabled or set up correctly? And which ones are the most important? We’ll now go through 5 configuration options that will help you secure your MongoDB environment! We’ll also list some required configuration options that will work in conjunction with our 5 most important configuration options to keep your data safe. We’ll break these configuration options into their security focus areas.
MongoDB uses a configuration file in the YAML file format. The configuration file is usually found in the following locations, depending on your Operating System:
Our first configuration option, security.authorization, is perhaps the most important for enabling security on your MongoDB Deployment. This configuration option not only enforces MongoDB using authentication so that a user must at least login using credentials but it also simultaneously engages role-based access control which limits what a user can do.
|
1 |
security:<br> authorization: enabled |
Tip: If you set this configuration option up before creating a user in MongoDB, you could use the localhost exception in order to create your first user. This is especially helpful in cases of automation or other situations where you want to have all your configuration options configured only once and then come in and add users.
There are several other authentication configuration options that are required for your MongoDB deployment:
The security.authorization configuration option that enabled authentication is also the most important configuration option for setting up authorization since it also gives us roles that allow us to authorize users to have specific permissions. While there are some authorization configuration options for the inbuilt authorization system, most of the options are useful for integrating LDAP or other external authentication mechanisms with your roles. Read more about setting up LDAP Authorization, as well as a great blog post discussing how to set it up.
Transport Encryption ensures that your data is encrypted between your application and the database, it also can be used to encrypt data between members of your replica set and sharded cluster. The most important configuration option here is net.tls.mode. This configuration option is new in MongoDB 4.2, previous to MongoDB 4.2, this configuration option is named net.ssl.mode. This configuration option decides how strictly you want to enforce TLS encryption. The options for this configuration option are:
|
1 |
net:<br> tls:<br> mode: requireTL |
Additional required configuration options for transport encryption are:
Data at Rest Encryption ensures that your data can’t be read by someone who steals your database’s data files unless they also steal the key. This prevents someone from reading your MongoDB data files at the file system level. Here the most important configuration option is security.enableEncryption.
|
1 |
security:<br> enableEncryption: true |
Additional required configuration options for Data At Rest Encryption are:
Percona Server for MongoDB Specific Configuration Options:
Percona Server for MongoDB has integration with HashiCorp Vault for secret management for your Data at Rest Encryption. Read the documentation for Vault and Using Vault to Store the Master Key for Data at Rest Encryption on Percona Server for MongoDB.
Important configuration options for the Vault Integration are:
MongoDB Enterprise Specific Data At Rest Encryption Configuration Options:
Currently, MongoDB Enterprise does not have Vault Integration for Encryption at rest except in MongoDB Atlas. MongoDB Enterprise does support the KMIP protocol and you can integrate MongoDB with any Key Management tool that utilizes the KMIP protocol. Documentation can be found here.
Important configuration options to support Key Management through the KMIP protocol are:
Auditing allows IT Security Compliance teams to track and log activities that are run against the MongoDB database. There are several important auditing configuration options for MongoDB, auditLog.filter is the most important as it decides what exactly you are setting up in your auditing log.
|
1 |
auditLog:<br> filter: { <field1>: <expression1>, ... } |
For example, if we only wanted to have an audit log entry created every time someone created or removed a collection, we would set the auditLog.Filter as such:
|
1 |
auditLog:<br> filter: { atype: { $in: [ "createCollection", "dropCollection" ] } } |
If we wanted to audit everyone with a specific role, we could set the auditFilter as such:
|
1 |
auditLog:<br> filter:{ roles: { role: "readWrite", db: "appdb" } } |
Additional required configuration options for auditing are:
Finally, while auditing is important to track and log activity in your database, including accessing PII or other sensitive data, you don’t want to expose PII in your auditing or other log files. To accomplish this you must set up log redaction on your MongoDB Replica Set or Sharded Cluster. The important configuration option for log redaction is security.redactClientLogData. Acceptable values for this configuration option are true and false.
|
1 |
security:<br> redactClientLogData: true |
In this blog post, we’ve gone over five important MongoDB configuration options to ensure you have a more secure MongoDB deployment as well as some other configuration options that help the five keep your data secure. We hope that these configuration options will help you build more secure MongoDB deployments and avoid being a statistic of a data breach. Thanks for reading!
MongoDB Top Five Security Concerns
Our latest resource, Using Open Source Software to Ensure the Security of Your MongoDB Database, documents how to deploy a secure, enterprise-grade, MongoDB deployment without worrying about license fees, giving organizations the flexibility to deploy consistent models across their entire infrastructure.
Download “Using Open Source Software to Ensure the Security of Your MongoDB Database”
Resources
RELATED POSTS