From ce07860a1c7989f81f849911764c1ad67fdf59b9 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 15 May 2023 16:37:47 +0200 Subject: [PATCH] machine: fix default connection URL to use 127.0.0.1 gvproxy listens on 127.0.0.1, using localhost as hostname can result in the client trying to connect to the ipv6 localhost (`::1`). This will fail as shown in the issue. This switches the hostname in the system connection to 127.0.0.1 to fix this problem. I switched the qemu, hyperV and WSL backend. I haven't touched the applehv code because it uses two different ips and I am not sure what is the correct thing there. I leave this to Brent to figure out. [NO NEW TESTS NEEDED] [1] https://github.com/containers/gvisor-tap-vsock/blob/main/cmd/gvproxy/main.go#L197-L199 Fixes #16470 Signed-off-by: Paul Holzinger --- pkg/machine/connection.go | 2 ++ pkg/machine/hyperv/machine.go | 4 ++-- pkg/machine/qemu/machine.go | 4 ++-- pkg/machine/wsl/machine.go | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/machine/connection.go b/pkg/machine/connection.go index 15e4fbef02..74db4ff50f 100644 --- a/pkg/machine/connection.go +++ b/pkg/machine/connection.go @@ -10,6 +10,8 @@ import ( "github.com/containers/common/pkg/config" ) +const LocalhostIP = "127.0.0.1" + func AddConnection(uri fmt.Stringer, name, identity string, isDefault bool) error { if len(identity) < 1 { return errors.New("identity must be defined") diff --git a/pkg/machine/hyperv/machine.go b/pkg/machine/hyperv/machine.go index 8ee9390672..baba8d68db 100644 --- a/pkg/machine/hyperv/machine.go +++ b/pkg/machine/hyperv/machine.go @@ -109,8 +109,8 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) { m.Port = sshPort if len(opts.IgnitionPath) < 1 { - uri := machine.SSHRemoteConnection.MakeSSHURL("localhost", fmt.Sprintf("/run/user/%d/podman/podman.sock", m.UID), strconv.Itoa(m.Port), m.RemoteUsername) - uriRoot := machine.SSHRemoteConnection.MakeSSHURL("localhost", "/run/podman/podman.sock", strconv.Itoa(m.Port), "root") + uri := machine.SSHRemoteConnection.MakeSSHURL(machine.LocalhostIP, fmt.Sprintf("/run/user/%d/podman/podman.sock", m.UID), strconv.Itoa(m.Port), m.RemoteUsername) + uriRoot := machine.SSHRemoteConnection.MakeSSHURL(machine.LocalhostIP, "/run/podman/podman.sock", strconv.Itoa(m.Port), "root") identity := filepath.Join(sshDir, m.Name) uris := []url.URL{uri, uriRoot} diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 634bf7220d..c54af5516b 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -318,8 +318,8 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { v.CmdLine = append(v.CmdLine, "-drive", "if=virtio,file="+v.getImageFile()) // This kind of stinks but no other way around this r/n if len(opts.IgnitionPath) < 1 { - uri := machine.SSHRemoteConnection.MakeSSHURL("localhost", fmt.Sprintf("/run/user/%d/podman/podman.sock", v.UID), strconv.Itoa(v.Port), v.RemoteUsername) - uriRoot := machine.SSHRemoteConnection.MakeSSHURL("localhost", "/run/podman/podman.sock", strconv.Itoa(v.Port), "root") + uri := machine.SSHRemoteConnection.MakeSSHURL(machine.LocalhostIP, fmt.Sprintf("/run/user/%d/podman/podman.sock", v.UID), strconv.Itoa(v.Port), v.RemoteUsername) + uriRoot := machine.SSHRemoteConnection.MakeSSHURL(machine.LocalhostIP, "/run/podman/podman.sock", strconv.Itoa(v.Port), "root") identity := filepath.Join(sshDir, v.Name) uris := []url.URL{uri, uriRoot} diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index b52d1303d1..b4674e6d46 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -503,8 +503,8 @@ func (v *MachineVM) writeConfig() error { } func setupConnections(v *MachineVM, opts machine.InitOptions, sshDir string) error { - uri := machine.SSHRemoteConnection.MakeSSHURL("localhost", rootlessSock, strconv.Itoa(v.Port), v.RemoteUsername) - uriRoot := machine.SSHRemoteConnection.MakeSSHURL("localhost", rootfulSock, strconv.Itoa(v.Port), "root") + uri := machine.SSHRemoteConnection.MakeSSHURL(machine.LocalhostIP, rootlessSock, strconv.Itoa(v.Port), v.RemoteUsername) + uriRoot := machine.SSHRemoteConnection.MakeSSHURL(machine.LocalhostIP, rootfulSock, strconv.Itoa(v.Port), "root") identity := filepath.Join(sshDir, v.Name) uris := []url.URL{uri, uriRoot}