Skip to content

Commit

Permalink
ssh_config: allow IdentityFile file with tilde
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit cbb2820)
  • Loading branch information
Luap99 committed Nov 19, 2024
1 parent 28e7b23 commit 93562b4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/bindings/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"os"
"os/user"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 93562b4

Please sign in to comment.