-
Notifications
You must be signed in to change notification settings - Fork 18.9k
libnet/d/bridge: port mappings: filter by input iface #48721
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
akerouanton
merged 1 commit into
moby:master
from
akerouanton:45610-filter-by-input-iface
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
147 changes: 147 additions & 0 deletions
147
integration/network/bridge/iptablesdoc/generated/usernet-portmap-hostip.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| ## Container on a user-defined network, with a port published on a specific HostIP | ||
|
|
||
| Adding a network running a container with a mapped port, equivalent to: | ||
|
|
||
| docker network create \ | ||
| -o com.docker.network.bridge.name=bridge1 \ | ||
| --subnet 192.0.2.0/24 --gateway 192.0.2.1 bridge1 | ||
| docker run --network bridge1 -p 127.0.0.1:8080:80 --name c1 busybox | ||
|
|
||
| The filter and nat tables are the same as with no HostIP specified. | ||
|
|
||
| <details> | ||
| <summary>Filter table</summary> | ||
|
|
||
| Chain INPUT (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
|
|
||
| Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 DOCKER-USER 0 -- * * 0.0.0.0/0 0.0.0.0/0 | ||
| 2 0 0 ACCEPT 0 -- * * 0.0.0.0/0 0.0.0.0/0 match-set docker-ext-bridges-v4 dst ctstate RELATED,ESTABLISHED | ||
| 3 0 0 DOCKER-ISOLATION-STAGE-1 0 -- * * 0.0.0.0/0 0.0.0.0/0 | ||
| 4 0 0 DOCKER 0 -- * * 0.0.0.0/0 0.0.0.0/0 match-set docker-ext-bridges-v4 dst | ||
| 5 0 0 ACCEPT 0 -- docker0 * 0.0.0.0/0 0.0.0.0/0 | ||
| 6 0 0 ACCEPT 0 -- bridge1 * 0.0.0.0/0 0.0.0.0/0 | ||
|
|
||
| Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
|
|
||
| Chain DOCKER (1 references) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 ACCEPT 6 -- !bridge1 bridge1 0.0.0.0/0 192.0.2.2 tcp dpt:80 | ||
| 2 0 0 DROP 0 -- !docker0 docker0 0.0.0.0/0 0.0.0.0/0 | ||
| 3 0 0 DROP 0 -- !bridge1 bridge1 0.0.0.0/0 0.0.0.0/0 | ||
|
|
||
| Chain DOCKER-ISOLATION-STAGE-1 (1 references) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 DOCKER-ISOLATION-STAGE-2 0 -- docker0 !docker0 0.0.0.0/0 0.0.0.0/0 | ||
| 2 0 0 DOCKER-ISOLATION-STAGE-2 0 -- bridge1 !bridge1 0.0.0.0/0 0.0.0.0/0 | ||
|
|
||
| Chain DOCKER-ISOLATION-STAGE-2 (2 references) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 DROP 0 -- * bridge1 0.0.0.0/0 0.0.0.0/0 | ||
| 2 0 0 DROP 0 -- * docker0 0.0.0.0/0 0.0.0.0/0 | ||
|
|
||
| Chain DOCKER-USER (1 references) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 RETURN 0 -- * * 0.0.0.0/0 0.0.0.0/0 | ||
|
|
||
|
|
||
| -P INPUT ACCEPT | ||
| -P FORWARD ACCEPT | ||
| -P OUTPUT ACCEPT | ||
| -N DOCKER | ||
| -N DOCKER-ISOLATION-STAGE-1 | ||
| -N DOCKER-ISOLATION-STAGE-2 | ||
| -N DOCKER-USER | ||
| -A FORWARD -j DOCKER-USER | ||
| -A FORWARD -m set --match-set docker-ext-bridges-v4 dst -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT | ||
| -A FORWARD -j DOCKER-ISOLATION-STAGE-1 | ||
| -A FORWARD -m set --match-set docker-ext-bridges-v4 dst -j DOCKER | ||
| -A FORWARD -i docker0 -j ACCEPT | ||
| -A FORWARD -i bridge1 -j ACCEPT | ||
| -A DOCKER -d 192.0.2.2/32 ! -i bridge1 -o bridge1 -p tcp -m tcp --dport 80 -j ACCEPT | ||
| -A DOCKER ! -i docker0 -o docker0 -j DROP | ||
| -A DOCKER ! -i bridge1 -o bridge1 -j DROP | ||
| -A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2 | ||
| -A DOCKER-ISOLATION-STAGE-1 -i bridge1 ! -o bridge1 -j DOCKER-ISOLATION-STAGE-2 | ||
| -A DOCKER-ISOLATION-STAGE-2 -o bridge1 -j DROP | ||
| -A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP | ||
| -A DOCKER-USER -j RETURN | ||
|
|
||
|
|
||
| </details> | ||
|
|
||
| <details> | ||
| <summary>NAT table</summary> | ||
|
|
||
| Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 DOCKER 0 -- * * 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL | ||
|
|
||
| Chain INPUT (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
|
|
||
| Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 DOCKER 0 -- * * 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL | ||
|
|
||
| Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 MASQUERADE 0 -- * !bridge1 192.0.2.0/24 0.0.0.0/0 | ||
| 2 0 0 MASQUERADE 0 -- * !docker0 172.17.0.0/16 0.0.0.0/0 | ||
|
|
||
| Chain DOCKER (2 references) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 RETURN 0 -- bridge1 * 0.0.0.0/0 0.0.0.0/0 | ||
| 2 0 0 RETURN 0 -- docker0 * 0.0.0.0/0 0.0.0.0/0 | ||
| 3 0 0 DNAT 6 -- !bridge1 * 0.0.0.0/0 127.0.0.1 tcp dpt:8080 to:192.0.2.2:80 | ||
|
|
||
|
|
||
| -P PREROUTING ACCEPT | ||
| -P INPUT ACCEPT | ||
| -P OUTPUT ACCEPT | ||
| -P POSTROUTING ACCEPT | ||
| -N DOCKER | ||
| -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER | ||
| -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER | ||
| -A POSTROUTING -s 192.0.2.0/24 ! -o bridge1 -j MASQUERADE | ||
| -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE | ||
| -A DOCKER -i bridge1 -j RETURN | ||
| -A DOCKER -i docker0 -j RETURN | ||
| -A DOCKER -d 127.0.0.1/32 ! -i bridge1 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.0.2.2:80 | ||
|
|
||
|
|
||
| </details> | ||
|
|
||
| The raw table is: | ||
|
|
||
| Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
| 1 0 0 ACCEPT 6 -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:8080 ADDRTYPE match dst-type LOCAL limit-in | ||
| 2 0 0 DROP 6 -- * * 0.0.0.0/0 127.0.0.1 tcp dpt:8080 | ||
|
|
||
| Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) | ||
| num pkts bytes target prot opt in out source destination | ||
|
|
||
|
|
||
| <details> | ||
| <summary>iptables commands</summary> | ||
|
|
||
| -P PREROUTING ACCEPT | ||
| -P OUTPUT ACCEPT | ||
| -A PREROUTING -d 127.0.0.1/32 -p tcp -m tcp --dport 8080 -m addrtype --dst-type LOCAL --limit-iface-in -j ACCEPT | ||
| -A PREROUTING -d 127.0.0.1/32 -p tcp -m tcp --dport 8080 -j DROP | ||
|
|
||
|
|
||
| </details> | ||
|
|
||
| The difference from [port mapping with no HostIP][0] is: | ||
|
|
||
| - An ACCEPT rule is added to the PREROUTING chain to drop packets targeting the | ||
| mapped port and coming from the interface that has the HostIP assigned. | ||
| - And a DROP rule is added too, to drop packets targeting the mapped port but | ||
| didn't pass the previous check. | ||
|
|
||
| [0]: usernet-portmap.md |
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
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
48 changes: 48 additions & 0 deletions
48
integration/network/bridge/iptablesdoc/templates/usernet-portmap-hostip.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| ## Container on a user-defined network, with a port published on a specific HostIP | ||
|
|
||
| Adding a network running a container with a mapped port, equivalent to: | ||
|
|
||
| docker network create \ | ||
| -o com.docker.network.bridge.name=bridge1 \ | ||
| --subnet 192.0.2.0/24 --gateway 192.0.2.1 bridge1 | ||
| docker run --network bridge1 -p 127.0.0.1:8080:80 --name c1 busybox | ||
|
|
||
| The filter and nat tables are the same as with no HostIP specified. | ||
|
|
||
| <details> | ||
| <summary>Filter table</summary> | ||
|
|
||
| {{index . "LFilter4"}} | ||
|
|
||
| {{index . "SFilter4"}} | ||
|
|
||
| </details> | ||
|
|
||
| <details> | ||
| <summary>NAT table</summary> | ||
|
|
||
| {{index . "LNat4"}} | ||
|
|
||
| {{index . "SNat4"}} | ||
|
|
||
| </details> | ||
|
|
||
| The raw table is: | ||
|
|
||
| {{index . "LRaw4"}} | ||
|
|
||
| <details> | ||
| <summary>iptables commands</summary> | ||
|
|
||
| {{index . "SRaw4"}} | ||
|
|
||
| </details> | ||
|
|
||
| The difference from [port mapping with no HostIP][0] is: | ||
|
|
||
| - An ACCEPT rule is added to the PREROUTING chain to drop packets targeting the | ||
| mapped port and coming from the interface that has the HostIP assigned. | ||
| - And a DROP rule is added too, to drop packets targeting the mapped port but | ||
| didn't pass the previous check. | ||
|
|
||
| [0]: usernet-portmap.md |
Oops, something went wrong.
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.
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.
Is this only for our tests, or is this a new dependency we should have installed (and to be added as "requires" in our packages?)
I can't find a direct reference to this in this PR; was it accidentally left behind (for local debugging?)
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.
That's only for testing. Here's where it's used: https://github.com/moby/moby/pull/48721/files#diff-4fd76a7e4270f16a03d5160517ee2454558f127af10e95c55451963b17429414R817