mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Fixing ~/.ssh/identity handling
Signed-off-by: Valery Masiutsin <val.masutin@gmail.com>
This commit is contained in:
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/blang/semver/v4"
|
"github.com/blang/semver/v4"
|
||||||
"github.com/containers/common/pkg/ssh"
|
"github.com/containers/common/pkg/ssh"
|
||||||
"github.com/containers/podman/v5/version"
|
"github.com/containers/podman/v5/version"
|
||||||
|
"github.com/containers/storage/pkg/fileutils"
|
||||||
"github.com/kevinburke/ssh_config"
|
"github.com/kevinburke/ssh_config"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/net/proxy"
|
"golang.org/x/net/proxy"
|
||||||
@ -92,9 +93,7 @@ func NewConnection(ctx context.Context, uri string) (context.Context, error) {
|
|||||||
// or unix:///run/podman/podman.sock
|
// or unix:///run/podman/podman.sock
|
||||||
// or ssh://<user>@<host>[:port]/run/podman/podman.sock
|
// or ssh://<user>@<host>[:port]/run/podman/podman.sock
|
||||||
func NewConnectionWithIdentity(ctx context.Context, uri string, identity string, machine bool) (context.Context, error) {
|
func NewConnectionWithIdentity(ctx context.Context, uri string, identity string, machine bool) (context.Context, error) {
|
||||||
var (
|
var err error
|
||||||
err error
|
|
||||||
)
|
|
||||||
if v, found := os.LookupEnv("CONTAINER_HOST"); found && uri == "" {
|
if v, found := os.LookupEnv("CONTAINER_HOST"); found && uri == "" {
|
||||||
uri = v
|
uri = v
|
||||||
}
|
}
|
||||||
@ -210,15 +209,27 @@ func sshClient(_url *url.URL, uri string, identity string, machine bool) (Connec
|
|||||||
|
|
||||||
if identity == "" {
|
if identity == "" {
|
||||||
if val := cfg.Get(alias, "IdentityFile"); val != "" {
|
if val := cfg.Get(alias, "IdentityFile"); val != "" {
|
||||||
|
// we get default IdentityFile value (~/.ssh/identity) every time
|
||||||
|
// checking if we got default
|
||||||
|
defaultIdentityPath := val == ssh_config.Default("IdentityFile")
|
||||||
|
|
||||||
identity = strings.Trim(val, "\"")
|
identity = strings.Trim(val, "\"")
|
||||||
|
|
||||||
if strings.HasPrefix(identity, "~/") {
|
if strings.HasPrefix(identity, "~/") {
|
||||||
homedir, err := os.UserHomeDir()
|
homedir, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return connection, fmt.Errorf("failed to find home dir: %w", err)
|
return connection, fmt.Errorf("failed to find home dir: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
identity = filepath.Join(homedir, identity[2:])
|
identity = filepath.Join(homedir, identity[2:])
|
||||||
}
|
}
|
||||||
found = true
|
|
||||||
|
// if we have default value but no file exists ignoring identity
|
||||||
|
if err := fileutils.Exists(identity); err != nil && defaultIdentityPath {
|
||||||
|
identity = ""
|
||||||
|
} else {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +273,8 @@ func sshClient(_url *url.URL, uri string, identity string, machine bool) (Connec
|
|||||||
connection.Client = &http.Client{
|
connection.Client = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
DialContext: dialContext,
|
DialContext: dialContext,
|
||||||
}}
|
},
|
||||||
|
}
|
||||||
return connection, nil
|
return connection, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user