Skip to content
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

Add a common method for asking for a new password #251

Merged

Conversation

agrare
Copy link
Member

@agrare agrare commented May 10, 2024

When entering an existing password it is sufficient to prompt once since if the user mistyped the password it will fail later on, but when creating a new password it is common to re-prompt them to confirm that they didn't typo the new password.

We had this "prompt twice, check non-empty" loop in two places and were going to need it in a third so it seemed better to move this to a common method.

TODO

  • Live test on an appliance

Database configuration testing:

Each database region number must be unique.
Enter the database region number: 0
Enter the database password on localhost: 

Password can not be empty, please try again
Enter the database password on localhost: 

Password can not be empty, please try again
Enter the database password on localhost: *******
Enter the Re-enter database password on localhost: *****

The passwords did not match, please try again
Enter the database password on localhost: *******
Enter the Re-enter database password on localhost: *******

Message Server Configuration testing

Installed file /opt/kafka/config/server.properties found.

Already configured on this Appliance, Un-Configure first? (Y/N): Y
Remove Installed Files
Unconfigure Firewall
Deactivate Services

Proceed with Configuration? (Y/N): Y

Message Server Parameters:

Enter the Message Keystore Password: |admin| ss: |manageiq-devel.localdomain| 

Password can not be empty, please try again
Enter the Message Keystore Password: *******
Enter the Re-enter Message Keystore Password: *****

The passwords did not match, please try again
Enter the Message Keystore Password: *******
Enter the Re-enter Message Keystore Password: *******

Fixes ManageIQ/manageiq#23031

@agrare agrare force-pushed the add_common_method_for_prompting_new_password branch from 299176d to 18ae029 Compare May 10, 2024 16:47
end
self.database_name = just_ask("cluster database name", database_name)
self.database_user = just_ask("cluster database username", database_user)
self.database_password = ask_for_new_password("cluster database password", :default => database_password, :allow_empty => true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE I'm not sure if this was intentional but the old method did allow for an empty password

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird - @jrafanie or @bdunne do you know?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe because it has a default, allow empty allows it to use the default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/ManageIQ/manageiq-appliance_console/pull/251/files#diff-58f7d485041385eb768bd8d25d7e83a11ccf1a1bbf2bc4fb136fcdcf9cd6b590L126 had a default as well but that checks for a 0 length password. I think the default is only present if you've already configured a password but if this is the first time through there would be no default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was like that back to the initial open source commit.

It had a concept of no password, which I assume means the default, likely already configured with a password. I'm not sure though.

+    def ask_for_database_credentials
+      self.host     = ask_for_ip_or_hostname("database hostname or IP address", host) if host.blank? || !local?
+      self.database = just_ask("name of the database on #{host}", database) unless local?
+      self.username = just_ask("username", username) unless local?
+      count = 0
+      loop do
+        count += 1
+        password1   = ask_for_password_or_none("database password on #{host}", password)
+        # if they took the default, just bail
+        break if (password1 == password)
+        password2   = ask_for_password("database password again")
+        if password1 == password2
+          self.password = password1
+          break
+        elsif count > 1 # only reprompt password once
+          raise ArgumentError, "passwords did not match"
+        else
+          say("\nThe passwords did not match, please try again")
+        end
+      end
+    end

af46735

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I think I'm going to keep the behavior the same as the internal database configuration and not allow a non-default empty password.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrare I agree 👍

@agrare agrare force-pushed the add_common_method_for_prompting_new_password branch from 18ae029 to b0708b2 Compare May 10, 2024 16:53
@agrare agrare force-pushed the add_common_method_for_prompting_new_password branch 2 times, most recently from 4544ca6 to de20f41 Compare May 10, 2024 17:39
When entering an existing password it is sufficient to prompt once since
if the user mistyped the password it will fail later on, but when
creating a new password it is common to re-prompt them to confirm that
they didn't typo the new password.
@agrare agrare force-pushed the add_common_method_for_prompting_new_password branch from de20f41 to 7892d83 Compare May 10, 2024 19:32
@miq-bot
Copy link
Member

miq-bot commented May 10, 2024

Checked commit agrare@7892d83 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
6 files checked, 0 offenses detected
Everything looks fine. 🍰

@bdunne bdunne merged commit c619139 into ManageIQ:master May 15, 2024
5 of 6 checks passed
@agrare agrare deleted the add_common_method_for_prompting_new_password branch May 15, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Messaging server prompts should not accept empty password
6 participants