Ten configuration tips to improve MongoDB security

  • 2020-05-14 05:18:05
  • OfStack

MongoDB provides a series of 1 components to improve data security. Data security is Paramount in MongoDB -- so it leverages these components to reduce exposure. Here are 10 tips you can use to improve the security of your personal or cloud MongoDB servers.

1. Enable auth- enabling auth is a good security practice even when deploying an MongoDB server on a trusted network. It provides "deep defense" when your network is attacked. Edit the configuration file to enable auth.


auth = true


2. Do not expose your production database to Internet - restricting physical access to the database is a very important security measure. Do not expose the production environment's database to Internet if it is not necessary. If the attacker cannot physically connect to the MongoDB server at a discount, then the data is no more secure than it is now. If you deploy your service on amazon web service (AWS), then you should deploy your database on the virtual private cloud (VPC) private subnet.

3. Use a firewall - the use of a firewall can limit which entities are allowed to connect to the MongoDB server. The best approach is to allow only your own application server to access the database. If you cannot deploy to amazon web service (AWS), you can use the "security group" feature to restrict access. If you are deploying your service on a host from a provider that does not support firewalls, you can use "iptables" to configure the server yourself. Please refer to the mongodb documentation to configure iptables for your specific environment.

4. Set up a replication server cluster using key files - specify Shared key files to enable communication between MongoDB instances of the replication cluster. Add the keyfile parameter to the configuration file below. The contents of this file must be the same on all machines in the replication cluster.


keyFile = /srv/mongodb/keyfile


5. Disables the HTTP status interface - by default Mongodb runs the http interface on port 28017 to provide the "master" status page. It is recommended not to use this interface in a production environment, and it is best to disable it. This http interface can be disabled using the "nohttpinterface" configuration Settings.

nohttpinterface = true


6. Disable REST interfaces - it is not recommended to enable REST interfaces for MongoDB in production environments. This interface does not support any authentication. This interface is turned off by default. If you use the "rest" configuration option to open the interface, you should turn it off in production.

rest = false

7. Configure bind_ip- if your system USES multiple network interfaces, you can use the "bind_ip" option to restrict the mongodb server to listening only on the interfaces associated with this configuration item. By default, mongoDB binds all interfaces.


bind_ip = 10.10.0.25,10.10.0.26


8. Enable SSL- if you are not using SSL, the data you transmit between the MongoDB client and the MongoDB server is clear text, vulnerable to eavesdropping, tampering, and "man-in-the-middle" attacks. If you are connecting to an MongoDB server over a non-secure network like internet, enabling SSL is very important.

Role-based authentication - MongoDB supports role-based authentication so you have fine-grained control over the actions that each user can perform. Using role-based authentication constructs can restrict access to the database, rather than all users being administrators. Refer to the documentation on roles for more information.

10. Enterprise MongoDB and kerberos- enterprise mongodb inherit the kerberos certification. Refer to the mongodb documentation for more information on this. Username/password-based systems are inherently insecure, so use kerberos-based authentication if possible.


Related articles: