PSA: Docker nukes your firewall rules and replaces them with its own.
I use nftables to set my firewall rules. I typically manually configure the rules myself. Recently, I just happened to dump the ruleset, and, much to my surprise, my config was gone, and it was replaced with an enourmous amount of extremely cryptic firewall rules. After a quick examination of the rules, I found that it was Docker that had modified them. And after some brief research, I found a number of open issues, just like this one, of people complaining about this behaviour. I think it's an enourmous security risk to have Docker silently do this by default.
I have heard that Podman doesn't suffer from this issue, as it is daemonless. If that is true, I will certainly be switching from Docker to Podman.
I just set it up last week, it works exceptionally well.
Did you also install podman-docker, make sure that the podman socket was running, and verify that the socket directory referenced in the config files was correct?
Those are the 3 things that I got a bit stuck on. In the end, I RTFM and all was well.
podman-compose is different from docker-compose. It runs your containers in rootless mode. This may break certain containers if configured incorrectly. This is why I suggested podman-docker, which allows podman to emulate docker, and the native docker-compose tool. Then you use sudo docker-compose to run your compose files in rootful mode.
I'm a podman user, but what's the point of using podman if you are going to use a daemon and run it as root? I like podman so I can specifically avoid those things.
I am using it as a migration tool tbh. I am trying to get to rootless, but some of the stuff I host just don't work well in rootless yet, so I use rootful for those containers. Meanwhile, I am using rootless for dev purposes or when testing out new services that I am unsure about.
Podman also has good integration into Cockpit, which is nice for monitoring purposes.
Yeah, it needs those rules for e.g. port-forwarding into the containers.
But it doesnt really 'nuke' existing ones.
I have simply placed my rules at higher priority than normal. Very simple in nftables and good to not have rules mixed between nftables and iptables in unexpected ways.
You should filter as early as possible anyways to reduce ressource usage on e.g. connection tracking.
How come I don't see my previous rules when I dump the ruleset, then? I have my rules written in /etc/nftables.conf, and they were previously applied by running # nft -f /etc/nftables.conf. Now, when I dump the current ruleset with # nft list ruleset, those previous rules aren't there — all I see are Docker's rules.
How come I don't see my previous rules when I dump the ruleset, then? I have my rules written in /etc/nftables.conf, and they were previously applied by running # nft -f /etc/nftables.conf. Now, when I dump the current ruleset with # nft list ruleset, those previous rules aren't there — all I see are Docker's rules.
This is standard, but often unwanted, behavior of docker.
Docker creates a bunch of chain rules, but IIRC, doesn't modify actual incoming rules (at least it doesn't for me) it just will make a chain rule for every internal docker network item to make sure all of the services can contact each other.
Yes it is a security risk, but if you don't have all ports forwarded, someone would still have to breach your internal network IIRC, so you would have many many more problems than docker.
I think from the dev's point of view (not that it is right or wrong), this is intended behavior simply because if docker didn't do this, they would get 1,000 issues opened per day of people saying containers don't work when they forgot to add a firewall rules for a new container.
Option to disable this behavior would be 100x better then current, but what do I know lol
That assumes you're on some VPS with a hardware firewall in front.
Often enough you're on a dedicated server that's directly exposed to the internet, with those iptables rules being the only thing standing between your services and the internet.
What difference does it make if you open the ports yourself for the services you expose, or Docker does it for you? That's all that Docker is meant to do, act as convenience so you don't have to add/remove rules as the containers go up/down, or remember Docker interfaces.
If by any chance you are making services listen on 0.0.0.0 and covering them up with a firewall that's very bad practice.
Yes it is a security risk, but if you don’t have all ports forwarded, someone would still have to breach your internal network IIRC, so you would have many many more problems than docker.
I think from the dev’s point of view (not that it is right or wrong), this is intended behavior simply because if docker didn’t do this, they would get 1,000 issues opened per day of people saying containers don’t work when they forgot to add a firewall rules for a new container.
My problem with this, is that when running a public facing server, this ends up with people exposing containers that really, really shouldn't be exposed.
Resulting in exposed services. Feel free to look at shodan or zoomeye, internet connected search engines, for exposed versions of this service. This service is highly dangerous to expose, as it gives people an in to your system via the docker socket.
But... You literally have ports rules in there. Rules that expose ports.
You don't get to grumble that docker is doing something when you're telling it to do it
Dockers manipulation of nftables is pretty well defined in their documentation. If you dig deep everything is tagged and natted through to the docker internal networks.
As to the usage of the docker socket that is widely advised against unless you really know what you're doing.
My solution to this has been to not forward the ports on individual services at all. I put a reverse proxy in front of them, refer to them by container name in the reverse proxy settings, and make sure they're on the same docker network.
So uh, I just spun up a vps a couple days ago, few docker containers, usual security best practices... I used ufw to block all and open only ssh and a couple others, as that's what I've been told all I need to do. Should I be panicking about my containers fucking with the firewall?
Don't know what it's actually doing, I'm just learning how to work with nftables, but I saved that link in case oneday I want to manage the iptables rules myself :)
IIRC, doesn’t modify actual incoming rules (at least it doesn’t for me)
How come I don't see my previous rules when I dump the ruleset, then? I have my rules written in /etc/nftables.conf, and they were previously applied by running # nft -f /etc/nftables.conf. Now, when I dump the current ruleset with # nft list ruleset, those previous rules aren't there — all I see are Docker's rules.
ofcourse docker desktop is not affected because it's a vm running docker running on your computer. the nftables inside the container are modified by docker