user993683
user993683

Reputation:

If I have authorization enabled, why is it dangerous to open up MongoDB to all remote IPs?

MongoDB by default only listens to traffic coming in from 127.0.0.1 (and port 27017). I'm the only one who can send traffic to that IP address, so this prevents random internet people from messing with my database and stealing data. Cool. But then I enable authorization by creating an admin user:

mongo
use admin
db.createUser(
  {
    user: "ADMINUSERNAME",
    pwd: "ADMINPASSWORD",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)
exit

and setting security.authorization to "enabled" in /etc/mongod.conf.

Now, if I set net.bindIp in /etc/mongod.conf to 127.0.0.1,<serveripaddress>, and open up port 27017 with ufw allow 27017, what method could attackers use (other than brute force user/password stuff) to break in to my database?

Is the recommendation to have an IP white-list just an extra layer of security, or is there something that I'm missing here? Advantages that I can think of:

  1. If an exploit is discovered in MongoDB, you still have an extra layer of defence.
  2. If you have bugs in your code, or mess up something (e.g. accidentally add a user with a weak password), you've got that extra layer.
  3. Safe from brute force user/password attacks - but assuming my password is 50 random ASCII characters long, this wouldn't be a problem, right?
  4. Bad actors can't directly DDOS/flood the mongodb server directly - but this is easy to solve in other ways I think (fail2ban or something like that).

So points #1 and #2 seem to be the only real problems - and I can definitely see the dangers there, but am I missing anything else?


Note: I don't think this question is suited to the security stackexchange site because it's a fairly simple program-specific question.

Edit: I was originally saying "authentication" when I meant "authorization".

Upvotes: 1

Views: 694

Answers (1)

Markus W Mahlberg
Markus W Mahlberg

Reputation: 20703

I thought long about wether to answer the question here or mark it as off-topic, but since “DevOps” seems to be ubiquitous these days, it might prevent serious damage when more easily accessible.

Disclaimer: there are books written about the general topic and a whole industry of engineers concerned with it. Here, only a brief overview and some hints can be given. Furthermore, some topics are heavily simplified. Do not rely solely on the information given here.

Assumption as per best practice: An attacker knows at least as much about your system (network, software, OS etc) as you do.

So, let us recap (some of) the general risks.

Unless you monitor failed login attempts and set up automatic action after a few failed attempts from a specific client (fail2ban being the simpelest example), one could brute force your accounts and passwords.

Furthermore, unless you use TLS, your connections are prone to eavesdropping. When successful, an attacker knows any credentials sent to the server.

Using exploits, for example of the ssh server, an attacker might hijack you machine. This risk increases for every exposed service. This attack is by far the most dangerous as your data will be compromised and the attacker might use your system to do Very Bad Things™ . In your name and in some jurisdictions even on your legal account.

Whitelisting IPs is surely helpful, but a determined attacker might get around this via IP spoofing. And you have to assume that the attacker knows valid source and destination IPs. Furthermore, when one of the whitelisted IPs is (partially) hijacked, an attack might well originate from there.

Now there are three general ways of dealing with those risks:

  • Risk mitigation, such as proper patch management and proper firewall setup.
  • Intrusion prevention, such as fail2ban
  • Intrusion detection

The latter deserves a bit of explanation. It is considered best practice to assume that sooner or later a successful attack is mounted against the system in question. It is imperative that a system's administrator can detect the intrusion in order to be able to take countermeasures. However, as soon as an attacker gets root privileges, all countermeasures can be undone. Therefor, it is imperative that an attacker can only acquire non-privileged access during the initial phases of an attack so you can detect his actions for privilege escalation. Conversely, this means that you have to make absolutely sure that the attacker can not acquire root privileges during the initial phases of an attack (which is one of the many reasons why no exposed service should ever run as root).

Assuming that you do not control the network, you have to resort to what is called host based intrusion detection or HIDS for short. HIDS in turn belong to two categories: behaviour based HIDS and state based HIDS. OSSEC belongs to the latter category and is (relatively) easy to set up and maintain while offering a broad range of features.

On a different level, exposing a database service to the public internet is almost always a sure sign that something is wrong with the system design. Unless you specifically want to provide database services, there is no reason I can think of for doing so.

If you only want to expose the data: write a REST-/SOAP-/whatever-API for it. If your database servers are only accessible via the public internet for some strange reason: Use VPN or stunnel.

Hint: depending on the application you create or the jurisdiction you live in, exposing the database service to the public internet might violate rules, regulations or even the law

tl;dr: if you have to ask, you probably should not do it.

Upvotes: 3

Related Questions