mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-21 07:01:47 +00:00
Merge pull request #1404 from fluxcd/private-key-password
This commit is contained in:
commit
99bdb20aeb
1 changed files with 15 additions and 1 deletions
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
cryptossh "golang.org/x/crypto/ssh"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/bootstrap"
|
"github.com/fluxcd/flux2/internal/bootstrap"
|
||||||
|
|
@ -232,7 +233,20 @@ func transportForURL(u *url.URL) (transport.AuthMethod, error) {
|
||||||
}, nil
|
}, nil
|
||||||
case "ssh":
|
case "ssh":
|
||||||
if bootstrapArgs.privateKeyFile != "" {
|
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
|
return nil, nil
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue