8000 Don't skip DNAT for a routed network without userland-proxy by robmry · Pull Request #49577 · moby/moby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't skip DNAT for a routed network without userland-proxy #49577

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

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

robmry
Copy link
Contributor
@robmry robmry commented Mar 4, 2025

- What I did

If the userland-proxy is running, packets from one bridge network addressed to the host port are not DNAT'd - so that docker-proxy can pick them up, and therefore the packet bypasses the network isolation rules.

Without the userland-proxy, there's no way for a packet from one bridge network to bypass the network isolation rules. So, in this case, DNAT is not skipped - and that at-least allows packets originating from the network that published the port to access the host port.

Commit 0546d90 improved support for routed mode networks (allowing nat-mode networks access to containers in routed-mode networks, as well as just remote access).

That commit changed the "SKIP DNAT" logic, making sure DNAT was skipped for a routed-mode network if the userland-proxy was enabled (so, containers in routed mode networks could access ports published by other networks).

But, it still skipped DNAT for a routed mode network if the userland proxy was disabled - packets from the routed mode network aimed at any other network would be dropped by the network isolation rules anyway, and containers in a routed mode network don't need access to ports published from that network (because, by definition, there can't be any).

However, network isolation rules can be worked-around with a rule in the DOCKER-USER chain, but the SKIP DNAT rule is harder to deal with.

- How I did it

For routed-mode, only skip DNAT if the userland-proxy is enabled (just like nat-mode networks).

- How to verify it

New regression test.

< 8000 strong>- Human readable description for the release notes

- Do not skip DNAT for packets originating in a `gateway_mode=routed` network.

@robmry robmry added this to the 28.0.2 milestone Mar 4, 2025
@robmry robmry self-assigned this Mar 4, 2025
@robmry robmry force-pushed the routed_no_skip_dnat branch 2 times, most recently from 343c364 to e49e7e2 Compare March 5, 2025 10:06
@robmry robmry marked this pull request as ready for review March 5, 2025 12:31
@robmry robmry requested review from akerouanton and vvoland March 5, 2025 12:32
Comment on lines 589 to 611
for _, ipamCfg := range insp.IPAM.Config {
url := "http://" + net.JoinHostPort(ipamCfg.Gateway, "8080")
res := container.RunAttach(ctx, t, c,
container.WithNetworkMode(routedNetName),
container.WithCmd("wget", "-O-", "-T3", url),
)
if tc.expResponse {
// 404 Not Found means the server responded, but it's got nothing to serve.
assert.Check(t, is.Contains(res.Stderr.String(), "404 Not Found"), "url: %s", url)
} else {
assert.Check(t, is.Contains(res.Stderr.String(), "download timed out"), "url: %s", url)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done.

If the userland-proxy is running, packets from one bridge network
addressed to the host port are not DNAT'd - so that docker-proxy
can pick them up, and therefore the packet bypasses the network
isolation rules.

Without the userland-proxy, there's no way for a packet from one
bridge network to bypass the network isolation rules. So, in this
case, DNAT is not skipped - and that at-least allows packets
originating from the network that published the port to access
the host port.

Commit 0546d90 improved support for routed mode networks (allowing
nat-mode networks access to containers in routed-mode networks, as
well as just remote access).

That commit changed the "SKIP DNAT" logic, making sure DNAT was
skipped for a routed-mode network if the userland-proxy was enabled
(so, containers in routed mode networks could access ports published
by other networks).

But, it still skipped DNAT for a routed mode network if the userland
proxy was disabled - packets from the routed mode network aimed at
any other network would be dropped by the network isolation rules
anyway, and containers in a routed mode network don't need access to
ports published from that network (because, by definition, there
can't be any).

However, network isolation rules can be worked-around with a rule
in the DOCKER-USER chain, but the SKIP DNAT rule is
8000
 harder to deal
with.

So, for routed-mode, only skip DNAT if the userland-proxy is
enabled (just like nat-mode networks).

Signed-off-by: Rob Murray <rob.murray@docker.com>
@robmry robmry force-pushed the routed_no_skip_dnat branch from e49e7e2 to 4d8cff7 Compare March 10, 2025 17:15
Copy link
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

// If the userland proxy is disabled, don't skip, so packets will be DNAT'd. That will
// enable access to ports published by containers in the same network. But, the INC rules
// will block access to that published port from containers in other networks. (However,
// users may add a rule to DOCKER-USER to work around the INC rules if needed.)
Copy link
Member

Choose a reason for hiding this comment

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

As shared privately, it'd be best to not require users to mess with their DOCKER-USER chain to enable that use-case. But, as you pointed out, it's too much risk for a patch release, and probably not worth implementing in iptables.

@akerouanton akerouanton merged commit d2ad7c3 into moby:master Mar 13, 2025
149 checks passed
@robmry robmry deleted the routed_no_skip_dnat branch May 29, 2025 18:51
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.

28.0.0: host exposed ports cannot be accessed from other bridge network with gateway_mode=routed
3 participants
0