Merge pull request #14638 from Mia-Cross/load_ed25519_ssh_key

Add id_ed25519 to auto-loaded ssh keys
This commit is contained in:
Kubernetes Prow Robot 2022-11-28 04:32:07 -08:00 committed by GitHub
commit d1459d1581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 5 deletions

View File

@ -31,6 +31,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"go.uber.org/multierr"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
@ -734,17 +735,27 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr
} }
if autoloadSSHPublicKeys { if autoloadSSHPublicKeys {
// Load from default location, if found // Load from default locations, if found
sshPublicKeyPath := "~/.ssh/id_rsa.pub" sshPublicKeyPaths := []string{
"~/.ssh/id_rsa.pub",
"~/.ssh/id_ed25519.pub",
}
var merr error
for _, sshPublicKeyPath := range sshPublicKeyPaths {
c.SSHPublicKeys, err = loadSSHPublicKeys(sshPublicKeyPath) c.SSHPublicKeys, err = loadSSHPublicKeys(sshPublicKeyPath)
if err != nil { if err == nil {
break
}
// Don't wrap file-not-found // Don't wrap file-not-found
if os.IsNotExist(err) { if os.IsNotExist(err) {
klog.V(2).Infof("ssh key not found at %s", sshPublicKeyPath) klog.V(2).Infof("ssh key not found at %s", sshPublicKeyPath)
} else { } else {
return fmt.Errorf("error reading SSH key file %q: %v", sshPublicKeyPath, err) merr = multierr.Append(merr, err)
} }
} }
if merr != nil && len(c.SSHPublicKeys) == 0 {
return fmt.Errorf("error reading SSH public key files %q: %v", sshPublicKeyPaths, merr)
}
} }
} }