Skip to content
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

Avoid duplicate rules #38

Closed
shinebayar-g opened this issue Dec 26, 2021 · 10 comments
Closed

Avoid duplicate rules #38

shinebayar-g opened this issue Dec 26, 2021 · 10 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@shinebayar-g
Copy link
Owner

Right now program is relying on ufw for duplicate entries handling. Duplicate rules are produced on some scenario like defining allowed ports specifically.

@shinebayar-g
Copy link
Owner Author

shinebayar-g commented Dec 27, 2021

After #40 program will produce even more duplicate rules on container startup to sync the rules, that's fine. However, I'm not sure I should even consider duplication check for couple of reasons.

  1. ufw already handles duplication correctly. This is an idempotent operation.
  2. If I have to check duplicate ufw rules, first I have to get the ufw rules, then parse them through to check for duplication, then create ufw rule if it doesn't exist. Or I could probably introduce additional persistent storage like sqlite for O(1) lookup & other information tracking purposes. This path will introduce little bit overhead than simply relying on ufw for handling duplication.

For now, I consider this is not necessary to implement.

@pannal
Copy link

pannal commented Jul 28, 2023

So this is entirely normal and can be ignored? When using ufw-docker manually, those duplicates don't get created.

[ 6] 172.18.0.3 443/tcp         ALLOW FWD   Anywhere                   # xxxx:526635d3c7a4
[ 7] 172.18.0.3 80/tcp          ALLOW FWD   Anywhere                   # xxxx:526635d3c7a4
[ 8] 172.18.0.6 32400/tcp       ALLOW FWD   Anywhere                   # yyyy:7ff829f4fb0c
[ 9] 172.18.0.9 443/tcp         ALLOW FWD   Anywhere                   # xxxx:526635d3c7a4
[10] 172.18.0.9 80/tcp          ALLOW FWD   Anywhere                   # xxxx:526635d3c7a4
[11] 172.18.0.7 32400/tcp       ALLOW FWD   Anywhere                   # yyyy:7ff829f4fb0c

@shinebayar-g
Copy link
Owner Author

shinebayar-g commented Jul 28, 2023

Hi @pannal , In your example your rules are not duplicate, they are all unique. IIRC I was talking about exact duplicate rule check when adding ufw rules. For example, when adding a new rule, ufw-docker-automated doesn't check if that exact ufw rule exists or not, it just adds and leaves duplication check to ufw. I don't quite recall at which event duplication was happening though.

Does your pod have multiple networks? I am curious how you ended up with such rules.

[ 8] 172.18.0.6 32400/tcp       ALLOW FWD   Anywhere                   # yyyy:7ff829f4fb0c
[11] 172.18.0.7 32400/tcp       ALLOW FWD   Anywhere                   # yyyy:7ff829f4fb0c

@pannal
Copy link

pannal commented Jul 28, 2023

I've got these:

docker network ls
NETWORK ID     NAME            DRIVER    SCOPE
9e8edc3fc3c0   bridge          bridge    local
85563272b1fc   host            host      local
61de4892a059   none            null      local
eda632a15479   stuff_default   bridge    local

stuff_default being the only one I actively use in docker compose.

The machine itself has only one NIC.

@shinebayar-g
Copy link
Owner Author

shinebayar-g commented Jul 28, 2023

👍 does your container has multiple IPs?

@pannal
Copy link

pannal commented Jul 28, 2023

No it doesn't. What you see there is what came after a reboot of the host machine. The xxxx container had the IP .3 before the reboot and .9 after the reboot.

The second set of forwards were added automatically added to ufw upon reboot.

@shinebayar-g
Copy link
Owner Author

shinebayar-g commented Jul 28, 2023

Got it. Are you on latest version v0.11.0? If yes and if it's happening I think we should consider it a bug. If you could provide a reliable instructions to reproduce it I can try to fix it.

@pannal
Copy link

pannal commented Jul 28, 2023

Well, I've installed it a couple of hours ago, so I'm pretty sure it's the latest one. (4ef0c7306a06b0d04403297c1848608ea8ad8018 /usr/local/bin/ufw-docker-automated)

I've just tried to reproduce it. I did docker-compose down, to take all the containers down (and the "current" correct rules), then deleted the incorrect ones.

After docker-compose up -d the correct rules get created. Once I reboot, the IPs of the containers change, and I get duplicate rules again.

@ikrevem
Copy link

ikrevem commented Jan 27, 2024

@pannal Have you managed to solve this issue? I'm having the exact same problem: when I reboot (or shutdown) the host, the IPs of the containers change and new rules get added without deleting the old ones.

Thanks :)

@pannal
Copy link

pannal commented Jan 27, 2024

Unfortunately not, no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants