Repository navigation
Mac: KIRI_HOST_LOOPBACK=off keeps containers away from the Mac's loopback - #1008
Open
masihmoloodian wants to merge 1 commit into
Open
masihmoloodian wants to merge 1 commit into
masihmoloodian wants to merge 1 commit into
Conversation
…back On a Mac, host.docker.internal reaches every service on the Mac's 127.0.0.1 and ::1 (libracoder#258), as on Docker Desktop and OrbStack. For untrusted workloads, such as CI jobs in a Kiri that runs as its own macOS user, there was no way to turn that off (libracoder#995). The engine itself opens the connection, and pf can't stop it, since macOS skips lo0 while a VM runs. - `KIRI_HOST_LOOPBACK=off` (or 0, false, no) in the daemon's environment refuses each container connection to the Mac's loopback: host.docker.internal, host.kiri.internal and --add-host host-gateway. The names still resolve, and the connection is closed, as from a host where nothing listens. Unset or anything else, nothing changes. - Kiri's own image mirror stays reachable there: builds pull through it, and it checks its token. - The daemon logs that it is off when the VM starts, and the first connection it refuses. Fixes libracoder#995
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
On a Mac,
host.docker.internalreaches every service on the Mac's127.0.0.1and::1(#258), as on Docker Desktop and OrbStack. That's right for development. For untrusted workloads, such as CI jobs run by a Kiri under its own macOS user, there was no way to turn it off (#995):The engine itself opens that connection on the Mac (
ports.rs,host_bound), and pf can't stop it, because macOS skipslo0while a VM runs.This adds
KIRI_HOST_LOOPBACK=off(or0,false,no) to the daemon's environment:host.docker.internal,host.kiri.internal,--add-host x:host-gateway, and the same from--network host. The names still resolve, which the issue allows. The connection is closed, as from a host where nothing listens on the port.198.19.248.254:<mirror port>, so builds would break without it. Reading images from it needs its secret token.It's an environment variable, like
KIRI_TLS_ROOTS, because the use in #995 is akiri daemonunder a LaunchDaemon, whose plist sets it. There's no Settings switch.Linux hosts are unchanged. There
host.docker.internalis the bridge's gateway and never reached127.0.0.1. Windows (WSL) is unchanged too, since it has its own relay (hostrelay.rs).Containers can still reach the Mac's own network addresses, for services listening on every address. The issue is about loopback, and those connections don't go through this relay.
Fixes #995
How you tested it
On this branch, with
KIRI_HOST_LOOPBACK=off kiri daemonand the same server on the Mac's 127.0.0.1:The daemon log:
A
docker build(FROM busybox:1.36,RUN …) with it off works. BuildKit pushed its image to Kiri through the mirror at198.19.248.254:47391. Without the variable,host-internal,host-gatewayandhost-internal-hostnetpass as before.Tests:
cargo test -p kiri: 1054 passed. New test:host_loopback_off_refuses_all_but_the_mirror. It covers the values that turn it off and the ones that don't, every port with it on, and only the mirror's port with it off.tests/e2e.sh: 3 new checks, run when the suite runs withKIRI_HOST_LOOPBACK=offagainst a daemon started with it. They pass:host-loopback-offhost-loopback-off-gatewayhost-loopback-off-hostnetThe full suite against a daemon started without it: 938 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.cargo clippy: no warnings in the changed lines.Tested on: macOS 27.2.1, Apple M4 Pro. The change only acts on a Mac. Linux and Windows hosts have no such relay to the host's loopback.
How you found it
AI tools used to write this change:
Checklist
cargo fmt,cargo clippyand the tests pass