From 93562b4955aaab1100060b2b7b875a188ae13ad0 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 14 Nov 2024 16:52:27 +0100 Subject: [PATCH] ssh_config: allow IdentityFile file with tilde The ssh_config can contain a path with ~/ to refer to the home dir like done on shells. Handle that special case and resolve the path correctly so it can be used. Signed-off-by: Paul Holzinger (cherry picked from commit cbb2820a7e1c0cb997b8809c6d5cd43f76e4fd7d) --- pkg/bindings/connection.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go index 9a12cbebe3..762e77d810 100644 --- a/pkg/bindings/connection.go +++ b/pkg/bindings/connection.go @@ -11,6 +11,7 @@ import ( "net/url" "os" "os/user" + "path/filepath" "strconv" "strings" "time" @@ -205,10 +206,15 @@ func sshClient(_url *url.URL, uri string, identity string, machine bool) (Connec if identity == "" { if val := cfg.Get(alias, "IdentityFile"); val != "" { - if val != ssh_config.Default("IdentityFile") { - identity = strings.Trim(val, "\"") - found = true + identity = strings.Trim(val, "\"") + if strings.HasPrefix(identity, "~/") { + homedir, err := os.UserHomeDir() + if err != nil { + return connection, fmt.Errorf("failed to find home dir: %w", err) + } + identity = filepath.Join(homedir, identity[2:]) } + found = true } }