Skip to content

[23.0 backport] Check iptables options before looking for ip6tables binary#44727

Merged
thaJeztah merged 4 commits into
moby:23.0from
thaJeztah:23.0_backport_fix_42127
Jan 9, 2023
Merged

[23.0 backport] Check iptables options before looking for ip6tables binary#44727
thaJeztah merged 4 commits into
moby:23.0from
thaJeztah:23.0_backport_fix_42127

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented Dec 31, 2022

backports:

⚠️ I had a merge conflict in the second commit of #43060, as #43793 was back ported to 23.0 (through #43813), and it looks like git was smart enough to apply af7236f on the master branch (without rebase), but applying the same on the 23.0 branch cause a conflict, and would remove the patch from #43813

ch33hau and others added 4 commits December 31, 2022 18:07
- use local variables for chains instead of sharing global variables
- make createNewChain a t.Helper

Signed-off-by: Chee Hau Lim <[email protected]>
(cherry picked from commit a2cea99)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
iptables package has a function `detectIptables()` called to initialize
some local variables. Since v20.10.0, it first looks for iptables bin,
then ip6tables and finally it checks what iptables flags are available
(including -C). It early exits when ip6tables isn't available, and
doesn't execute the last check.

To remove port mappings (eg. when a container stops/dies), Docker
first checks if those NAT rules exist and then deletes them. However, in
the particular case where there's no ip6tables bin available, iptables
`-C` flag is considered unavailable and thus it looks for NAT rules by
using some substring matching. This substring matching then fails
because `iptables -t nat -S POSTROUTING` dumps rules in a slighly format
than what's expected.

For instance, here's what `iptables -t nat -S POSTROUTING` dumps:

```
-A POSTROUTING -s 172.18.0.2/32 -d 172.18.0.2/32 -p tcp -m tcp --dport 9999 -j MASQUERADE
```

And here's what Docker looks for:

```
POSTROUTING -p tcp -s 172.18.0.2 -d 172.18.0.2 --dport 9999 -j MASQUERADE
```

Because of that, those rules are considered non-existant by Docker and
thus never deleted. To fix that, this change reorders the code in
`detectIptables()`.

Fixes moby#42127.

Signed-off-by: Albin Kerouanton <[email protected]>
(cherry picked from commit af7236f)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
The former was doing some checks and logging warnings, whereas
the latter was doing the same checks but to set some internal variables.
As both are called only once and from the same place, there're now
merged together.

Signed-off-by: Albin Kerouanton <[email protected]>
(cherry picked from commit 205e527)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
iptables -C flag was introduced in v1.4.11, which was released ten
years ago. Thus, there're no more Linux distributions supported by
Docker using this version. As such, this commit removes the old way of
checking if an iptables rule exists (by using substring matching).

Signed-off-by: Albin Kerouanton <[email protected]>
(cherry picked from commit 799cc14)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Copy Markdown
Member Author

@corhere @neersighted ptal

@thaJeztah
Copy link
Copy Markdown
Member Author

Let me bring this one in 👍

@thaJeztah thaJeztah merged commit f3761a5 into moby:23.0 Jan 9, 2023
@thaJeztah thaJeztah deleted the 23.0_backport_fix_42127 branch January 9, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants