Make SSH path handling consistent across providers during e2e

There were providers which would:
 - allow overrides of the file base name but not the path
 - allow oeverrides of the file path
 - not allow any overrides at all

This change makes it such that each of the supported providers
can override the SSH key location using an env var. The env
var itself may vary based on the provider though.

If given an absolute path to the key, it is used. If given
a relative path it will be made relative to ~/.ssh

Fixes: #68747
This commit is contained in:
John Schnake 2018-09-17 14:51:28 -05:00 committed by John Schnake
parent 817d420d68
commit 266080e18d

View File

@ -3530,44 +3530,43 @@ func DeletePodOrFail(c clientset.Interface, ns, name string) {
// GetSigner returns an ssh.Signer for the provider ("gce", etc.) that can be
// used to SSH to their nodes.
func GetSigner(provider string) (ssh.Signer, error) {
// Get the directory in which SSH keys are located.
keydir := filepath.Join(os.Getenv("HOME"), ".ssh")
// Select the key itself to use. When implementing more providers here,
// please also add them to any SSH tests that are disabled because of signer
// support.
keyfile := ""
key := ""
switch provider {
case "gce", "gke", "kubemark":
keyfile = "google_compute_engine"
case "aws":
// If there is an env. variable override, use that.
aws_keyfile := os.Getenv("AWS_SSH_KEY")
if len(aws_keyfile) != 0 {
return sshutil.MakePrivateKeySignerFromFile(aws_keyfile)
keyfile = os.Getenv("GCE_SSH_KEY")
if keyfile == "" {
keyfile = "google_compute_engine"
}
case "aws":
keyfile = os.Getenv("AWS_SSH_KEY")
if keyfile == "" {
keyfile = "kube_aws_rsa"
}
// Otherwise revert to home dir
keyfile = "kube_aws_rsa"
case "local", "vsphere":
keyfile = os.Getenv("LOCAL_SSH_KEY") // maybe?
if len(keyfile) == 0 {
keyfile = os.Getenv("LOCAL_SSH_KEY")
if keyfile == "" {
keyfile = "id_rsa"
}
case "skeleton":
keyfile = os.Getenv("KUBE_SSH_KEY")
if len(keyfile) == 0 {
if keyfile == "" {
keyfile = "id_rsa"
}
default:
return nil, fmt.Errorf("GetSigner(...) not implemented for %s", provider)
}
if len(key) == 0 {
key = filepath.Join(keydir, keyfile)
// Respect absolute paths for keys given by user, fallback to assuming
// relative paths are in ~/.ssh
if !filepath.IsAbs(keyfile) {
keydir := filepath.Join(os.Getenv("HOME"), ".ssh")
keyfile = filepath.Join(keydir, keyfile)
}
return sshutil.MakePrivateKeySignerFromFile(key)
return sshutil.MakePrivateKeySignerFromFile(keyfile)
}
// CheckPodsRunningReady returns whether all pods whose names are listed in