Skip to content

Commit

Permalink
Set correct auth_mechanism for updateUser
Browse files Browse the repository at this point in the history
Currently the mongodb command `updateUser` defaults to SCRAM-SHA-256 but you can't update these passwords.

And also show an error when the update goes wrong.
  • Loading branch information
JvGinkel committed Jan 26, 2023
1 parent 60e16ce commit 1658799
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/puppet/provider/mongodb_user/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ def password_hash=(_value)
command = {
updateUser: @resource[:username],
pwd: @resource[:password_hash],
digestPassword: false
digestPassword: false,
mechanisms: @resource[:auth_mechanism] == :scram_sha_1 ? ['SCRAM-SHA-1'] : ['SCRAM-SHA-256'],
}

mongo_eval("db.runCommand(#{command.to_json})", @resource[:database])
out = JSON.parse(mongo_eval("db.runCommand(#{command.to_json})", @resource[:database]))
raise "Failed update User password for user '#{@resource[:username]}'\n#{out}" if out['ok'].zero?
else
Puppet.warning 'User password operations are available only from master host'
end
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
{
"updateUser":"new_user",
"pwd":"pass",
"digestPassword":false
"digestPassword":false,
"mechanisms":["SCRAM-SHA-1"]
}
EOS
allow(provider).to receive(:mongo_eval).
Expand Down

0 comments on commit 1658799

Please sign in to comment.