Deep Review: 20261015-112802-pr-5581

Date2026-10-15 11:28
Repolima-vm/lima
Round3
Author@ranacseruet
PR#5581 — vz: add networkOpts.hostLoopback to block guest access to host loopback
Branchfeat/host-loopback-opt-out
Commitsc388098f vz: add networkOpts.hostLoopback to block guest access to host loopback
Review SHAc388098fae8c332e1b18060aca05d21cf2795104
ReviewersClaude Opus 5.5 (effort: high), Codex GPT 6 Astra (effort: high), Gemini 3.1 Pro (effort: default), Gemini 3.5 Flash (effort: default)
VerdictMerge as-is — no Critical or Important finding; the four suggestions are optional
Wall-clock time19 min 4 s


Executive Summary

The PR adds networkOpts.hostLoopback. On vz, false maps host.lima.internal and 0.0.0.0 to the unroutable 0.0.0.1, and the other drivers and user-v2 refuse it. This is the round that converged. The rename reaches every consumer, round 2's I1 tests fail when their fixes are reverted, and gvisor-tap-vsock v0.9.0, now on master, does not open a new path to host loopback. The four remaining suggestions are optional.


Critical Issues

None.


Important Issues

None.


Suggestions

S1. The vz user-v2 test does not pin where the refusal lives Claude Opus 5.5 Codex GPT 6 Astra Gemini 3.1 Pro Gemini 3.5 Flash
	}
}

func TestValidateRejectsHostLoopbackFalseWithUserV2(t *testing.T) {
	t.Setenv("LIMA_HOME", t.TempDir())
	cfg := &limatype.LimaYAML{
		Firmware:    limatype.Firmware{LegacyBIOS: new(false)},
		NetworkOpts: limatype.NetworkOpts{HostLoopback: new(false)},
		Networks:    []limatype.Network{{Lima: "user-v2"}},
	}
	l := &LimaVzDriver{Instance: &limatype.Instance{Config: cfg}}
	assert.ErrorContains(t, l.Validate(t.Context()), "not supported with a `user-v2` network")
}

Round 2's S2 is still open. Deleting the refusal at pkg/driver/vz/vz_driver_darwin.go:262-264 fails this test only through a nil-pointer panic in validateConfig, because the fixture leaves Arch unset. Moving the refusal into validateConfig, which limactl delete runs through Configure, leaves the test green. BATS ok 4 catches the deletion on the vz job but not the move, since limactl start prints the same message either way. The test is optional. A misplaced refusal makes limactl delete fail with an error that names the field.

	return scripts, nil
}

