Securing MongoDB

Enable Access Control and Enforce Authentication

$ mongod --port 27017
$ mongo --port 27017
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "USE-SOME-SECURE-PASSWORD",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
$ mongod --auth --port 27017
$ mongo --port 27017 -u "myUserAdmin" -p "USE-SOME-SECURE-PASSWORD" --authenticationDatabase "admin"
$ mongo --port 27017
use admin
db.auth("myUserAdmin", "USE-SOME-SECURE-PASSWORD" )

Setup Firewall

$ iptables -A INPUT -s <ip-address> -p tcp --destination-port <port> -m state --state NEW,ESTABLISHED -j ACCEPT$ iptables -A OUTPUT -d <ip-address> -p tcp --source-port <port> -m state --state ESTABLISHED -j ACCEPT
$ iptables -P INPUT DROP

$ iptables -P OUTPUT DROP
$ service iptables saveor$ iptables-save > OUTPUT_FILE
$ iptables-restore < OUTPUT_FILE

--

--

Security, Cryptography, Privacy, AI

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store