← Back to Pull requests

vz: add networkOpts.hostLoopback to block guest access to host loopback #5581

Merged
ranacseruet merged 23 files (368 lines) on Oct 16, 2026 12:39 UTC
View on GitHub
ranacseruet ranacseruet commented on Oct 06, 2026 15:52 UTC
Author

Refs #5574

Adds networkOpts.hostLoopback to lima.yaml, in a new networkOpts group for network options. It defaults to true, so nothing changes unless it is set to false. When false, the in-process gateway maps host.lima.internal (and 0.0.0.0) to 0.0.0.1 instead of 127.0.0.1. The host has no route to 0.0.0.1, so the guest's connections are refused at once instead of reaching the host's loopback.

Scope. This is narrower than I proposed in the issue, which said vz and krunkit:

  • vmType: vz only. qemu, krunkit, wsl2 and hcs reject networkOpts.hostLoopback: false with an error instead of ignoring it. krunkit's default host resolver sends DNS through host.lima.internal, so it needs separate work, and I could not test krunkit.

  • A user-v2 network is rejected too, because it is a shared daemon and a per-instance setting cannot apply to it. A networks.yaml setting for it can be a follow-up.

  • QEMU's disable_host_loopback is not implemented here.

  • A proxy on the host's loopback (from the host's network settings, env, or propagateProxyEnv) becomes unreachable from the guest. Lima logs a warning and the docs say so.
  • Tested on macOS 26.6 with a vz VM, with and without the option, and with the option plus vzNAT: true. Host servers on 127.0.0.1:18081 and 0.0.0.0:18082:

    | From the guest | default | networkOpts.hostLoopback: false |
    |---|---|---|
    | host.lima.internal:18081 (host 127.0.0.1 only) | reachable | refused at once |
    | host.lima.internal:18082 (host ) | reachable | refused at once |
    | raw UDP from a root guest to 0.0.0.0 (host 127.0.0.1 only) | (reachable via host.lima.internal anyway) | blocked |
    | Mac LAN IP :18081 | closed | closed |
    | Mac LAN IP :18082 (host
    ) | reachable | reachable |
    | DNS, HTTPS | ok | ok |
    | limactl shell (SSH) | ok | ok |

    With vzNAT: true, connections to host.lima.internal are refused at once as well. The vzNAT gateway only reaches host services bound to *, like the LAN address.

    hack/bats/extras/vz-host-loopback.bats, added to the vz CI job, checks the first host.lima.internal row and DNS, then switches the instance to true and checks that the service is reachable. It also checks that a user-v2 network is rejected. It fails if the gateway mapping change is reverted.

    go test ./..., go vet and golangci-lint pass.

    Assisted-by: Claude Code

    Diff: 368 lines (+332 / -36) across 23 files Reviewer: AkihiroSuda Review duration: 14206m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.67) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.67 · 368 lines diff across 23 files
    0.67
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.76 · 5 substantive comment(s)
    0.76
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    85%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    20 items
    jandubois jandubois commented on Oct 07, 2026 03:23 UTC
    Reviewer

    AI review: https://jandubois.github.io/lima/20261006-184956-pr-5581.html

    Also commits should be squashed

    ranacseruet ranacseruet commented on Oct 07, 2026 16:14 UTC
    Author

    Thanks for the review. All the Important items and the suggestion are addressed, and the commits are squashed into one, and rebased on current master.

  • I1: The gateway now maps to 0.0.0.1 instead of having no entry. On a vz VM, connections to host.lima.internal are refused immediately (it took 4 s before on my machine), and 12 pending dials no longer stall new TCP connections.

  • I2: 0.0.0.0 maps to 0.0.0.1 too. A raw UDP packet from the guest to 0.0.0.0 no longer reaches a host listener bound only to 127.0.0.1.

  • I3: The refusals moved from validateConfig to each driver's Validate. With hostLoopback: false in _config/default.yaml, limactl delete -f works again, and start is still refused.

  • I4: The vz gvisor options are built in a helper, with tests for the wiring and the user-v2 refusal. Both tests fail if the ! is dropped or the refusal is removed.

  • S1: The proxy warning and rewrite now happen once per variable.
  • On external drivers failing open: agreed. I'd rather handle that as a follow-up, for example with a driver feature flag, than grow this PR. I also changed Fixes #5574 to Refs #5574, so the issue stays open for user-v2, krunkit and QEMU.

    jandubois jandubois commented on Oct 07, 2026 19:15 UTC
    Reviewer

    Thanks, LGTM,

    I would still like to see the tests added that are suggested by I1 in the updated review: https://jandubois.github.io/lima/20261007-102123-pr-5581.html

    I would ignore the new suggestions, but take a look if you feel you want to take any of them.

    ranacseruet ranacseruet commented on Oct 07, 2026 20:49 UTC
    Author

    Added the I1 tests (netstack NAT config and the krunkit refusal), plus the S1 doc wording. Squashed to one commit as well

    Two jobs (BATS, QEMU test-misc) timed out on this run. All their tests passed, but every VM boot in the run was 2–5× slower than the previous run (e.g. the BATS snapshot test took 517 s vs ~104 s on master today). @jandubois Could you please help re-run the failed jobs? (Seems like I can't trigger re-run myself)

    AkihiroSuda AkihiroSuda commented on code on Oct 08, 2026 01:40 UTC
    Code Review
    website/content/en/docs/config/network/user.md:1
    @@ -21,6 +21,18 @@ Use [VMNet]({{< ref "/docs/config/network/vmnet" >}}) to allow accessing the gue
     
     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 `hostLoopback: false` in `lima.yaml`:
    +
    +```yaml
    +hostLoopback: false
    +```
    +
    +DNS, outbound connections to other hosts and `limactl shell` keep working. Connections to `host.lima.internal` are refused instead.
    +A host service that listens on all interfaces is still reachable through the host's LAN address.
    +A proxy on the host's loopback (for example `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.
    +
    +`hostLoopback: false` is only supported with `vmType: vz`, and not with a [`user-v2`]({{< ref "/docs/config/network/user-v2" >}}) network.

    Can't we support it in user-v2 (via networks.yaml maybe), as they share the code with vz's default network?

    AkihiroSuda AkihiroSuda commented on code on Oct 08, 2026 01:41 UTC
    Code Review
    pkg/limatype/lima_yaml.go:1
    @@ -58,6 +58,7 @@ type LimaYAML struct {
     	Plain                *bool   `yaml:"plain,omitempty" json:"plain,omitempty" jsonschema:"nullable"`
     	TimeZone             *string `yaml:"timezone,omitempty" json:"timezone,omitempty" jsonschema:"nullable"`
     	NestedVirtualization *bool   `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty" jsonschema:"nullable"`
    +	HostLoopback         *bool   `yaml:"hostLoopback,omitempty" json:"hostLoopback,omitempty" jsonschema:"nullable"`

    Should we introduce struct NetworkOpts or something to groupify other potential network options?

    AkihiroSuda AkihiroSuda commented on code on Oct 08, 2026 01:42 UTC
    Code Review
    website/content/en/docs/config/network/user.md:1
    @@ -21,6 +21,18 @@ Use [VMNet]({{< ref "/docs/config/network/vmnet" >}}) to allow accessing the gue
     
     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 `hostLoopback: false` in `lima.yaml`:

    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 `hostLoopback: false` (available since Lima v2.3) in `lima.yaml`:
    

    ranacseruet ranacseruet commented on code on Oct 08, 2026 16:28 UTC
    Code Review
    website/content/en/docs/config/network/user.md:1
    @@ -21,6 +21,18 @@ Use [VMNet]({{< ref "/docs/config/network/vmnet" >}}) to allow accessing the gue
     
     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 `hostLoopback: false` in `lima.yaml`:
    +
    +```yaml
    +hostLoopback: false
    +```
    +
    +DNS, outbound connections to other hosts and `limactl shell` keep working. Connections to `host.lima.internal` are refused instead.
    +A host service that listens on all interfaces is still reachable through the host's LAN address.
    +A proxy on the host's loopback (for example `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.
    +
    +`hostLoopback: false` is only supported with `vmType: vz`, and not with a [`user-v2`]({{< ref "/docs/config/network/user-v2" >}}) network.

    Yes, we can. However, scope will increase a bit and I would propose it as a follow up PR, as also mentioned in our discussion on the issue thread(https://github.com/lima-vm/lima/issues/5574#issuecomment-6018078418).
    Let me know if that's ok with you.

    ranacseruet ranacseruet commented on code on Oct 08, 2026 16:28 UTC
    Code Review
    pkg/limatype/lima_yaml.go:1
    @@ -58,6 +58,7 @@ type LimaYAML struct {
     	Plain                *bool   `yaml:"plain,omitempty" json:"plain,omitempty" jsonschema:"nullable"`
     	TimeZone             *string `yaml:"timezone,omitempty" json:"timezone,omitempty" jsonschema:"nullable"`
     	NestedVirtualization *bool   `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty" jsonschema:"nullable"`
    +	HostLoopback         *bool   `yaml:"hostLoopback,omitempty" json:"hostLoopback,omitempty" jsonschema:"nullable"`

    Sounds good.
    Going to use networkOpts.hostLoopback unless you prefer different name. Will update the PR shortly.

    ranacseruet ranacseruet commented on code on Oct 08, 2026 16:28 UTC
    Code Review
    website/content/en/docs/config/network/user.md:1
    @@ -21,6 +21,18 @@ Use [VMNet]({{< ref "/docs/config/network/vmnet" >}}) to allow accessing the gue
     
     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 `hostLoopback: false` in `lima.yaml`:

    Thanks for the suggestion. Will fold it in the next PR update.

    ranacseruet ranacseruet commented on Oct 08, 2026 19:35 UTC
    Author

    @AkihiroSuda FYI: Done addressing your comments

    AkihiroSuda AkihiroSuda commented on Oct 09, 2026 09:29 UTC
    Reviewer

    Thanks

    AkihiroSuda AkihiroSuda commented on code on Oct 09, 2026 09:31 UTC
    Code Review
    ranacseruet ranacseruet commented on code on Oct 09, 2026 15:47 UTC
    Code Review
    website/content/en/docs/config/network/user.md:1

    Added hack/bats/extras/vz-host-loopback.bats and wired it into the vz job;

    ranacseruet ranacseruet commented on Oct 09, 2026 15:49 UTC
    Author

    The only red check in CI is the release job, which timed out (21 min vs its 20-min limit.
    @AkihiroSuda Could you re-run it?
    Also, the latest test push also dismissed your approval, a re-approval would be appreciated.

    jandubois jandubois commented on Oct 15, 2026 03:09 UTC
    Contributor

    Branch needs to be rebased to resolve merge conflict

    ranacseruet ranacseruet commented on Oct 15, 2026 13:12 UTC
    Author

    @jandubois Rebased on current master.
    Also, a re-approval would be appreciated.

    AkihiroSuda AkihiroSuda approved these changes on Oct 15, 2026 13:56 UTC
    Approved Reviewer

    Thanks

    jandubois jandubois approved these changes on Oct 15, 2026 18:58 UTC
    Approved Reviewer

    Thanks, LGTM

    AI review: https://jandubois.github.io/lima/20261015-112802-pr-5581.html

    Only contains suggestions; none of which are needed to merge the PR.

    Reviewers
    Assignees
    ranacseruet ranacseruet
    Labels
    risk: low confidence: 85.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 66.9% (HIGH) · Higher = larger blast radius
    66.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 85.6% · Lower = rushed or shallow review
    85.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.7% · Safe to merge
    9.7%
    Repository