Repository navigation
Networks: gateway_mode_ipv4=isolated leaves the host off an internal network - #1010
Open
masihmoloodian wants to merge 1 commit into
Open
masihmoloodian wants to merge 1 commit into
masihmoloodian wants to merge 1 commit into
Conversation
…network An internal network's bridge still had the gateway address, so its containers reached every service listening on all of the host's addresses through it (libracoder#1001): a database, a dev server, an admin endpoint. Docker 28 closes that path with `-o com.docker.network.bridge.gateway_mode_ipv4=isolated` on an internal network, and `inhibit_ipv4=true` does the same there. Kiri accepted both and did nothing with them. - With either on an internal network, the bridge gets no IPv4 address, so the host has none on the network. Containers keep their own addresses and reach each other, by name too: with nothing listening on the gateway, they ask Kiri's resolver at 127.0.0.11 in their own network. The same holds for a container that joins with `network connect`, on a Linux host and in the Mac's VM. - The gateway options are checked as Docker checks them: a known mode (`nat`, `nat-unprotected`, `routed`, `isolated`), a boolean `inhibit_ipv4`, and `isolated` only on an internal network, with Docker's messages. The modes other than `isolated` work as before. - `gateway_mode_ipv6=isolated` on a network with IPv6 is refused for now, rather than accepted with the bridge's IPv6 address left in place. Fixes libracoder#1001
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 this changes and why
An
--internalnetwork's bridge still has the gateway address, so its containers reach every service listening on all of the host's addresses through it (#1001): a database, a dev server, an admin endpoint. Docker 28 closes that path with-o com.docker.network.bridge.gateway_mode_ipv4=isolatedon an internal network, andinhibit_ipv4=truedoes the same there. Kiri accepted both and did nothing with them:In the daemon (
daemon/network.rs,daemon/engine.rs):network createchecks the gateway options as Docker's bridge driver does (parseNetworkOptions,newGwMode), with its messages:nat,nat-unprotected,routedorisolated, elsefailed to parse … (unknown gateway mode …);inhibit_ipv4must be a boolean;isolatedis refused unless the network is internal, withgateway mode 'isolated' can only be used for an internal network.isolatedwork as before.gateway_mode_ipv4=isolatedorinhibit_ipv4=true, each container that starts on it, or joins it withnetwork connect, hasnogw4=1among its network options for the guest.gateway_mode_ipv6=isolatedon a network with IPv6 is refused for now, rather than accepted with the bridge's IPv6 address left in place. On an IPv4-only network there is nothing for it to do, so it's accepted.In the guest (
kiri-init/src/linux/net.rs,container.rs,agent.rs), withnogw4:127.0.0.11in their own network, as they already do when the gateway won't take the listener (WSL 2 Linux host: user-defined bridge networks fail at gateway DNS bind (EINVAL) #477).This works the same on a Linux host and in the Mac's VM, where the same guest code makes the bridges.
inhibit_ipv4on a network that isn't internal is kept as before: Docker then leaves the bridge to be set up by hand, which Kiri doesn't do.One difference from Docker remains:
network inspectstill shows the subnet's first address as the gateway inIPAM.Config, where Docker shows none.Fixes #1001
How you tested it
On this branch, the same steps:
On a Linux host (
tests/linux-host.sh), the gateway's address is on none of the host's interfaces with the option, and a server on every host address isn't reached through the gateway.Tests:
cargo test -p kiri: 1054 passed. New test:an_isolated_gateway_is_for_internal_networks_only. It covers the options that isolate, the ones that don't, Docker's refusals and their messages, and the IPv6 case.cargo test -p kiri-init(in a Linux container): 283 passed, 4 failed. The 4 fail on main too, because the container may notmknod,mountor redirect:whiteout_becomes_char_device,an_overlay_of_more_layers_than_one_page_names,an_imported_writable_layer_becomes_the_upper_dir_wholeandegress_redirect_relays_vpn_tcp_with_original_dst_and_exempts_bridge_peers. New test:an_isolated_bridge_has_no_ipv4_gateway.tests/e2e.sh(macOS): 7 new checks. Three of them fail on a main build and pass here:isolated-host-unreachedisolated-connect-unreached, throughnetwork connectisolated-needs-internalThe others pass on both:
isolated-plain-internal-reaches-host(the same server reached without the option, so the check sees a real listener),isolated-names,isolated-resolverandisolated-option-shown. The internal-network checks around them pass.The full suite: 945 passed, 19 failed, 1 skipped.
default-bridge-no-names,dns-failed-start-gone,disconnect-dns-gone,network-recreate-same-subnet-old-name-gone,dns-user-net-three-silent-servfail-in-timeand the fiverename-dns-*checks.guest-kernel-nfs-dmcrypt, is my older guest kernel.tests/linux-host.sh: 6 new checks. On a main build,isolated-host-unreachedandisolated-bridge-no-ipv4fail; here all pass. The suite: 239 passed, 1 failed.failed-start-no-dnsfails on main too, because this Mac's VPN answers every DNS query. On one earlier runfwdrop-rulesandfwdrop-ufw-rulesfailed too, and passed on the next run.cargo clippy: no warnings in the changed lines.Tested on: macOS 27.2.1, Apple M4 Pro, and the Linux host build in
tests/linux-host.sh. Windows (WSL) runs the same Linux engine.How you found it
AI tools used to write this change:
Checklist
cargo fmt,cargo clippyand the tests pass