Add secure method for reading in password

Signed-off-by: eschcam <cameron.scholes@est.tech>
pull/11610/head
eschcam 3 years ago
parent ced54b1289
commit 859e3a9728

@ -21,15 +21,17 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"strings" "strings"
"syscall"
"github.com/moby/term" "github.com/moby/term"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/cmd/helm/require"
"helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/action"
xTerm "golang.org/x/term"
) )
const registryLoginDesc = ` const registryLoginDesc = `
@ -74,12 +76,17 @@ func getUsernamePassword(usernameOpt string, passwordOpt string, passwordFromStd
password := passwordOpt password := passwordOpt
if passwordFromStdinOpt { if passwordFromStdinOpt {
passwordFromStdin, err := ioutil.ReadAll(os.Stdin) fmt.Printf("Enter registry password: ")
passwordFromStdin, err := xTerm.ReadPassword(int(syscall.Stdin))
fmt.Println()
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
password = strings.TrimSuffix(string(passwordFromStdin), "\n")
password = strings.TrimSuffix(password, "\r") password = string(passwordFromStdin)
password = strings.TrimSpace(password)
} else if password == "" { } else if password == "" {
if username == "" { if username == "" {
username, err = readLine("Username: ", false) username, err = readLine("Username: ", false)

Loading…
Cancel
Save