|
5 | 5 | # == Parameters |
6 | 6 | # |
7 | 7 | # user - Database username. |
| 8 | +# auth_mechanism - Authentication mechanism. scram_sha_256 password verification is not supported. Defaults to 'scram_sha_1'. |
8 | 9 | # db_name - Database name. Defaults to $name. |
9 | 10 | # password_hash - Hashed password. Hex encoded md5 hash of "$username:mongo:$password". |
10 | 11 | # password - Plain text user password. This is UNSAFE, use 'password_hash' instead. |
11 | 12 | # roles (default: ['dbAdmin']) - array with user roles. |
12 | 13 | # tries (default: 10) - The maximum amount of two second tries to wait MongoDB startup. |
| 14 | +# update_password (default: false) - Force an update of the password when scram_sha_256 is used. |
13 | 15 | # |
14 | 16 | define mongodb::db ( |
15 | 17 | String $user, |
16 | | - String $db_name = $name, |
17 | | - Optional[Variant[String[1], Sensitive[String[1]]]] $password_hash = undef, |
18 | | - Optional[Variant[String[1], Sensitive[String[1]]]] $password = undef, |
19 | | - Array[String] $roles = ['dbAdmin'], |
20 | | - Integer[0] $tries = 10, |
| 18 | + Enum['scram_sha_1', 'scram_sha_256'] $auth_mechanism = 'scram_sha_1', |
| 19 | + String $db_name = $name, |
| 20 | + Optional[Variant[String[1], Sensitive[String[1]]]] $password_hash = undef, |
| 21 | + Optional[Variant[String[1], Sensitive[String[1]]]] $password = undef, |
| 22 | + Array[String] $roles = ['dbAdmin'], |
| 23 | + Integer[0] $tries = 10, |
| 24 | + Boolean $update_password = false, |
21 | 25 | ) { |
22 | 26 | unless $facts['mongodb_is_master'] == 'false' { # lint:ignore:quoted_booleans |
23 | 27 | mongodb_database { $db_name: |
|
35 | 39 | fail("Parameter 'password_hash' or 'password' should be provided to mongodb::db.") |
36 | 40 | } |
37 | 41 |
|
| 42 | + if $auth_mechanism == 'scram_sha_256' { |
| 43 | + $password_config = { |
| 44 | + password => $password, |
| 45 | + update_password => $update_password, |
| 46 | + } |
| 47 | + } else { |
| 48 | + $password_config = { |
| 49 | + password_hash => $hash, |
| 50 | + } |
| 51 | + } |
| 52 | + |
38 | 53 | mongodb_user { "User ${user} on db ${db_name}": |
39 | | - ensure => present, |
40 | | - password_hash => $hash, |
41 | | - username => $user, |
42 | | - database => $db_name, |
43 | | - roles => $roles, |
| 54 | + ensure => present, |
| 55 | + username => $user, |
| 56 | + database => $db_name, |
| 57 | + roles => $roles, |
| 58 | + auth_mechanism => $auth_mechanism, |
| 59 | + * => $password_config, |
44 | 60 | } |
45 | 61 | } |
46 | 62 | } |
0 commit comments