Skip to content

[RFC] libnetwork/iptables: preserve existing forward rules instead of re-creation#43585

Closed
azat wants to merge 1 commit intomoby:masterfrom
azat-archive:iptables-preserve-existing-forward-rules
Closed

[RFC] libnetwork/iptables: preserve existing forward rules instead of re-creation#43585
azat wants to merge 1 commit intomoby:masterfrom
azat-archive:iptables-preserve-existing-forward-rules

Conversation

@azat
Copy link
Copy Markdown

@azat azat commented May 12, 2022

Forwarding to DOCKER-USER chain is racy, because it is always re-created:

time="2022-05-11T20:03:03.915890496Z" level=debug msg="/usr/sbin/iptables, [--wait -D FORWARD -j DOCKER-USER]"
time="2022-05-11T20:03:04.051254185Z" level=debug msg="/usr/sbin/iptables, [--wait -I FORWARD -j DOCKER-USER]"

This is not very convenient since if you are using DOCKER-USER chain
to limit network between containers, for a short period of time rules
from DOCKER-USER will not be applied.

So replace -D/-I with -C/-I, seems that there should not be any issues
with this, although note that, after this change rules will not
re-queued at the beginning of the FORWARD chain
.

P.S. I've also tried to overcome this issue with creating separate
chain, but since docker users -I, my chain will goes after docker rules
and it will not receive any packets.

…eation

Forwarding to `DOCKER-USER` chain is racy, because it is always re-created:

    time="2022-05-11T20:03:03.915890496Z" level=debug msg="/usr/sbin/iptables, [--wait -D FORWARD -j DOCKER-USER]"
    time="2022-05-11T20:03:04.051254185Z" level=debug msg="/usr/sbin/iptables, [--wait -I FORWARD -j DOCKER-USER]"

This is not very convenient since if you are using `DOCKER-USER` chain
to limit network between containers, for a short period of time rules
from `DOCKER-USER` will not be applied.

So replace -D/-I with -C/-I, seems that there should not be any issues
with this, although note that, **after this change rules will not
re-queued at the beginning of the FORWARD chain**.

P.S. I've also tried to overcome this issue with creating separate
chain, but since docker users -I, my chain will goes after docker rules
and it will not receive any packets.

Signed-off-by: Azat Khuzhin <[email protected]>
@azat
Copy link
Copy Markdown
Author

azat commented May 12, 2022

Actually, this will not work, since it will place DOCKER-USER chain after other rules:

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   59  9222 DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  *      br-44b019ee7ea4  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
   59  9222 DOCKER     all  --  *      br-44b019ee7ea4  0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  br-44b019ee7ea4 !br-44b019ee7ea4  0.0.0.0/0            0.0.0.0/0           
   59  9222 ACCEPT     all  --  br-44b019ee7ea4 br-44b019ee7ea4  0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0           
   24  1236 DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0

And so it will not receive those packets.

@azat azat closed this May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant