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

Switch to crypto/ssh for parsing of private keys #1404

Merged
merged 1 commit into from
May 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmd/flux/bootstrap_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
cryptossh "golang.org/x/crypto/ssh"
corev1 "k8s.io/api/core/v1"

"github.com/fluxcd/flux2/internal/bootstrap"
Expand Down Expand Up @@ -232,7 +233,20 @@ func transportForURL(u *url.URL) (transport.AuthMethod, error) {
}, nil
case "ssh":
if bootstrapArgs.privateKeyFile != "" {
return ssh.NewPublicKeysFromFile(u.User.Username(), bootstrapArgs.privateKeyFile, gitArgs.password)
// TODO(hidde): replace custom logic with https://github.com/go-git/go-git/pull/298
// once made available in go-git release.
bytes, err := ioutil.ReadFile(bootstrapArgs.privateKeyFile)
if err != nil {
return nil, err
}
signer, err := cryptossh.ParsePrivateKey(bytes)
if _, ok := err.(*cryptossh.PassphraseMissingError); ok {
signer, err = cryptossh.ParsePrivateKeyWithPassphrase(bytes, []byte(gitArgs.password))
}
if err != nil {
return nil, err
}
return &ssh.PublicKeys{Signer: signer, User: u.User.Username()}, nil
}
return nil, nil
default:
Expand Down