Skip to content

Commit

Permalink
Add support for ssh_config for connection
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Sep 1, 2024
1 parent 8d2b55d commit 59c8f28
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hugelgupf/p9 v0.3.1-0.20230822151754-54f5c5530921
github.com/json-iterator/go v1.1.12
github.com/kevinburke/ssh_config v1.2.0
github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2
github.com/mattn/go-shellwords v1.0.12
github.com/mattn/go-sqlite3 v1.14.18
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
26 changes: 26 additions & 0 deletions pkg/bindings/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/blang/semver/v4"
"github.com/containers/common/pkg/ssh"
"github.com/containers/podman/v4/version"
"github.com/kevinburke/ssh_config"
"github.com/sirupsen/logrus"
"golang.org/x/net/proxy"
)
Expand Down Expand Up @@ -115,6 +116,31 @@ func NewConnectionWithIdentity(ctx context.Context, uri string, identity string,
return nil, err
}
}
// ssh_config
alias := _url.Hostname()
logrus.Debugf("Alias: %s", alias)
cfg := ssh_config.DefaultUserSettings
if val := cfg.Get(alias, "User"); val != "" {
_url.User = url.User(val)
logrus.Debugf("User: %s", val)
}
if val := cfg.Get(alias, "Hostname"); val != "" {
uri = val
logrus.Debugf("Hostname: %s", val)
}
if val := cfg.Get(alias, "Port"); val != "" {
port, err = strconv.Atoi(val)
if err != nil {
return nil, err
}
logrus.Debugf("Port: %s", val)
}
if val := cfg.Get(alias, "IdentityFile"); val != "" {
if val != ssh_config.Default("IdentityFile") {
identity = strings.Trim(val, "\"")
logrus.Debugf("Identity: %s", val)
}
}
conn, err := ssh.Dial(&ssh.ConnectionDialOptions{
Host: uri,
Identity: identity,
Expand Down
3 changes: 3 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ github.com/josharian/intern
# github.com/json-iterator/go v1.1.12
## explicit; go 1.12
github.com/json-iterator/go
# github.com/kevinburke/ssh_config v1.2.0
## explicit
github.com/kevinburke/ssh_config
# github.com/klauspost/compress v1.17.3
## explicit; go 1.19
github.com/klauspost/compress
Expand Down

0 comments on commit 59c8f28

Please sign in to comment.