Skip to content

Commit

Permalink
[CLOUD-53] Solicitar una sóla vez + reintentos la passphrase para el …
Browse files Browse the repository at this point in the history
…descifrado (kubernetes-sigs#344)

* version v0.18.0-alpha

* chore: Request the Vault password only once if the secret file exists.

* revert change

---------

Co-authored-by: Benjamin Elder <[email protected]>
  • Loading branch information
esierra-stratio and BenTheElder authored Oct 18, 2023
1 parent b87b071 commit 00081c4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/cmd/kind/create/cluster/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"

"syscall"
"time"
Expand Down Expand Up @@ -161,7 +162,7 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error {
}

if flags.VaultPassword == "" {
flags.VaultPassword, err = setPassword()
flags.VaultPassword, err = setPassword(secretsDefaultPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -238,17 +239,20 @@ func configOption(rawConfigFlag string, stdin io.Reader) (cluster.CreateOption,
return cluster.CreateWithRawConfig(raw), nil
}

func setPassword() (string, error) {
func setPassword(secretsDefaultPath string) (string, error) {
firstPassword, err := requestPassword("Vault Password: ")
if err != nil {
return "", err
}
secondPassword, err := requestPassword("Rewrite Vault Password:")
if err != nil {
return "", err
}
if firstPassword != secondPassword {
return "", errors.New("The passwords do not match.")

if _, err := os.Stat(secretsDefaultPath); os.IsNotExist(err) {
secondPassword, err := requestPassword("Rewrite Vault Password:")
if err != nil {
return "", err
}
if firstPassword != secondPassword {
return "", errors.New("The passwords do not match.")
}
}

return firstPassword, nil
Expand Down

0 comments on commit 00081c4

Please sign in to comment.