Skip to content

[24.0 backport] libnetwork: fix resolver restore w/ chatty 'iptables -C'#45659

Merged
neersighted merged 1 commit intomoby:24.0from
corhere:backport-24.0/libn/setup-resolver-with-verbose-iptables
May 30, 2023
Merged

[24.0 backport] libnetwork: fix resolver restore w/ chatty 'iptables -C'#45659
neersighted merged 1 commit intomoby:24.0from
corhere:backport-24.0/libn/setup-resolver-with-verbose-iptables

Conversation

@corhere
Copy link
Copy Markdown
Contributor

@corhere corhere commented May 30, 2023

Resolver.setupIPTable() checks whether it needs to flush or create the user chains used for NATing container DNS requests by testing for the existence of the rules which jump to said user chains. Unfortunately it does so using the IPTable.RawCombinedOutputNative() method, which returns a non-nil error if the iptables command returns any output even if the command exits with a zero status code. While that is fine with iptables-legacy as it prints no output if the rule exists, iptables-nft v1.8.7 prints some information about the rule. Consequently, Resolver.setupIPTable() would incorrectly think that the rule does not exist during container restore and attempt to create it. This happened work work by coincidence before 8f5a9a7 because the failure to create the already-existing table would be ignored and the new NAT rules would be inserted before the stale rules left in the table from when the container was last started/restored. Now that failing to create the table is treated as a fatal error, the incompatibility with iptables-nft is no longer hidden.

Switch to using IPTable.ExistsNative() to test for the existence of the jump rules as it correctly only checks the iptables command's exit status without regard for whether it outputs anything.

- What I did

- How I did it

- How to verify it

- Description for the changelog

  • Fixed an issue which prevented DNS resolution from working in live-restored containers on systems using iptables-nft

- A picture of a cute animal (not mandatory but encouraged)

Resolver.setupIPTable() checks whether it needs to flush or create the
user chains used for NATing container DNS requests by testing for the
existence of the rules which jump to said user chains. Unfortunately it
does so using the IPTable.RawCombinedOutputNative() method, which
returns a non-nil error if the iptables command returns any output even
if the command exits with a zero status code. While that is fine with
iptables-legacy as it prints no output if the rule exists, iptables-nft
v1.8.7 prints some information about the rule. Consequently,
Resolver.setupIPTable() would incorrectly think that the rule does not
exist during container restore and attempt to create it. This happened
work work by coincidence before 8f5a9a7
because the failure to create the already-existing table would be
ignored and the new NAT rules would be inserted before the stale rules
left in the table from when the container was last started/restored. Now
that failing to create the table is treated as a fatal error, the
incompatibility with iptables-nft is no longer hidden.

Switch to using IPTable.ExistsNative() to test for the existence of the
jump rules as it correctly only checks the iptables command's exit
status without regard for whether it outputs anything.

Signed-off-by: Cory Snider <csnider@mirantis.com>
(cherry picked from commit 1178319)
Signed-off-by: Cory Snider <csnider@mirantis.com>
@corhere corhere added area/networking Networking kind/bugfix PR's that fix bugs area/networking/dns Networking labels May 30, 2023
@corhere corhere added this to the 24.0.3 milestone May 30, 2023
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@akerouanton akerouanton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@neersighted neersighted merged commit 7861aa7 into moby:24.0 May 30, 2023
@corhere corhere deleted the backport-24.0/libn/setup-resolver-with-verbose-iptables branch May 31, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking/dns Networking area/networking Networking kind/bugfix PR's that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants