-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker and ufw serious problems #4737
Comments
Ufw is only setting things in the |
@Soulou would you recommend adding to mangle or nat? edited previous comment after some research |
In my case I wanted to only allow a specific IP to connect to the exposed port. I've managed to do this with this rule. It drops all connections to port
|
@honi In Docker 1.5 (maybe 1.4?) there were several iptables changes. Can you verify if this is still a problem with 1.5? |
@cpuguy83 I can confirm that this is still a problem with Docker 1.6 Adding |
+1, still a problem with Docker 1.6 |
So what is the story here? With Docker version 1.7.0, build 0baf609 on Ubuntu 14 this is still completely broken. Also the installaton instructions on https://docs.docker.com/installation/ubuntulinux/ have a section "Enable UFW forwarding" which appears to be unnecessary. Anyone installing docker on an Ubuntu box exposes any forwarded ports from their containers to the outside world, and even worse looking at the ufw rules gives no hints that this is occurring which is needless to stay pretty bad. |
Also with Docker 1.7 here. My experience is that Docker+UFW can facilitate two scenarios. The first scenario and default behavior indeed exposes all mapped ports to the outside world; UFW cannot filter access to the containers. Alternatively when setting the In my opinion a sensible default behavior for docker would be how it behaves currently with |
I don't have a problem getting out. Did you try: ufw allow in on docker0 |
@newhook |
I have been experimenting with this a few hours now. I think I got it figured out.
The FORWARD chain does need policy set to ACCEPT if you have What you need for a setup that allows filtering with UFW, inter container networking and outbound connectivity is
|
You are indeed correct! After a reboot communication is gone. Those rules seem to sort everything out. Thanks very much! |
with this setup its not possible anymore to access exposed ports from within a container:
|
@dakky I can't reproduce your issue. I have no issues with inter container communication. I suggest making sure you expose the port in your Dockerfile. Also try flushing your iptables rules and delete all user-defined chains before configuring and enabling UFW. In any case it would be good if someone from the Docker team can verify that the configuration I propose makes sense. |
Hi, any update on this? I can't find any official source how to fix this.
.1 I can reach Internet from container Am I missing something here? 10x |
I had managed to fix this through iptables
|
This is still a problem. Is there a clear fix available? I don't expect a built-in solution. But maybe some |
Guys, this is a serious security issue. Why is there no hint in the documentation for it? Only by accident I found out, that my MySQL Port is wide open to the world. I absolutely didn't expect that as I've used |
For the record, the solution from @VascoVisser worked for me with docker V1.10. Here are the files I had to change:
UPDATE: On Ubuntu 16.04 things are different, because docker is started by systemd, so
and issue |
@mikehaertl I want to mention that this is not really an issue just with UFW, as it is just another layer over iptables. This is a general problem in my opinion. |
@lenovouser Thing is, that the documentation has some recommendation which sounds like "do this and everything is fine with ufw". But that's definitely not the case, so there should be big warning signs there. |
The only thing that helped me: https://p1ngouin.com/posts/how-to-manage-iptables-rules-with-ufw-and-docker |
I get: ERROR: Could not load logging rules after |
most recent discussion in #22054 |
I did exactly this test on my VPS with a PUBLIC-IP (202.xx.xxx.xxx), i cannot reproduce the behaviour why?
Any Idea? |
Based on chaifeng/ufw-docker#53 after removing these lines: -A ufw-docker-logging-deny -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW DOCKER BLOCK] " I can confirm the behaviour that the published port 28081 is open after allowing port 4000. |
I did not do any changes to default ufw or docker. And added rule |
With the default install of UFW and Docker, I was able to ensure that external IPs are not able to connect to the published ports of Docker containers via the following changes. I amended the
After saving the file, run
What is important to note is:
Does anybody see any issues with the above setup? |
Just wanted to update with some thoughts on changes we discussed amongst maintainers: #45076 sends a warning to clients on container create when port forwards are requested for anything other than localhost with an option to disable via env var (on the daemon). Also planning to abstract port forwarding logic and provide an implementation that uses IPVS NAT instead of iptables. This would mean dockerd is not poking holes in the firewall. It would be opt-in to not break existing users. After this interface is well tested we plan to make this available as a plugin (exactly how is not determined yet, maybe an API over a unix socket or just a simple call to a host binary). |
I created a discussion about what's going on with custom iptables rules (whether created through ufw or manually) and what we can do to improve that. It's available here: |
It's unbelievably irresponsible of Docker to have not fixed this major security gotcha for 9 years. Strange... |
@cpuguy83 I don't think anyone is relying on such an extremely unexpected behavior, and even if they are relying on it unknowingly, they shouldn't be. I would argue this is one of those cases where it's definitely okay to break the current behavior, when the current behavior can be considered a blatant bug by any reasonable definition: why would a program (e.g. Docker) punch holes in the firewall?! It should not be opt-in IMO, just fix it as a default. This is the sort of thing that plagues many people without them even being aware of it, therefore it's precisely the kind of thing you want to have 'fixed by default', so to speak. |
@aradalvand I would expect most people to be relying on this. Can we make the current behavior opt-in at some point? Probably, but we need the to have alternative implementations available and well tested before doing so. |
Thanks a lot! In my case, this is exactly what I needed. |
Came here because I got kdevtmpfsi malware as a result of this. edit: To elaborate a bit. If you configure ufw to only allow ssh, the expectation is that only ssh will be allowed regardless of any docker configuration. Yes, my postgres password should have not been postgres, but this was a toy app and the fact that I got malware actually did not matter. I just remade the container. But it is exposed to me the fact that blocking everything but ssh did in fact not block everything but ssh. In a production scenario maybe I wouldn't have got hit because I'd have a better password, but I would have been blissfully unaware of the fact that my postgres server was being exposed to the internet when I thought it wasn't, and that's bad! Maybe this is in fact a ufw issue, I don't know. I'm just here because this where the conversation led me to when researching the problem. This is some pretty dangerous stuff. |
Yeah... me too... all my databases were stolen und a message from some russian guy wanting btc was left... Thank god that there were no data in the tables... |
GREAT WORK TOU REALLY HELPED ME OUT TODAY |
Are there any plans to actually make docker play nice with firewall rules and host's localhost and spare us developers some already huge cognitive load using crutches instead of real solutions and trying to memorize all the madhouse of incompatible permutations of rootless vs rooful, |
Having installed ufw and blocking all incoming traffic by default (
sudo ufw default deny
) by running docker images that map the ports to my host machine, these mapped docker ports are accessible from outside, even though they are never allowed to be accessed.Please note that on this machine
DEFAULT_FORWARD_POLICY="ACCEPT"
as described on this page http://docs.docker.io/en/latest/installation/ubuntulinux/#ufw has not been enabled and the propertyDEFAULT_FORWARD_POLICY="DROP"
is still set.Any ideas what might causing this?
Output of ufw status:
Here is the output of my rabbitmq via
docker ps
:Nmap test:
General infos:
The text was updated successfully, but these errors were encountered: