Skip to content

fix: use the instance SSH port for <instance>-host in brev refresh - #534

Open
Rudra184 wants to merge 1 commit into
brevdev:mainfrom
Rudra184:fix/531-brev-refresh-writes-instance-host
Open

Rudra184 wants to merge 1 commit into
brevdev:mainfrom
Rudra184:fix/531-brev-refresh-writes-instance-host

Conversation

@Rudra184

Copy link
Copy Markdown

Problem

With v0.6.337, brev refresh writes <instance>-host with the instance IP as Hostname but the gateway port as Port. The gateway port is not open on the instance, so ssh <instance>-host times out.

Cause

resolveWorkspaceSSH overrides HostSSHHostname with the instance's public IP/DNS but leaves HostSSHPort at its legacy value, which is the gateway port for VM-mode instances:

// To support the "--host" fallback, preserve the legacy hostname information returned by the initial workspace query.
if providerHostname := providerSSHHostname(environment.GetInstance(), port.GetHostname()); providerHostname != "" {
workspace.HostSSHHostname = providerHostname
workspace.HostSSHProxyHostname = ""
}

makeSSHConfigEntryV2 then writes the mismatched pair into the -host entry:

hostport := workspace.GetHostSSHPort()
hostuser := workspace.GetHostSSHUser()
hostSSHHostname := workspace.GetHostSSHHostname()
if workspace.HostSSHProxyHostname == "" {
projPath, err := workspace.GetProjectFolderPath()
if err != nil {
return "", breverrors.WrapAndTrace(err)
}
entry := SSHConfigEntryV2{
Alias: alias,
IdentityFile: privateKeyPath,
User: hostuser,
Dir: projPath,
HostName: hostSSHHostname,
Port: hostport,
}
tmpl, err := template.New(alias).Parse(SSHConfigEntryTemplateV3)
if err != nil {
return "", breverrors.WrapAndTrace(err)
}
hostSSHVal, err = tmplAndValToString(tmpl, entry)
if err != nil {
return "", breverrors.WrapAndTrace(err)
}

Fix

When the host hostname is overridden, HostSSHPort is now set at the same place from the instance's reported SSH port, falling back to 22 if unset (providerSSHPort). The hostname and port now always come from the same source. The gateway entry (SSHHostname/SSHPort) is untouched.

Verification

  • go test ./pkg/cmd/refresh/ -run TestEnrichWorkspacesWithSSHAccess_HostPortIsNeverTheGatewayPort: pass
  • go test ./pkg/cmd/refresh/ ./pkg/entity/: pass
  • go test ./pkg/ssh/ -skip JetBrains|GateWay: pass
  • go vet ./pkg/..., make fmtcheck, make lint, make test, go mod tidy -diff: pass

The new regression test starts with a legacy HostSSHPort equal to the gateway port (23126) and checks that the result is the instance port (2222) or 22 when unset, and that SSHPort stays 23126. It fails on the base commit and passes with the patch.

Not verified against a real instance; only unit tests were run.

Fixes #531

After refresh enrichment, HostSSHHostname is overridden with the
instance's public IP/DNS, but HostSSHPort kept its legacy value. For
VM-mode instances that value is the gateway port, which is not open
on the instance, so `ssh <instance>-host` timed out.

Set HostSSHPort together with the hostname override, from the
instance's reported SSH port and falling back to 22 when unset.
SSHHostname and SSHPort (the gateway pair) are unchanged.

Fixes brevdev#531

Signed-off-by: Rudra184 <bhattrudra235@gmail.com>
@Rudra184
Rudra184 requested a review from a team as a code owner November 14, 2026 03:52
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.

brev refresh writes <instance>-host with the instance IP but the gateway port (v0.6.337), so host SSH times out

1 participant