The breach was never exotic
Every headline about a leaked MongoDB — millions of records, wide open, indexed by a scanner in minutes — was the same mistake wearing a different company's name. Not a clever exploit, not a zero-day. A database bound to 0.0.0.0 with authentication disabled, reachable on port 27017 by anyone who cared to look. The install worked perfectly. That was the problem: it worked, it answered, and it answered the entire internet.
So the thesis of this piece is narrow and uncomfortable: with MongoDB, installing is not securing — the security lives in the bind address and the authorization switch, and both are off the beaten path of a naive setup. The packages are trivial. Whether your data faces the world is one configuration line, and it is the only line that matters until you get it right.
Before you install: is there already a dataset here?
The reconnaissance that matters most has an irreversible failure mode behind it. A reinstall that steps on an existing data directory does not upgrade your database; it can orphan or replace it. Look before you touch.
- Is MongoDB present, and at what version?
command -v mongod && mongod --version | head -1. If it answers, you are auditing an existing install, not laying down a new one. - Is the daemon running?
systemctl is-active mongod. A livemongodmeans data may be in flight, and a reinstall is the last thing you fire blind. - Is 27017 already taken?
ss -tlnH 'sport = :27017'. Something answering there is the loudest possible signal to stop and read before you act.
Say it plainly: never re-initialise a server that already holds a dataset. If MongoDB is already there, the correct behaviour is to verify the version and report, not to install on top. The only way to know whether that condition holds is to look first — which is why any honest run leads with reconnaissance and refuses to touch a data path it did not expect to find.
1. Install from the official repository, not whatever ships by default
On Debian and Ubuntu the sane path is MongoDB's own repository: add the official source, then apt-get install -y mongodb-org. The reason to use the vendor repo rather than a distribution's stock package is version control in the literal sense — you get the major version you chose, from a source you can name, with the tooling (mongosh, the database tools) that matches it. A supply chain you can point at is one you can reason about later.
The proof the step worked is a version string from mongod --version | head -1, not that apt exited zero. Then systemctl enable --now mongod, and confirm systemctl is-active mongod returns active — a daemon that runs today but does not survive a reboot is a datastore that vanishes at the worst time.
2. The bind address: the one line the breaches were about
Here is the fact the install guides bury and this article prints in bold. A MongoDB listening on 127.0.0.1 is reachable only from the machine itself; a MongoDB listening on 0.0.0.0 is reachable from every network the server touches. The default posture you want is loopback, full stop, until you have a deliberate reason and a firewalled path to do otherwise.
The trap is that widening the bind feels like progress — “now my app on the other box can connect” — and it is the exact move that put those millions of records on a scanner list. If a remote service genuinely needs the database, the answer is a private network or a tunnel, not 0.0.0.0. And widening the bind is precisely the moment authorization stops being optional.
3. Authorization is off by default — turn it on and prove it
A stock MongoDB starts with no authentication enabled. On loopback that is survivable; the instant the bind address is anything else, it is an open door. Enabling authorization means creating an administrative user and then requiring credentials for every connection, so that reaching the port is not the same as owning the data.
The verification here is unusually satisfying, because you can prove the negative:
- create the admin user first — because once authorization is on with no users, you can lock yourself out;
- enable authorization and restart the daemon, confirming
is-activestill returnsactiveafter the restart; - prove an unauthenticated
mongoshis refused — a connection that used to list databases now gets an authorization error. That refusal is the proof the switch is real; a green service is not.
Keep the admin password out of the shell history, and never echo it into a log. The whole point of enabling auth is defeated by a credential sitting in ~/.bash_history.
What a default MongoDB does not do
A fresh install enables no authentication — so “it installed” and “it is secure” are two entirely different claims, and only one of them is your job to make true. A single Community node is not a managed, replicated cluster: it does not fail over, and if the machine dies you are restoring, not switching. Nothing about installing MongoDB backs up your data — that is a separate discipline, and a dump you have never restored is a hypothesis, not a backup. And a public bind with weak or absent auth is not a misconfiguration you can monitor your way out of; it is game over the moment a scanner finds it. Convenience is not a security posture.
The check that proves the posture, not just the install
In order: mongod --version | head -1 for the engine; systemctl is-active mongod and is-enabled so it survives a reboot; ss -tlpn confirming mongod answers on 127.0.0.1:27017 and not the 0.0.0.0 wildcard; and, once authorization is on, an unauthenticated mongosh being refused. The last one is the check people skip, and it is the only one that proves the door is actually locked.
Where Servor fits
Servor ships MongoDB as a recipe — one of 150+ vetted playbooks — and the recipe shape is what keeps a datastore install from quietly becoming a data leak. A recipe is not a script fired blind: it starts with reconnaissance, reading whether MongoDB is already installed, whether the daemon is up, and whether 27017 is taken, so it never re-initialises a dataset it found. Each step carries its own verify — the version string, the is-active, the refused unauthenticated connection — so the run proves the posture, not just the packages. The playbook is idempotent: an existing install is checked and reported, not stacked over.
The guardrails are written in because the defaults are dangerous: bind to localhost by default, and never open 0.0.0.0 without authentication. A public bind is treated as the deliberate, eyes-open decision it is — proposed and explained, not slipped through.
And the execution never leaves the zero-knowledge path: every command is signed in your browser with a key derived from your vault key, relayed verbatim, and verified by the agent on the machine before it runs. The database credentials you store never reach us in the clear. The care applied to the more relational cousin is in the PostgreSQL piece, the cache-shaped one in the Redis piece, and the discipline behind the approve-sign-verify loop is in the Plan-Execute-Verify piece. Browse the rest of the recipe catalogue, or read how it all fits together in our server operations guide.