Skip to content

Commit

Permalink
feat(helm): hiding password input on terminal
Browse files Browse the repository at this point in the history
When using "helm repo add" with "--username" and without "--password",
hide user's input with a password prompt. This allows users to not
expose their passwords to the command line history.
  • Loading branch information
imroc committed Aug 27, 2018
1 parent 4589ae2 commit 518a9d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/helm/repo_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import (

"github.com/spf13/cobra"

"golang.org/x/crypto/ssh/terminal"
"k8s.io/helm/pkg/getter"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/repo"
"syscall"
)

type repoAddCmd struct {
Expand Down Expand Up @@ -73,13 +75,31 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
}

func (a *repoAddCmd) run() error {
if a.username != "" && a.password == "" {
fmt.Fprint(a.out, "Password:")
password, err := readPassword()
fmt.Fprintln(a.out)
if err != nil {
return err
}
a.password = password
}

if err := addRepository(a.name, a.url, a.username, a.password, a.home, a.certFile, a.keyFile, a.caFile, a.noupdate); err != nil {
return err
}
fmt.Fprintf(a.out, "%q has been added to your repositories\n", a.name)
return nil
}

func readPassword() (string, error) {
password, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
return "", err
}
return string(password), nil
}

func addRepository(name, url, username, password string, home helmpath.Home, certFile, keyFile, caFile string, noUpdate bool) error {
f, err := repo.LoadRepositoriesFile(home.RepositoryFile())
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import:
- package: golang.org/x/crypto
subpackages:
- openpgp
- ssh/terminal
# pin version of golang.org/x/sys that is compatible with golang.org/x/crypto
- package: golang.org/x/sys
version: 43eea11
Expand Down

0 comments on commit 518a9d6

Please sign in to comment.