Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add id_ed25519 to auto-loaded ssh keys #14638

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.uber.org/multierr"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -734,17 +735,27 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr
}

if autoloadSSHPublicKeys {
// Load from default location, if found
sshPublicKeyPath := "~/.ssh/id_rsa.pub"
c.SSHPublicKeys, err = loadSSHPublicKeys(sshPublicKeyPath)
if err != nil {
// Load from default locations, if found
sshPublicKeyPaths := []string{
"~/.ssh/id_rsa.pub",
"~/.ssh/id_ed25519.pub",
}
var merr error
for _, sshPublicKeyPath := range sshPublicKeyPaths {
c.SSHPublicKeys, err = loadSSHPublicKeys(sshPublicKeyPath)
if err == nil {
break
}
// Don't wrap file-not-found
if os.IsNotExist(err) {
klog.V(2).Infof("ssh key not found at %s", sshPublicKeyPath)
} 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)
}
}
}

Expand Down