puppetlabs/puppetlabs-mongodb — pull request #150 by sjtubinlong (2014-12-12 04:04:56+00:00)
Title: Fix the bug that new user's password_hash will be rehashed

while we create a db and a user, we define something like this:

```
mongodb::db { 'testdb':
user => 'testuser',
password => 'testpass',
require => Class['::mongodb::server'],
}
```
or
```
mongodb::db { 'testdb':
user => 'testuser',
password_hash => '19c8747ac7b3654045c99bea032d61be',
require => Class['::mongodb::server'],
}
```

19c8747ac7b3654045c99bea032d61be is equal to md5('testuser:mongo:testpass').

what we expect here is that we can authenticate a user in a client like:

```python
db.authenticate('testuser', 'testpass')
```
or
```javascript
db.auth('testuser', 'testpass')
```

However, after I apply my puppet pp file the first time, I can only use the password_hash to auth a user:
```
db.auth('testuser', 'testpass')
```
The plaintext password 'testpass' doesn't work at all.

Later, I try to apply the same pp file again without modify anything. After that, something curious happened, puppet log notice me that the password_hash changed from 84b719f4c9000b640c3f1bfe3257341e to 19c8747ac7b3654045c99bea032d61be.
(Here 84b719f4c9000b640c3f1bfe3257341e is equal to md5('testuser:mongo:19c8747ac7b3654045c99bea032d61be') )

So I try to read the source code of this module, I found that it create a new User with the follwoing command:

```javascript
db.createUser{"user":"testuser","pwd":"19c8747ac7b3654045c99bea032d61be", "customData":{"createdBy":"Puppet Mongodb_user['testuser'] Password[@resource[:password_hash]]"},"roles":["dbAdmin"]}
```

and update a User's password user the following code:
```javascript
db.runCommand{"updateUser":"testuser","pwd":"19c8747ac7b3654045c99bea032d61be", "digestPassword":false}
```

where the field `digestPassword = false` tell the mongodb server store the user-hashed password directly.

The mongo js client's createUser command doesn't support the filed , so I fix it by changing createUser to runCommand.

PS. The filed `passwordDigestor` doesn't work.

My system is Debian 7, and my mongo version is 2.6.0