Skip to content

(CAT-1919) - Handle scenario when user input password in <anything-in-caps-with-alpha-numeric>*<alpha-numeric-40-chars-in-caps> #1634

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 1 commit into from
Jul 5, 2024
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
2 changes: 1 addition & 1 deletion lib/puppet/functions/mysql/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def password(password, sensitive = false)
password = password.unwrap if password.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)

result_string = if %r{\*[A-F0-9]{40}$}.match?(password)
result_string = if %r{^\*[A-F0-9]{40}$}.match?(password)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just have a few minutes right now, but I'm wondering why we have this regex at all? Does it check if it's a hash and otherwise runs into the last else block and runs SHA1?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the intention is if it's already a Hash, then don't hash it, but since the regex isn't anchored it can pick up other passwords. The other password looks incredibly unlikely in the real world though. But I guess @Ramesh7 bumped into this in their environment??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bastelfreak yeah, if its hash then it will return that otherwise it will hash it with SHA1.
@alexjfisher yeah, recently we encountered this and found there is flow in regex which needs to fix, so took it here.

password
elsif password.empty?
''
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/00_mysql_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class { '::mysql::server':
end

it 'can be set' do
apply_manifest(pp, catch_failures: true) do |r|
expect(r.stderr).to be_empty
end
# TODO : Returning warning message while running above manifest
# Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other'
apply_manifest(pp)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/functions/mysql_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
expect(subject).to run.with_params('').and_return('')
end

it 'converts the password when its given in caps with * sign' do
expect(subject).to run.with_params('AFDJKFD1*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29').and_return('*91FF6DD4E1FC57D2EFC57F49552D0596F7D46BAF')
end

it 'does not convert a password that is already a hash' do
expect(subject).to run.with_params('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19').and_return('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')
end
Expand Down
Loading