-
Notifications
You must be signed in to change notification settings - Fork 18.8k
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
Conversation
343c364
to
e49e7e2
Compare
8000 td> | 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) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto :)
There was a problem hiding this comment.
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>
e49e7e2
to
4d8cff7
Compare
There was a problem hiding this 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.) |
There was a problem hiding this comment.
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.
- What I did
gateway_mode=routed
#49509If 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