[23.0 backport] Clear conntrack entries for published UDP ports#44752
Merged
[23.0 backport] Clear conntrack entries for published UDP ports#44752
Conversation
Conntrack entries are created for UDP flows even if there's nowhere to route these packets (ie. no listening socket and no NAT rules to apply). Moreover, iptables NAT rules are evaluated by netfilter only when creating a new conntrack entry. When Docker adds NAT rules, netfilter will ignore them for any packet matching a pre-existing conntrack entry. In such case, when dockerd runs with userland proxy enabled, packets got routed to it and the main symptom will be bad source IP address (as shown by moby#44688). If the publishing container is run through Docker Swarm or in "standalone" Docker but with no userland proxy, affected packets will be dropped (eg. routed to nowhere). As such, Docker needs to flush all conntrack entries for published UDP ports to make sure NAT rules are correctly applied to all packets. - Fixes moby#44688 - Fixes moby#8795 - Fixes moby#16720 - Fixes moby#7540 - Fixes moby/libnetwork#2423 - and probably more. As a precautionary measure, those conntrack entries are also flushed when revoking external connectivity to avoid those entries to be reused when a new sandbox is created (although the kernel should already prevent such case). Signed-off-by: Albin Kerouanton <albinker@gmail.com> (cherry picked from commit b37d343) Signed-off-by: Cory Snider <csnider@mirantis.com>
neersighted
approved these changes
Jan 5, 2023
akerouanton
approved these changes
Jan 5, 2023
Member
akerouanton
left a comment
There was a problem hiding this comment.
I was going to open a backport PR too. Thanks for doing it 😁
2 tasks
vincentbernat
added a commit
to akvorado/akvorado
that referenced
this pull request
Dec 8, 2025
This is not needed anymore since Docker Engine v23. This version is unmaintained since May 2025 (not that old). See: - moby/moby#44752 - moby/moby#44742 Fix #2153 (in a way)
vincentbernat
added a commit
to akvorado/akvorado
that referenced
this pull request
Dec 8, 2025
This is not needed anymore since Docker Engine v23. This version is unmaintained since May 2025 (not that old). See: - moby/moby#44752 - moby/moby#44742 Fix #2153 (in a way)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Conntrack entries are created for UDP flows even if there's nowhere to route these packets (ie. no listening socket and no NAT rules to apply). Moreover, iptables NAT rules are evaluated by netfilter only when creating a new conntrack entry.
When Docker adds NAT rules, netfilter will ignore them for any packet matching a pre-existing conntrack entry. In such case, when dockerd runs with userland proxy enabled, packets got routed to it and the main symptom will be bad source IP address (as shown by #44688).
If the publishing container is run through Docker Swarm or in "standalone" Docker but with no userland proxy, affected packets will be dropped (eg. routed to nowhere).
As such, Docker needs to flush all conntrack entries for published UDP ports to make sure NAT rules are correctly applied to all packets.
As a precautionary measure, those conntrack entries are also flushed when revoking external connectivity to avoid those entries to be reused when a new sandbox is created (although the kernel should already prevent such case).
Signed-off-by: Albin Kerouanton albinker@gmail.com
(cherry picked from commit b37d343)
Signed-off-by: Cory Snider csnider@mirantis.com
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)