Skip to content
Open
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
16 changes: 16 additions & 0 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,22 @@ func publicKey(file string) (ssh.AuthMethod, error) {
}

key, err := ssh.ParsePrivateKey(buffer)
if err != nil && err.Error() == "ssh: this private key is passphrase protected" {
// Note: Newer version of Go support the error type `PassphraseMissingError'. Using that, the error check is:
// if err, ok := err.(*PassphraseMissingError); !ok {...}
// Note: Put the variable name just into a variable; would need to be passed through from fx/middlewares/ssh.go
// using context.Contexter.
envName := "SSH_PASS_PHRASE"
passphrase := os.Getenv(envName)
if passphrase != "" {
key, err = ssh.ParsePrivateKeyWithPassphrase(buffer, []byte(passphrase))
if err != nil {
err = fmt.Errorf("Using passphrase from environment: %s, %v", envName, err)
}
} else {
err = fmt.Errorf("No passphrase defined by environment: %s, %v", envName, err)
}
}
if err != nil {
return nil, err
}
Expand Down