mirror of
https://github.com/containers/podman.git
synced 2025-12-02 11:08:36 +08:00
vendor latest c/{buildah,common,image,storage}
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
73
vendor/github.com/containers/common/pkg/ssh/connection_golang.go
generated
vendored
73
vendor/github.com/containers/common/pkg/ssh/connection_golang.go
generated
vendored
@@ -16,14 +16,20 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
// We are using skeema/knownhosts rather than
|
||||
// golang.org/x/crypto/ssh/knownhosts because the
|
||||
// latter has an issue when the first key returned
|
||||
// by the server doesn't match the one in known_hosts:
|
||||
// https://github.com/golang/go/issues/29286
|
||||
// https://github.com/containers/podman/issues/23575
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
"github.com/containers/storage/pkg/homedir"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/skeema/knownhosts"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/agent"
|
||||
"golang.org/x/crypto/ssh/knownhosts"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
@@ -301,46 +307,44 @@ func ValidateAndConfigure(uri *url.URL, iden string, insecureIsMachineConnection
|
||||
return nil, err
|
||||
}
|
||||
|
||||
keyFilePath := filepath.Join(homedir.Get(), ".ssh", "known_hosts")
|
||||
known, err := knownhosts.NewDB(keyFilePath)
|
||||
if err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return nil, err
|
||||
}
|
||||
keyDir := path.Dir(keyFilePath)
|
||||
if err := fileutils.Exists(keyDir); errors.Is(err, os.ErrNotExist) {
|
||||
if err := os.Mkdir(keyDir, 0o700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
k, err := os.OpenFile(keyFilePath, os.O_RDWR|os.O_CREATE, 0o600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
k.Close()
|
||||
known, err = knownhosts.NewDB(keyFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var callback ssh.HostKeyCallback
|
||||
if insecureIsMachineConnection {
|
||||
callback = ssh.InsecureIgnoreHostKey()
|
||||
} else {
|
||||
callback = ssh.HostKeyCallback(func(host string, remote net.Addr, pubKey ssh.PublicKey) error {
|
||||
keyFilePath := filepath.Join(homedir.Get(), ".ssh", "known_hosts")
|
||||
known, err := knownhosts.New(keyFilePath)
|
||||
if err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
keyDir := path.Dir(keyFilePath)
|
||||
if err := fileutils.Exists(keyDir); errors.Is(err, os.ErrNotExist) {
|
||||
if err := os.Mkdir(keyDir, 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
k, err := os.OpenFile(keyFilePath, os.O_RDWR|os.O_CREATE, 0o600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
k.Close()
|
||||
known, err = knownhosts.New(keyFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// we need to check if there is an error from reading known hosts for this public key and if there is an error, what is it, and why is it happening?
|
||||
// if it is a key mismatch we want to error since we know the host using another key
|
||||
// however, if it is a general error not because of a known key, we want to add our key to the known_hosts file
|
||||
hErr := known(host, remote, pubKey)
|
||||
var keyErr *knownhosts.KeyError
|
||||
// if keyErr.Want is not empty, we are receiving a different key meaning the host is known but we are using the wrong key
|
||||
as := errors.As(hErr, &keyErr)
|
||||
hErr := known.HostKeyCallback()(host, remote, pubKey)
|
||||
switch {
|
||||
case as && len(keyErr.Want) > 0:
|
||||
case knownhosts.IsHostKeyChanged(hErr):
|
||||
logrus.Warnf("ssh host key mismatch for host %s, got key %s of type %s", host, ssh.FingerprintSHA256(pubKey), pubKey.Type())
|
||||
return keyErr
|
||||
return hErr
|
||||
// if keyErr.Want is empty that just means we do not know this host yet, add it.
|
||||
case as && len(keyErr.Want) == 0:
|
||||
case knownhosts.IsHostUnknown(hErr):
|
||||
// write to known_hosts
|
||||
err := addKnownHostsEntry(host, pubKey)
|
||||
if err != nil {
|
||||
@@ -358,10 +362,11 @@ func ValidateAndConfigure(uri *url.URL, iden string, insecureIsMachineConnection
|
||||
}
|
||||
|
||||
cfg := &ssh.ClientConfig{
|
||||
User: uri.User.Username(),
|
||||
Auth: authMethods,
|
||||
HostKeyCallback: callback,
|
||||
Timeout: tick,
|
||||
User: uri.User.Username(),
|
||||
Auth: authMethods,
|
||||
HostKeyCallback: callback,
|
||||
Timeout: tick,
|
||||
HostKeyAlgorithms: known.HostKeyAlgorithms(uri.Host),
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
14
vendor/github.com/containers/common/pkg/timezone/timezone.go
generated
vendored
14
vendor/github.com/containers/common/pkg/timezone/timezone.go
generated
vendored
@@ -23,18 +23,20 @@ func ConfigureContainerTimeZone(timezone, containerRunDir, mountPoint, etcPath,
|
||||
switch {
|
||||
case timezone == "":
|
||||
return "", nil
|
||||
case os.Getenv("TZDIR") != "":
|
||||
// Allow using TZDIR per:
|
||||
// https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149
|
||||
|
||||
timezonePath = filepath.Join(os.Getenv("TZDIR"), timezone)
|
||||
case timezone == "local":
|
||||
timezonePath, err = filepath.EvalSymlinks("/etc/localtime")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("finding local timezone for container %s: %w", containerID, err)
|
||||
}
|
||||
default:
|
||||
timezonePath = filepath.Join("/usr/share/zoneinfo", timezone)
|
||||
// Allow using TZDIR per:
|
||||
// https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149
|
||||
zoneinfo := os.Getenv("TZDIR")
|
||||
if zoneinfo == "" {
|
||||
// default zoneinfo location
|
||||
zoneinfo = "/usr/share/zoneinfo"
|
||||
}
|
||||
timezonePath = filepath.Join(zoneinfo, timezone)
|
||||
}
|
||||
|
||||
etcFd, err := openDirectory(etcPath)
|
||||
|
||||
Reference in New Issue
Block a user