Blueprints · Docker & Databases
MongoDB 8 production hardening
Binds MongoDB to localhost, turns authorization on, and blocks 27017 when UFW is already active. The HTTP status interface is left unset because current mongod builds do not expose it.
Why this should not be public
Automated campaigns have wiped public MongoDB databases and left ransom notes since 2017. Authorization is still off unless you turn it on, so a reachable port is a readable, deletable database.
Live config
Baked-in protections
- bindIp is 127.0.0.1
- security.authorization is enabled
- Port 27017 is denied only when a firewall is already enforcing
- No extra HTTP listener is configured
Step 1 · yaml
mongod.conf
/root/portgate-blueprints/mongod.conf
Create the admin user on localhost before you restart, or you will lock yourself out of a fresh server.
net: bindIp: 127.0.0.1 port: 27017 security: authorization: enabled storage: dbPath: /var/lib/mongodb
Step 2 · bash
Firewall and reload
/root/portgate-blueprints/mongo-apply.sh
Does not enable UFW. A deny is added only when the firewall is already active. Database name {{DB_NAME}} is the application database, not the admin database.
#!/bin/sh set -eu if command -v ufw >/dev/null 2>&1 && ufw status | grep -q "Status: active"; then ufw deny 27017/tcp || true fi echo "Review /root/portgate-blueprints/mongod.conf and create an admin user before you replace the live config. Database: app"