Fix incorrect validation of port mapping #48088
Merged
+76
−15
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.
- What I did
In 27.0.1, #47871 added a check that no host address/port is included in a port mapping when NAT is disabled (because it'd be misleading, with no NAT the container port is opened but there's no mapping from the host).
A port mapping from a specific IPv6 host address can be used by a container on an IPv4-only network, docker-proxy makes the connection. That new validation erroneously reported an error for this situation.
- How I did it
Rather than treat a container with no IPv6 address as having no NAT6 (in
!disableNAT6 && len(containerIPv6) > 0
), ignore the presence of an address. Then, in the validation function special-case a container with no IPv6 address, allowing anything in an IPv6 port mapping.- How to verify it
With an IPv4-only network,
docker run --rm -ti --network nnn -p 127.0.0.1:8080:80 -p '[::1]:8080:80' nginx
.Updated unit tests, and new integration test.
- Description for the changelog