Skip to content

feat: add forward subcommand to reach guest ports from the host - #6

Merged
stempler merged 2 commits into
mainfrom
feat/forward-guest-ports
Oct 19, 2026
Merged

stempler merged 2 commits into
mainfrom
feat/forward-guest-ports

Conversation

@stempler

Copy link
Copy Markdown
Member

Lima's automatic port forwarding is switched off so nothing in the guest reaches the host on its own, which also left no way to open a dev server or mockup running in the VM in a host browser.

code-vm forward PORT|HOST_PORT:GUEST_PORT... opens an SSH tunnel over the instance's Lima ssh config for as long as it runs. The host side always binds 127.0.0.1, so the guest is never exposed to the host's network, and nothing is persisted: the default stays closed. The VM must already be running; forward does not boot it.

ExitOnForwardFailure turns a busy host port into an error. Interrupt and terminate signals are relayed to ssh, since a signal sent to code-vm alone (a script stopping a background forward) would otherwise leave the tunnel open.

Lima's automatic port forwarding is switched off so nothing in the guest
reaches the host on its own, which also left no way to open a dev server
or mockup running in the VM in a host browser.

`code-vm forward PORT|HOST_PORT:GUEST_PORT...` opens an SSH tunnel over
the instance's Lima ssh config for as long as it runs. The host side
always binds 127.0.0.1, so the guest is never exposed to the host's
network, and nothing is persisted: the default stays closed. The VM must
already be running; forward does not boot it.

ExitOnForwardFailure turns a busy host port into an error. Interrupt and
terminate signals are relayed to ssh, since a signal sent to code-vm
alone (a script stopping a background forward) would otherwise leave the
tunnel open.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Binding and cleanup assertions can silently pass when socket inspection fails, including on default macOS installations.

1 open issue
What changed in this PR

Adds explicit, temporary SSH forwarding so host applications can reach guest servers while automatic forwarding remains disabled.

Changes:

  • Adds loopback-only forwarding with port validation and signal handling.
  • Retrieves Lima SSH connection details without starting the VM.
  • Documents usage and adds unit and integration tests.
File Description
test-vm-sandbox.sh Tests reachability, binding, and cleanup.
README.md Documents explicit port forwarding.
internal/​lima/​limactl.go Exposes SSH configuration and host alias.
internal/​cli/​root.go Registers the forward command.
internal/​cli/​forward.go Implements validation and tunnel lifecycle.
internal/​cli/​forward_test.go Tests arguments, VM state, and termination.

Review effort: Balanced

Comment thread test-vm-sandbox.sh Outdated
The listener checks piped `ss` straight into grep, so a missing `ss`
(macOS has no iproute2) read as "nothing is listening" and the loopback
and cleanup guarantees passed without being verified. A helper now lists
listeners with `ss` on Linux or `lsof` on macOS and fails the check when
neither runs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved issues were identified in validation, loopback binding, instance targeting, or tunnel cleanup.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@stempler
stempler merged commit 5b728df into main Oct 19, 2026
8 checks passed
@stempler
stempler deleted the feat/forward-guest-ports branch October 19, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants