From 971c9215d19ea5ab63f6e3eca971e186442564d6 Mon Sep 17 00:00:00 2001 From: Jack Weldon Date: Fri, 10 Jul 2020 15:44:39 -0400 Subject: [PATCH] feat(helm): prompt for password with helm repo add Previously in Helm 2, 'helm repo add' would prompt for your password if you only provided the --username flag. This helps prevent someone's credentials from being logged in their shell's history, from showing up in process lists, and from being seen by others nearby. Closes #7174 Signed-off-by: Jack Weldon --- cmd/helm/repo_add.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/helm/repo_add.go b/cmd/helm/repo_add.go index 9c67641e5..3abb58334 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -24,11 +24,13 @@ import ( "os" "path/filepath" "strings" + "syscall" "time" "github.com/gofrs/flock" "github.com/pkg/errors" "github.com/spf13/cobra" + "golang.org/x/crypto/ssh/terminal" "sigs.k8s.io/yaml" "helm.sh/helm/v3/cmd/helm/require" @@ -114,6 +116,16 @@ func (o *repoAddOptions) run(out io.Writer) error { return errors.Errorf("repository name (%s) already exists, please specify a different name", o.name) } + if o.username != "" && o.password == "" { + fmt.Fprint(out, "Password:") + password, err := terminal.ReadPassword(syscall.Stdin) + fmt.Fprintln(out) + if err != nil { + return err + } + o.password = string(password) + } + c := repo.Entry{ Name: o.name, URL: o.url,