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

Jump to DOCKER-INGRESS from DOCKER-FORWARD #49538

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

robmry
Copy link
Contributor

@robmry robmry commented Feb 24, 2025

- What I did

In 28.0.0, the iptables jump to DOCKER-INGRESS could get out of place, fixed that.

Introduced in commit 0ef2b24 - the intention was that jumps to DOCKER-USER, DOCKER-ISOLATION-STAGE-1 and DOCKER-INGRESS no longer needed to be deleted and re-created at the top of the FORWARD chain each time a new network was added. That works for the other chains, because on daemon restart they're re-created. However, the jump to DOCKER-INGRESS is not re-created (shuffled back to the top of the table) if the DOCKER-INGRESS chain already existed. So, it ended up in the wrong place in the FORWARD chain. It worked in 27.x, because arrangeIngressFilterRule was called when the ingress network was re-created on startup.

- How I did it

A jump to DOCKER-INGRESS chain is only created when Swarm needs it. That's always after jumps to DOCKER-USER and DOCKER-FORWARD have been inserted at the top of the FORWARD chain. The DOCKER-INGRESS rule needs to be between those two other jumps.

Placing the jump to DOCKER-INGRESS at the top of the DOCKER-FORWARD chain puts it in the right place, without needing to shuffle any other rules around when it's added.

- How to verify it

With 27.5.1, created a swarm service with a published port (docker service create -p 8080:80 nginx), checked that the jump to DOCKER-INGRESS followed the jump to DOCKER-USER in the FORWARD chain. Stopped the daemon and started one built with this change - waited until the swarm service restarted, checked that the jump to DOCKER-INGRESS had been removed from the FORWARD chain and added to the top of DOCKER-FORWARD.

I'll follow up with a regression test, but that doesn't need to block 28.0.1.

- Human readable description for the release notes

Fix an issue with Swarm ingress, caused by incorrect ordering of iptables rules.

A jump to DOCKER-INGRESS chain is only created when Swarm needs
it. That's always after jumps to DOCKER-USER and DOCKER-FORWARD
have been inserted at the top of the FORWARD chain. The
DOCKER-INGRESS rule needs to be between those two other jumps.

Placing the jump to DOCKER-INGRESS at the top of the DOCKER-FORWARD
chain puts it in the right place, without needing to shuffle any
other rules around when it's added.

Signed-off-by: Rob Murray <rob.murray@docker.com>
@robmry robmry marked this pull request as ready for review February 25, 2025 17:19
Comment on lines +373 to +375
// the daemon older than 28.0.1.
// FIXME(robmry) - should only do this once, on startup.
if iptable.Exists(iptables.Filter, "FORWARD", "-j", ingressChain) {
Copy link
Member

Choose a reason for hiding this comment

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

VERY unlikely to be relevant in this spot and no need to update 👈 , but Go (GoDoc) has some extra semantics for "special" comments (most notably Deprecated: but ISTR also to some extent TODO / FIXME comments); to prevent such comments from being considered part of the comment itself, they expect there to be an empty (comment-)line before them, and for them to be last in the comment block, e.g.;

Suggested change
// the daemon older than 28.0.1.
// FIXME(robmry) - should only do this once, on startup.
if iptable.Exists(iptables.Filter, "FORWARD", "-j", ingressChain) {
// the daemon older than 28.0.1.
//
// FIXME(robmry) - should only do this once, on startup.
if iptable.Exists(iptables.Filter, "FORWARD", "-j", ingressChain) {

In this case it unlikely matters as it's a comment internal to the function (which Go itself doesn't really bother with), but I try to stick to that convention when writing these, also to make sure IDEs can spot them (which tend to try to follow Go conventions, although usually are slightly more permissive).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thank you ... will do for next time.

I should have found somewhere better to put that delete, but this seemed safest right now - it mustn't happen on a live-restore (if swarm supports that), and I didn't want to miss any other special case. It can be tidied up as we shift over to nftables.

Copy link
Contributor

@vvoland vvoland 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
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.

code changes LGTM

Let me bring this one in; my only comment was more a general "tip", nothing specific to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v28 iptables DROPS all packages
4 participants