func (l *LimaVzDriver) Validate(_ context.Context) error {
	// Configure, which deletion also uses, runs validateConfig, so this start-time check is here.
	if cfg := l.Instance.Config; cfg != nil && !limayaml.HostLoopbackEnabled(cfg) && limayaml.FirstUsernetIndex(cfg) != -1 {
		return errors.New("`networkOpts.hostLoopback: false` is not supported with a `user-v2` network, which is shared by instances")
	}
	if err := validateConfig(l.Instance.Config); err != nil {
		return err
	}
	if len(l.Instance.Config.BlockDevices) == 0 {
		return nil

Fix: load the config and run Configure, as deletion does, before Validate. I ran this version. It passes on the tree, fails with "expected an error, got nil" when the refusal is deleted, and fails with the refusal's message when the refusal moves into validateConfig.

t.Setenv("LIMA_HOME", t.TempDir())
cfg, err := limayaml.Load(t.Context(), []byte("vmType: vz\nnetworkOpts: {hostLoopback: false}\nnetworks: [{lima: user-v2}]\n"), "lima.yaml")
assert.NilError(t, err)
l := &LimaVzDriver{}
_, err = l.Configure(t.Context(), &limatype.Instance{Dir: t.TempDir(), Config: cfg})
assert.NilError(t, err)
assert.ErrorContains(t, l.Validate(t.Context()), "not supported with a `user-v2` network")
S2. No test runs setupEnv with hostLoopback false Claude Opus 5.5 Codex GPT 6 Astra Gemini 3.1 Pro Gemini 3.5 Flash

			for _, ip := range netLookupIP(u.Hostname()) {
				if !ip.IsLoopback() {
					continue
				}
				if !hostLoopback {
					logrus.Warnf("%#q value %#q points at the host's loopback, which the guest cannot reach with `networkOpts.hostLoopback: false`", name, value)
				}
				newHost := slirpGateway
				if u.Port() != "" {
					newHost = net.JoinHostPort(newHost, u.Port())
				}
				u.Host = newHost

Round 2's S3 is still open. Every setupEnv call in cidata_test.go and fuzz_test.go passes true, so deleting this warning, or the break at line 104, leaves go test ./pkg/cidata/ green. The test is optional, since the warning is diagnostic only.

					newHost = net.JoinHostPort(newHost, u.Port())
				}
				u.Host = newHost
				value = u.String()
				// Every loopback address gives the same rewrite.
				break
			}
			if value != env[name] {
				logrus.Infof("Replacing %#q value %#q with %#q", name, env[name], value)
				env[name] = value
			}

TestSetupEnv replaces netLookupIP with a one-address stub and does not restore it (pkg/cidata/cidata_test.go:26). A new test must install its own two-address stub; otherwise a full package run cannot catch a missing break.

func fakeLookupIP(_ string) []net.IP {
	return []net.IP{net.IPv4(127, 0, 0, 0)}
}

func TestSetupEnv(t *testing.T) {
	netLookupIP = fakeLookupIP
	urlMustParse := func(urlStr string) *url.URL {
		u, err := url.Parse(urlStr)
		assert.NilError(t, err)
		return u
	}

Fix: add a test with this body. In a full go test ./pkg/cidata/ run it passes on the tree, counts 0 warnings when the warning is deleted, and counts 2 when the break is deleted.

netLookupIP = func(string) []net.IP { return []net.IP{net.IPv4(127, 0, 0, 1), net.IPv6loopback} }
hook := logrustest.NewGlobal()
_, err := setupEnv(map[string]string{"http_proxy": "http://localhost:3128"}, false, false, networks.SlirpGateway)
assert.NilError(t, err)
warnings := slices.DeleteFunc(hook.AllEntries(), func(e *logrus.Entry) bool { return e.Level != logrus.WarnLevel })
assert.Equal(t, len(warnings), 1)
S3. The template's "(since Lima v2.3)" says the default changed Claude Opus 5.5
  # - Only supported with `vmType: vz`. Not supported with a `user-v2` network, which is shared by instances.
  # - Does not restrict the host's other addresses: a host service bound to all interfaces is still
  #   reachable through the host's LAN IP.
  # - A proxy on the host's loopback (e.g. `http_proxy=http://127.0.0.1:3128`), whether it comes from
  #   the host's network settings, `env`, or `propagateProxyEnv`, becomes unreachable from the guest.
  # 🟢 Builtin default: true (since Lima v2.3)
  hostLoopback: null

# EXPERIMENTAL
# When enabled, an emulated TPM 2.0 device is provided to the guest via swtpm.
# Requires swtpm to be installed on the host. Only supported with vmType: qemu.

In this template, a version note after a builtin default dates a change of default. 9e7fc04b turned loadDotSSHPubKeys's Builtin default: true into false (since Lima v1.0) (line 162), and securityModel has "none" (since Lima v0.13) (line 87). Read the same way, line 705 says the default became true in v2.3, as if earlier releases blocked host loopback. They did not; the field itself is new. The docs' "(available since Lima v2.3)" at website/content/en/docs/config/network/user.md:24 gets this right.


## Host IP (192.168.5.2)

The loopback addresses of the host is `192.168.5.2` and is accessible from the guest as `host.lima.internal`.

This includes services that listen only on the host's `127.0.0.1`. To block this, for example for a guest that runs untrusted code, set `networkOpts.hostLoopback: false` (available since Lima v2.3) in `lima.yaml`:

```yaml
networkOpts:
  hostLoopback: false
```
#    # 🟢 Builtin default: "openssh-sftp-server" if OpenSSH SFTP Server binary is found, otherwise "builtin"
#    sftpDriver: null
#  9p:
#    # Supported security models are "passthrough", "mapped-xattr", "mapped-file" and "none".
#    # "mapped-xattr" and "mapped-file" are useful for persistent chown but incompatible with symlinks.
#    # 🟢 Builtin default: "none" (since Lima v0.13)
#    securityModel: null
#    # Select 9P protocol version. Valid options are: "9p2000" (legacy), "9p2000.u", "9p2000.L".
#    # 🟢 Builtin default: "9p2000.L"
#    protocolVersion: null
#    # The number of bytes to use for 9p packet payload, where 4KiB is the absolute minimum.
  localPort: null
  # Load ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
  # This option is useful when you want to use other SSH-based
  # applications such as rsync with the Lima instance.
  # If you have an insecure key under ~/.ssh, do not use this option.
  # 🟢 Builtin default: false (since Lima v1.0)
  loadDotSSHPubKeys: null
  # Forward ssh agent into the instance.
  # The ssh agent socket can be mounted in a container at the path `/run/host-services/ssh-auth.sock`.
  # Set the environment variable `SSH_AUTH_SOCK` value to the path above.
  # The socket is accessible by the non-root user inside the Lima instance.

Fix: move the version to its own line.

-  # 🟢 Builtin default: true (since Lima v2.3)
+  # Available since Lima v2.3.
+  # 🟢 Builtin default: true
S4. The docs do not warn that an older limactl ignores the option Codex GPT 6 Astra Gemini 3.5 Flash Claude Opus 5.5

## Host IP (192.168.5.2)

The loopback addresses of the host is `192.168.5.2` and is accessible from the guest as `host.lima.internal`.

This includes services that listen only on the host's `127.0.0.1`. To block this, for example for a guest that runs untrusted code, set `networkOpts.hostLoopback: false` (available since Lima v2.3) in `lima.yaml`:

```yaml
networkOpts:
  hostLoopback: false
```

A limactl without this change reads networkOpts as an unknown field. It logs "Non-strict YAML detected" (pkg/limayaml/marshal.go:81) and starts the guest with host loopback reachable, so the option fails open for the untrusted guests it targets. Round 2 recorded this as a design concern.

	}
	// Finally log a warning if the YAML file violates the "strict" rules
	opts = append(opts, yaml.Strict())
	var ignore limatype.LimaYAML
	if err := yaml.UnmarshalWithOptions(data, &ignore, opts...); err != nil {
		logrus.WithField("comment", comment).WithError(err).Warn("Non-strict YAML detected; please check for typos")
	}
	return nil
}

