-
Notifications
You must be signed in to change notification settings - Fork 9
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
World to host not working (& host to container) #705
Comments
Hm, having set the device explicitly to eth0, I see now some rules (yeah, I tried other containers, too, but nothing works) and nftables seems to reflect it, but no change in behaviour. Apart from that I see that journalctl, despite logs, does not show the incoming 9443 packets anymore.
|
Ok, my log was stupid because now I want to log FORWARD of course. And there I see something:
Well, this seems fine. The packet is filtered towards the docker container but for some reason nothing happens there hmmm... OUT is a bit strange though, this is some veth0 interface because this whole thing runs on a KVM virtual machine... (not managed by me but my provider where I buy the hosting solution, was not a problem so far though). |
Ok, I needed to also add "backend_defaults"... I somehow thought this would not be needed as it was default anyways. Also in your docs you describe some sample nftables.conf file... This is a REALLY bad one because it will also not allow pinging out or working with established connections. Maybe replacing it with something with sensible rules would make more sense? I suggest:
although it's certainly incomplete because ping6 does not work yet... anyways |
Hi @MichaelVoelkel, thanks for reaching out. I'll try to go through your various points one-by-one, although some might overlap with others. 🙂
Every Docker container you run has to be attached to some kind of Linux network interface, at least assuming it should be able to connect to the network (which it does unless you specify Given this fact that a Docker container always will be associated with a virtual bridge network interface, for firewalling to work, nftables has to know which network interface packets are destined for or coming from and thus DFW has to know too, for it to be able to create rules with the correct constraints.
Unless you run DFW with the If you have started your applications before you started DFW, DFW will still automatically apply all relevant rules, because it also applies all rules whenever it starts up.
I am fairly certain that you are using it, even if you don't think you are: the $ cat "$(systemctl show -P FragmentPath nftables.service)" | grep '^Exec'
ExecStart=/usr/sbin/nft -f /etc/nftables.conf
ExecReload=/usr/sbin/nft -f /etc/nftables.conf
ExecStop=/usr/sbin/nft flush ruleset This means that the systemd-unit
If the unit is active and enabled, it works as I have described above. The reason I'm going into so much detail here: my personal suggestion for setting up nftables is to configure your base-rules in Following is the
A few things to note in the
You are correct that the package will be dropped. As shown above I add the
Do I understand correctly that things work now after you have added One thing I did notice in the rulesets you have posted is that DFW does not hook itself into the [backend_defaults]
custom_tables = { name = "filter", chains = ["input", "forward"] } You can find more details on this field in the documentation here, but the gist of it is this: DFW has to be able to act on traffic when it traverses any one of the
Assuming DFW has run and is instructed to attach to the existing tables it would work: the Regarding established/related packets: I agree, this should be part of the default config. Regarding allowing incoming pings: In summary, the final more-than-minimal configuration that works well for me is this:
Tasks:
|
Hi! Thanks for your great, long answer. Yeah, now everything works, maybe apart from locally accessing containers, BUT I will try out your And all sounds really interesting what you write. Of course, it's true that nftables is used as base. And yes to:
My default policy clearly is drop. And by the way, as for pings, I was just talking to pings going outside. I agree that inside pings are a different story. As for the network thingy, I was just thinking, if the docker container only has one network, dfw could theoretically read it from it and use it, as a convenience idea. But yeah, that's not necessarily needed. All in all, I need to say: your solution is great!! Getting nftables running with docker is normally not doable nicely... And it should really be a firewall solution that sits in its own docker container to have it maintainable. This seems like the best practice. And your repo offers exactly this solution. So thanks a lot! |
Hi,
being on Debian12, I switched to NFT now again. The basic configuration is just from the docs,
/etc/nftables.conf
:/etc/nftables
exists but I don't use it. I hope it makes no trouble.I can connect to ssh and nothing else works, so far so good.
Now I have portainer running on 9443 where I could before have world access and host access (it has the ports mapping of 9443:9443, so I should access it via localhost, e.g.,
nc -vv localhost 9443
). As connection times out both ways, I'd assume that the package is dropped.My
rules.toml
is: (yeah, small, nothing else)I run
dfw
currently like this to see the logs:And yeah, stuff like
nc
etc. I do via a second ssh session, so I keep it open. :)So, my problem clearly is that I cannot connect but would hope/expect to do so.
Some more information / pecularities / questions / comments:
sudo nft list ruleset
does not seem to show any rules that have been created, is this expected?docker inspect
) that I calledportainer_network
and which you see in my rules-file now.Probably I messed up something very basic. I tried also to make sure that old iptables is disabled but
sudo systemctl disable iptables
told me it did not even know iptables.Hm, when I reset nft rules to /etc/nftables.conf, it's empty though, when I start dfw, it fills up to the config shown above, so it seems to do something.
The text was updated successfully, but these errors were encountered: