Skip to content

Commit 1fb7245

Browse files
authored
Merge pull request puppetlabs#1400 from cocker-cc/Use_Puppet-Datatype_Sensitive
Use Puppet-Datatype Sensitive
2 parents b70b3eb + 8413dbe commit 1fb7245

File tree

21 files changed

+121
-36
lines changed

21 files changed

+121
-36
lines changed

.puppet-lint.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
--relative
2+
--no-140chars-check

lib/puppet/functions/mysql/password.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,35 @@
77
Puppet::Functions.create_function(:'mysql::password') do
88
# @param password
99
# Plain text password.
10+
# @param sensitive
11+
# If the Postgresql-Passwordhash should be of Datatype Sensitive[String]
1012
#
1113
# @return hash
1214
# The mysql password hash from the clear text password.
1315
#
1416
dispatch :password do
15-
required_param 'String', :password
16-
return_type 'String'
17+
required_param 'Variant[String, Sensitive[String]]', :password
18+
optional_param 'Boolean', :sensitive
19+
return_type 'Variant[String, Sensitive[String]]'
1720
end
1821

19-
def password(password)
20-
return '' if password.empty?
21-
return password if %r{\*[A-F0-9]{40}$}.match?(password)
22-
'*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(password)).upcase
22+
def password(password, sensitive = false)
23+
if password.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
24+
password = password.unwrap
25+
end
26+
27+
result_string = if %r{\*[A-F0-9]{40}$}.match?(password)
28+
password
29+
elsif password.empty?
30+
''
31+
else
32+
'*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(password)).upcase
33+
end
34+
35+
if sensitive
36+
Puppet::Pops::Types::PSensitiveType::Sensitive.new(result_string)
37+
else
38+
result_string
39+
end
2340
end
2441
end

lib/puppet/functions/mysql_password.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
# @return
99
# The mysql password hash from the 4.x function mysql::password.
1010
dispatch :mysql_password do
11-
required_param 'String', :password
12-
return_type 'String'
11+
required_param 'Variant[String, Sensitive[String]]', :password
12+
optional_param 'Boolean', :sensitive
13+
return_type 'Variant[String, Sensitive[String]]'
1314
end
1415

15-
def mysql_password(password)
16+
def mysql_password(password, sensitive = false)
1617
call_function('deprecation', 'mysql_password', "This method has been deprecated, please use the namespaced version 'mysql::password' instead.")
17-
call_function('mysql::password', password)
18+
call_function('mysql::password', password, sensitive)
1819
end
1920
end

lib/puppet/provider/mysql_user/mysql.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def create
7474
max_updates_per_hour = @resource.value(:max_updates_per_hour) || 0
7575
tls_options = @resource.value(:tls_options) || ['NONE']
7676

77+
password_hash = password_hash.unwrap if password_hash.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
78+
7779
# Use CREATE USER to be compatible with NO_AUTO_CREATE_USER sql_mode
7880
# This is also required if you want to specify a authentication plugin
7981
if !plugin.nil?

manifests/backup/mysqlbackup.pp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
class mysql::backup::mysqlbackup (
77
$backupuser = '',
8-
$backuppassword = '',
8+
Variant[String, Sensitive[String]] $backuppassword = '',
99
$maxallowedpacket = '1M',
1010
$backupdir = '',
1111
$backupdirmode = '0700',
@@ -32,6 +32,11 @@
3232
$compression_command = undef,
3333
$compression_extension = undef,
3434
) inherits mysql::params {
35+
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
36+
$backuppassword.unwrap
37+
} else {
38+
$backuppassword
39+
}
3540
mysql_user { "${backupuser}@localhost":
3641
ensure => $ensure,
3742
password_hash => mysql::password($backuppassword),
@@ -104,7 +109,7 @@
104109
'incremental_base' => 'history:last_backup',
105110
'incremental_backup_dir' => $backupdir,
106111
'user' => $backupuser,
107-
'password' => $backuppassword,
112+
'password' => $backuppassword_unsensitive
108113
},
109114
}
110115
$options = mysql::normalise_and_deepmerge($default_options, $mysql::server::override_options)

manifests/backup/mysqldump.pp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
class mysql::backup::mysqldump (
66
$backupuser = '',
7-
$backuppassword = '',
7+
Variant[String, Sensitive[String]] $backuppassword = '',
88
$backupdir = '',
99
$maxallowedpacket = '1M',
1010
$backupdirmode = '0700',
@@ -33,6 +33,12 @@
3333
$compression_command = 'bzcat -zc',
3434
$compression_extension = '.bz2'
3535
) inherits mysql::params {
36+
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
37+
$backuppassword.unwrap
38+
} else {
39+
$backuppassword
40+
}
41+
3642
unless $::osfamily == 'FreeBSD' {
3743
if $backupcompress and $compression_command == 'bzcat -zc' {
3844
ensure_packages(['bzip2'])
@@ -82,6 +88,7 @@
8288
require => File['mysqlbackup.sh'],
8389
}
8490

91+
# TODO: use EPP instead of ERB, as EPP can handle Data of Type Sensitive without further ado
8592
file { 'mysqlbackup.sh':
8693
ensure => $ensure,
8794
path => '/usr/local/sbin/mysqlbackup.sh',

manifests/backup/xtrabackup.pp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class mysql::backup::xtrabackup (
66
$xtrabackup_package_name = $mysql::params::xtrabackup_package_name,
77
$backupuser = undef,
8-
$backuppassword = undef,
8+
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
99
$backupdir = '',
1010
$maxallowedpacket = '1M',
1111
$backupmethod = 'xtrabackup',
@@ -36,6 +36,12 @@
3636
) inherits mysql::params {
3737
ensure_packages($xtrabackup_package_name)
3838

39+
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
40+
$backuppassword.unwrap
41+
} else {
42+
$backuppassword
43+
}
44+
3945
if $backupuser and $backuppassword {
4046
mysql_user { "${backupuser}@localhost":
4147
ensure => $ensure,
@@ -121,6 +127,7 @@
121127
group => $backupdirgroup,
122128
}
123129

130+
# TODO: use EPP instead of ERB, as EPP can handle Data of Type Sensitive without further ado
124131
file { 'xtrabackup.sh':
125132
ensure => $ensure,
126133
path => '/usr/local/sbin/xtrabackup.sh',

manifests/bindings.pp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@
102102
) inherits mysql::params {
103103
case $::osfamily {
104104
'Archlinux': {
105-
if $java_enable { fail("::mysql::bindings::java cannot be managed by puppet on ${osfamily}
105+
if $java_enable { fail("::mysql::bindings::java cannot be managed by puppet on ${::facts['os']['family']}
106106
as it is not in official repositories. Please disable java mysql binding.") }
107107
if $perl_enable { include 'mysql::bindings::perl' }
108-
if $php_enable { warning("::mysql::bindings::php does not need to be managed by puppet on ${osfamily}
108+
if $php_enable { warning("::mysql::bindings::php does not need to be managed by puppet on ${::facts['os']['family']}
109109
as it is included in mysql package by default.") }
110110
if $python_enable { include 'mysql::bindings::python' }
111-
if $ruby_enable { fail("::mysql::bindings::ruby cannot be managed by puppet on %{osfamily}
111+
if $ruby_enable { fail("::mysql::bindings::ruby cannot be managed by puppet on %{::facts['os']['family']}
112112
as it is not in official repositories. Please disable ruby mysql binding.") }
113113
}
114114

manifests/bindings/client_dev.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
provider => $mysql::bindings::client_dev_package_provider,
1313
}
1414
} else {
15-
warning("No MySQL client development package configured for ${os}.")
15+
warning("No MySQL client development package configured for ${::facts['os']['family']}.")
1616
}
1717
}

manifests/bindings/daemon_dev.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
provider => $mysql::bindings::daemon_dev_package_provider,
1313
}
1414
} else {
15-
warning("No MySQL daemon development package configured for ${os}.")
15+
warning("No MySQL daemon development package configured for ${::facts['os']['family']}.")
1616
}
1717
}

0 commit comments

Comments
 (0)