I understand that by default a docker container will be created in its own network stack.
I would like to use the --net host
flag when running docker containers to allow the use of all host ports.
The disadvantages I am aware of:
- Services running inside the container could potentially conflict with other services in other containers which run on the same port.
- Containers can access the full network stack.
My question is, what is the security impact when allowing a container to use the full network stack?
Threat Model
It's a bit overkill but usually it's a good idea to model out the threats that occur rather than saying "Don't do that it's insecure."
Use Case
This sounds like you host multiple instances of the same game, eg Minecraft.
However, mods may introduce new software like MySQL or MongoDB, meaning new attack surfaces open up.
I will assume process control groups (cgroups) are enabled to prevent one container from using full CPU or GPU on the host.
Malicious actors
--net host
enabled. The cheater knows that they can just access the database to change the number of coins stored in the local MySQL database or to set themselves as a moderator on the other instance.Using
--net host
Scenario 1: Crypto miner
Before, with just certain ports exposed, the other instances of the game using a mod with Mongo were safe. You probably have the Mongo port disabled in the public firewall.
However, now all containers can chat with each other, using
--net host
, and have no firewall enabled to prevent each other from maliciously sending traffic to each other.So when the mod is updated to include not just a crypto miner but also a port scanner, the mod scans localhost and finds the open MongoDB. It then takes over the other containers and uses much more CPU/GPU of the host assuming the containers had cgroups applied to them.
If there were no cgroups (process utilization control groups) applied, then the only threat is the additional access.
Scenario 2: Cheater mod backdoor
Before, with just certain ports exposed, the other instances of the game using a mod with MySQL were safe. You probably have the SQL port disabled in the public firewall.
However, now all containers can chat with each other, using
--net host
, and have no firewall enabled to prevent each other from maliciously sending traffic to each other.So when the cheater installs their mod on their instance, they directly access the MySQL server and increase the stored coin count making them rich. Server moderators are confused as there are no game logs showing this access, and they wonder if their server has been hacked.
Summary
In sum,
--net host
doesn't add additional exterior access assuming you have an active firewall, but it does reduce separation between containers that are running on the host, meaning if you're hosting malicious containers you're creating increased potential for non malicious containers to be taken advantage of.See also