From 14ef6a91bd9beffd94c1b231c7ab185de3e5ae9e Mon Sep 17 00:00:00 2001 From: Charlie Doern Date: Tue, 15 Nov 2022 16:52:42 -0500 Subject: [PATCH] fix port issues for CONTAINER_HOST if no port is specified for an ssh style url, default to 22 resolves #16509 Signed-off-by: Charlie Doern --- pkg/bindings/connection.go | 9 ++++++--- test/e2e/system_connection_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go index a3677d3932..48575c8598 100644 --- a/pkg/bindings/connection.go +++ b/pkg/bindings/connection.go @@ -91,9 +91,12 @@ func NewConnectionWithIdentity(ctx context.Context, uri string, identity string, var connection Connection switch _url.Scheme { case "ssh": - port, err := strconv.Atoi(_url.Port()) - if err != nil { - return nil, err + port := 22 + if _url.Port() != "" { + port, err = strconv.Atoi(_url.Port()) + if err != nil { + return nil, err + } } conn, err := ssh.Dial(&ssh.ConnectionDialOptions{ Host: uri, diff --git a/test/e2e/system_connection_test.go b/test/e2e/system_connection_test.go index 3c320778aa..729d92a606 100644 --- a/test/e2e/system_connection_test.go +++ b/test/e2e/system_connection_test.go @@ -281,6 +281,15 @@ var _ = Describe("podman system connection", func() { _, err = Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).ToNot(HaveOccurred()) + // export the container_host env var and try again + err = os.Setenv("CONTAINER_HOST", fmt.Sprintf("ssh://%s@localhost", u.Username)) + Expect(err).ToNot(HaveOccurred()) + defer os.Unsetenv("CONTAINER_HOST") + + cmd = exec.Command(podmanTest.RemotePodmanBinary, "ps") + _, err = Start(cmd, GinkgoWriter, GinkgoWriter) + Expect(err).ToNot(HaveOccurred()) + uri := url.URL{ Scheme: "ssh", User: url.User(u.Username),