lima: avoid mutating user config when injecting default DNS host - #1630
Open
ousamabenyounes wants to merge 1 commit into
Open
lima: avoid mutating user config when injecting default DNS host#1630ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
newConf aliased conf.Network.DNSHosts and then inserted the internal host.docker.internal default into it. Since maps are reference types, this mutated the caller's config in place, which is later persisted, leaking host.docker.internal into the user's saved colima.yaml. Copy the hosts into a new map before injecting the default. Signed-off-by: Ben Younes <2910651+ousamabenyounes@users.noreply.github.com>
ousamabenyounes
force-pushed
the
fix/dnshosts-config-mutation
branch
from
September 7, 2026 22:34
1ee8472 to
db572a2
Compare
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.
Problem
newConfinenvironment/vm/lima/yaml.gobuilds the lima config from the colimaconfig. It assigned the user's DNS-hosts map by reference and then injected
colima's internal
host.docker.internaldefault into it:Because Go maps are reference types, mutating
l.HostResolver.Hostsalso mutatesthe caller's
conf.Network.DNSHosts. That same config object is later saved(
l.conf = conf→SaveToFile, and the CLI'sconfigmanager.Saveshares thesame underlying map), so any user who has at least one
dnsHostsentry ends upwith an unwanted
host.docker.internal: host.lima.internalline silently writteninto their
colima.yaml.When
conf.Network.DNSHostswasnilthe code happened to allocate a fresh map,so the leak only affected users who set their own DNS hosts.
Fix
Copy the user-provided hosts into a new map before injecting the internal default,
so the caller's config is never mutated. Behavior is otherwise unchanged: the
host.docker.internaldefault is still added when absent, and a user override isstill respected.
Test verification (RED → GREEN)
Added
Test_newConf_doesNotMutateDNSHosts, which callsnewConfwith auser-supplied
dnsHostsmap and asserts the original map is left untouched.RED — on the unmodified base (bug present):
GREEN — with the fix:
go build ./...,go test ./..., andgolangci-lint run(v2.11.3) are all green.