// Convert converts from x to y, using YAML.

minimumLimaVersion makes an older limactl refuse the template (pkg/limayaml/validate.go:41-49). It has one gap. versionutil.Parse strips a prerelease suffix, and compare then ranks the prerelease above the release (pkg/version/versionutil/versionutil.go:16-42), so minimumLimaVersion: 2.3.0 also accepts the already tagged v2.3.0 betas, which lack the field.


	if len(y.Base) > 0 {
		errs = errors.Join(errs, errors.New("field `base` must be empty for YAML validation"))
	}

	if y.MinimumLimaVersion != nil {
		if _, err := versionutil.Parse(*y.MinimumLimaVersion); err != nil {
			errs = errors.Join(errs, fmt.Errorf("field `minimumLimaVersion` must be a semvar value, got %#q: %w", *y.MinimumLimaVersion, err))
		}
		// Unparsable version.Version (like commit hashes or "<unknown>") is treated as "latest/greatest"
		// and will pass all version comparisons, allowing development builds to work.
		if !versionutil.GreaterEqual(version.Version, *y.MinimumLimaVersion) {
			errs = errors.Join(errs, fmt.Errorf("template requires Lima version %#q; this is only %#q", *y.MinimumLimaVersion, version.Version))
		}
	}

	switch *y.OS {
	case limatype.LINUX, limatype.DARWIN, limatype.FREEBSD:
	case limatype.WINDOWS:

// Parse parses a Lima version string by removing the leading "v" character and
// stripping everything from the first "-" forward (which are `git describe` artifacts and
// not semver pre-release markers) or cutting ".m" suffix from exact version.
// So "v0.19.1-16-gf3dc6ed.m" will be parsed as "0.19.1".
func Parse(version string) (*semver.Version, error) {
	version = strings.TrimPrefix(version, "v")
	version, _, _ = strings.Cut(version, "-")
	version = strings.TrimSuffix(version, ".m")
	return semver.NewVersion(version)
}

func compare(limaVersion, oldVersion string) int {
	if limaVersion == "" {
		if oldVersion == "" {
			return 0
		}
		return -1
	}
	version, err := Parse(limaVersion)
	if err != nil {
		return 1
	}
	// Handle Unparsable oldVersion gracefully - treat as 0.0.0 so Unparsable limaVersion is always greater
	oldVer, err := semver.NewVersion(oldVersion)
	if err != nil {
		return 1
	}
	cmp := version.Compare(*oldVer)
	if cmp == 0 && strings.Contains(limaVersion, "-") {
		cmp = 1
	}
	return cmp
}

// GreaterThan returns true if the Lima version used to create an instance is greater
// than a specific older version. Always returns false if the Lima version is the empty string.

Fix: add a sentence to user.md and the template comment telling users that templates relying on the option should set minimumLimaVersion: 2.3.0.


Design Observations

Concerns

Strengths


Testing Assessment

I ran go test -count=1 ./... at the review SHA on macOS arm64: exit 0, 51 packages ok, none failed. I ran it again on the PR merged into current master, which ships gvisor-tap-vsock v0.9.0. go build ./... and go vet on the touched packages passed, and go test reported 51 packages ok, none failed. No CI run has tested that combination; the PR's runs merged it into f6158feb, which has v0.8.9. On c388098f, 36 checks pass and two Netlify checks are skipped. The vz job ran the new BATS file on an Intel runner and passed all four tests.

I applied each mutation alone in the lead worktree:

MutationExisting testsProposed test
natTable(gatewayIP, false) at the call siteTestNetstackConfigurationNAT fails
krunkit refusal deletedTestValidateRejectsHostLoopbackFalse fails
vz passes HostLoopbackEnabled without the !TestGVisorNetstackOptsHostLoopback fails
vz user-v2 refusal deletedfails by panicS1 fails
vz user-v2 refusal moved into validateConfiggreenS1 fails
setupEnv warning deletedgreenS2 fails
setupEnv break deletedgreenS2 fails
  1. Required: none missing. Every round 2 I1 link now has a test that fails when it is reverted.
  2. Optional: the vz user-v2 placement (S1). A misplaced refusal fails loudly on limactl delete.
  3. Optional: the setupEnv warning (S2). The warning is diagnostic only.

The krunkit test runs only on Apple silicon machines. CI runs go test on macOS only on Intel runners (.github/workflows/test.yml:289, :513), and the arm64 macos-26 job only lints.


Documentation Assessment


Acknowledged Limitations


Agent Performance Retro

Claude Opus 5.5

Claude alone found S3, by checking what the template's existing version notes mean, and alone found the template-merge concern, which it confirmed with limactl template copy --embed. It also noticed that CI never runs the krunkit test. Its S1 probe held up when rerun, but its S2 probe caught a deleted break only when run alone, because TestSetupEnv leaves a one-address stub installed. It re-raised the refusal-spelling suggestion that round 2 dropped, saying the krunkit and HCS packages already import limayaml; the three files with the inline check do not. It said that a subagent, not Claude itself, read the gvisor sources.

Codex GPT 6 Astra

Codex ran every mutation it reported, and its probes covered serialization, the schema, yq edits and template inheritance for the renamed field. It alone found that minimumLimaVersion: 2.3.0 accepts the 2.3 betas. It also corrected two acknowledged limitations. limactl create itself fails after writing the instance, and a load-time refusal leaves the instance listable with errors. But it judged the template's "(since Lima v2.3)" consistent with the repo's convention, which lines 87 and 162 contradict, and it marked the template reviewed with no issues.

Gemini 3.1 Pro

Gemini Pro found the two carried-over test gaps and nothing else. It edited tracked files in place with sed -i.bak and patch, which the prompt forbids, restored each with git checkout after its test run, and left .bak and .orig copies in its worktree. It also ran limactl create twice against a scratch LIMA_HOME; both runs failed before writing an instance. Its review cites none of those runs. It marked templates/default.yaml and user.md reviewed with no issues.

Gemini 3.5 Flash

Flash rated the vz user-v2 test gap Important, arguing that a misplaced refusal would break limactl delete silently. The failure names the field, so it stays a Suggestion; its proposed fix follows the qemu tests' pattern, and I did not run it. It re-raised the dropped refusal-spelling item and cited line 105 for a break that is on line 104. Its limitations section says 127.0.0.2 reaches host loopback, which contradicts round 1's measured timeout. The two Gemini models agree on both test gaps, which counts as one opinion.

Summary

Claude Opus 5.5Codex GPT 6 AstraGemini 3.1 ProGemini 3.5 Flash
Duration10m 28s9m 37s10m 56s10m 26s
Findings4S3S2S3S
Tool calls50 (Bash 43, Read 6, Agent 1)24 (shell 24)61 (runshellcommand 61)86 (grepsearch 29, readfile 23, runshellcommand 18)
Design observations4323
False positives0000
Unique insights3200
Files reviewed23232323
Coverage misses0120
Totals4S3S2S3S
Downgraded0001
Dropped1001

Claude supplied the most value and Codex the most careful evidence. The Gemini models found nothing the others missed.

Reconciliation. Gemini 3.5 Flash P1 I1 (vz user-v2 test): important → suggestion S1. Claude Opus 5.5 P1 S4 and Gemini 3.5 Flash P1 S3 (one spelling of the refusals): dropped, as in round 2.


Review Process Notes

Skill improvements

Repo context updates