Closed robby-d closed 1 year ago
Hi, thanks for the report. I see what's going on here. https://github.com/shinebayar-g/ufw-docker-automated/blob/main/main.go#L64 this code is syncing existing containers, but only executed on the startup. I should call the function on reconnect as well.
PartOf
is a nice workaround. Probably worth mentioning on the docs as well.
Ah, I see that now, great. Seems like an easy fix.
Yep, will upgrade dependencies and cleanup some things and cut a new release this weekend.
Cool deal. One minor nit: would be good to have instructions for building from source in the README. Wasn't hard, but not being familiar with building Go code, it took a bit of Googling.
That's fair. Do you prefer to build yourself instead of downloading from releases page?
Yeah, given the level of integration into the system (running as root
with interaction with docker containers) I prefer to compile directly from the source code on Github, which I give a quick review to. One less thing to worry about. :)
Sorry if I'm joining in here. I also have problems with Ubuntu 22.04 since short. Unfortunately, the workaround does nothing for me. No more rules are added.
./ufw-docker-automated
only shows
2023/01/20 20:32:08 ufw-docker-automated: Connected to the Docker Engine.
and
sudo journalctl -u ufw-docker-automated -f
shows only this, even on a container restart
Jan 20 05:52:45 nas sudo[635511]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jan 20 05:52:46 nas sudo[635511]: pam_unix(sudo:session): session closed for user root
Jan 20 20:27:40 nas systemd[1]: Stopping Ufw docker automated...
Jan 20 20:27:40 nas systemd[1]: ufw-docker-automated.service: Deactivated successfully.
Jan 20 20:27:40 nas systemd[1]: Stopped Ufw docker automated.
Jan 20 20:27:40 nas systemd[1]: Started Ufw docker automated.
Jan 20 20:28:45 nas ufw-docker-automated[2957078]: 2023/01/20 20:28:45 ufw-docker-automated: Connected to the Docker Engine.
Jan 20 20:28:45 nas sudo[2966573]: root : PWD=/ ; USER=root ; COMMAND=/usr/sbin/ufw show added
Jan 20 20:28:45 nas sudo[2966573]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Jan 20 20:28:45 nas sudo[2966573]: pam_unix(sudo:session): session closed for user root
Hey guys, sorry that I didn't fix this sooner. I just tagged a new release v0.11.0 Tested the behavior with sudo service docker restart
, this time ufw-docker-automated will properly sync with docker containers again on reconnect. Also implemented a new logging library for easier debugging.
No problem, thank you for the update! I’ll give it a try shortly and let you know if any problems.
Unrelated, I was sometimes seeing an issue with duplicate rules — i.e. rules would sometimes not be deleted when the container was stopped and restarted and you’d end up with two (or more) of the same rule after awhile. Might have just been an issue with named rules (where some title was set after the rule port number)…I’ll see if I can reproduce it and post an issue if so.
Sounds good. In general ufw
itself doesn't accept duplicate rules, so I'm currently relying on that behavior. If I receive duplicate rule event from Docker socket, I'm simply forwarding them to ufw
itself. If you're seeing duplicates, perhaps they're different containers? Other than that it shouldn't be possible to see duplicates.
Running into an issue on an Ubuntu 22.04 x64 host (using the latest
ufw-docker-automated
, built from source onmaster
) where the ufw container rules established is deleted and not properly recreated on aservice docker restart
/systemctl restart docker
command.E.g. - prior to
docker service restart
:After
sudo service docker restart
:Running
service ufw-docker-automated restart
will successfully re-create the custom rules.It seems that
ufw-docker-automated
has code to detect a disconnect from tcp. Here's what I see in/var/log/syslog
after thedocker
service restarts:However, inbound rules are not correctly readded post-service restart. Once I manually restart the
ufw-docker-automated
service/var/log/syslog
shows:Not familiar with Go code, but it seems like the service tries to reconnect to the Docker UNIX domain socket (e.g.
/var/run/docker.sock
) but perhaps binds to an old or inactive version of it?Anyhow, I "fixed" this issue by adding
PartOf=docker.service
to mysystemd
ufw-docker-automated.service
file, as so:A better fix might be more robust reconnection detection in the code, perhaps.