Skip to content

fix: 🐛 improve password confirmation prompt (fixes #1390) #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
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
39 changes: 16 additions & 23 deletions cmd/saml2aws/commands/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ const OneLoginOAuthPath = "/auth/oauth2/v2/token"

// Configure configure account profiles
func Configure(configFlags *flags.CommonFlags) error {

idpAccountName := configFlags.IdpAccount
idpAccountPassword := configFlags.Password

// pass in alternative location of saml2aws config file, if set.
cfgm, err := cfg.NewConfigManager(configFlags.ConfigFile)
if err != nil {
return errors.Wrap(err, "failed to load configuration")
Expand All @@ -34,39 +32,34 @@ func Configure(configFlags *flags.CommonFlags) error {
return errors.Wrap(err, "failed to load idp account")
}

// update username and hostname if supplied
flags.ApplyFlagOverrides(configFlags, account)

// do we need to prompt for values now?
if !configFlags.SkipPrompt {
err = saml2aws.PromptForConfigurationDetails(account)
if err != nil {
return errors.Wrap(err, "failed to input configuration")
}
if configFlags.SkipPrompt {
return saveConfiguration(cfgm, idpAccountName, account, configFlags, idpAccountPassword)
}

if err = saml2aws.PromptForConfigurationDetails(account); err != nil {
return errors.Wrap(err, "failed to input configuration")
}

if credentials.SupportsStorage() && idpAccountPassword == "" {
password := prompter.Password("Password")
if password != "" {
if confirmPassword := prompter.Password("Confirm"); confirmPassword == password {
idpAccountPassword = password
} else {
log.Println("Passwords did not match")
os.Exit(1)
}
} else {
log.Println("No password supplied")
}
if credentials.SupportsStorage() && idpAccountPassword == "" {
idpAccountPassword = prompter.Password("Enter password")
if idpAccountPassword == "" {
log.Println("No password supplied")
}
}

return saveConfiguration(cfgm, idpAccountName, account, configFlags, idpAccountPassword)
}

func saveConfiguration(cfgm *cfg.ConfigManager, idpAccountName string, account *cfg.IDPAccount, configFlags *flags.CommonFlags, idpAccountPassword string) error {
if credentials.SupportsStorage() {
if err := storeCredentials(configFlags, account, idpAccountPassword); err != nil {
return err
}
}

err = cfgm.SaveIDPAccount(idpAccountName, account)
if err != nil {
if err := cfgm.SaveIDPAccount(idpAccountName, account); err != nil {
return errors.Wrap(err, "failed to save configuration")
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/saml2aws/commands/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ func Console(consoleFlags *flags.ConsoleFlags) error {
return errors.Wrap(err,
fmt.Sprintf("error loading credentials for profile: %s", consoleFlags.LoginExecFlags.ExecProfile))
}
if err != nil {
return errors.Wrap(err, "error logging in")
}

if consoleFlags.LoginExecFlags.ExecProfile != "" {
// Assume the desired role before generating env vars
Expand Down
Loading