Skip to content

Commit b042af0

Browse files
committed
Add an option to force an update of the password when SCRAM-SHA-256 is used
1 parent b201149 commit b042af0

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,11 @@ Administrator authentication mechanism.
566566
scram_sha_256 password synchronization verification is not supported.
567567
Default: 'scram_sha_1'
568568

569+
##### `admin_update_password`
570+
Update password.
571+
Used with SCRAM-SHA-256 because password verification is not supported.
572+
Default: false
573+
569574
##### `admin_roles`
570575
Administrator user roles
571576

@@ -659,6 +664,11 @@ Can be either 'scram_sha_1' or 'scram_sha_256'.
659664
scram_sha_256 password synchronization verification is not supported.
660665
Default: 'scram_sha_1'
661666

667+
##### `update_password`
668+
Update password.
669+
Used with SCRAM-SHA-256 because password verification is not supported.
670+
Default: false
671+
662672
##### `roles`
663673
Array with user roles as string.
664674
Roles will be granted to user's database if no alternative database is explicitly defined.

lib/puppet/type/mongodb_user.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def to_s?(_value = @is)
9090
end
9191

9292
def insync?(_is)
93-
return true if @resource[:auth_mechanism] == :scram_sha_256
93+
return !@resource[:update_password] if @resource[:auth_mechanism] == :scram_sha_256
9494

9595
should_to_s == to_s?
9696
end
@@ -102,6 +102,11 @@ def insync?(_is)
102102
newvalues(:scram_sha_256, :scram_sha_1)
103103
end
104104

105+
newparam(:update_password, boolean: true) do
106+
desc 'Update password. Used with SCRAM-SHA-256 because password verification is not supported.'
107+
defaultto false
108+
end
109+
105110
newproperty(:scram_credentials) do
106111
desc 'The SCRAM-SHA-1 credentials of a user. These are read only and change when password or password_hash changes.'
107112
end

manifests/db.pp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
# password - Plain text user password. This is UNSAFE, use 'password_hash' instead.
1212
# roles (default: ['dbAdmin']) - array with user roles.
1313
# 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.
1415
#
1516
define mongodb::db (
1617
String $user,
17-
Enum['scram_sha_1', 'scram_sha_256'] $auth_mechanism = 'scram_sha_1',
18-
String $db_name = $name,
19-
Optional[Variant[String[1], Sensitive[String[1]]]] $password_hash = undef,
20-
Optional[Variant[String[1], Sensitive[String[1]]]] $password = undef,
21-
Array[String] $roles = ['dbAdmin'],
22-
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,
2325
) {
2426
unless $facts['mongodb_is_master'] == 'false' { # lint:ignore:quoted_booleans
2527
mongodb_database { $db_name:
@@ -39,7 +41,8 @@
3941

4042
if $auth_mechanism == 'scram_sha_256' {
4143
$password_config = {
42-
password => $password,
44+
password => $password,
45+
update_password => $update_password,
4346
}
4447
} else {
4548
$password_config = {

manifests/server.pp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
String $admin_username = $mongodb::params::admin_username,
7878
Optional[Variant[String, Sensitive[String]]] $admin_password = undef,
7979
Enum['scram_sha_1', 'scram_sha_256'] $admin_auth_mechanism = $mongodb::params::admin_auth_mechanism,
80+
Boolean $admin_update_password = false,
8081
Boolean $handle_creds = $mongodb::params::handle_creds,
8182
Boolean $store_creds = $mongodb::params::store_creds,
8283
Array $admin_roles = $mongodb::params::admin_roles,
@@ -106,10 +107,11 @@
106107
}
107108
if $create_admin and ($service_ensure == 'running' or $service_ensure == true) {
108109
mongodb::db { 'admin':
109-
user => $admin_username,
110-
auth_mechanism => $admin_auth_mechanism,
111-
password => $admin_password_unsensitive,
112-
roles => $admin_roles,
110+
user => $admin_username,
111+
auth_mechanism => $admin_auth_mechanism,
112+
password => $admin_password_unsensitive,
113+
roles => $admin_roles,
114+
update_password => $admin_update_password,
113115
}
114116

115117
# Make sure it runs before other DB creation

0 commit comments

Comments
 (0)