Skip to content

Commit 90168d9

Browse files
committed
Harden root_password class
Prior to this commit there was a possibility that malformed strings could be passed in to the resource. This could lead to unsafe executions on a remote system. The parameters that are susceptible are `install_secret_file`. This commit fixes the above by adding validation to ensure the given values confirm to expectation. `secret_file` is validated with a regular expression that ensures the given value is a valid path.
1 parent f83792b commit 90168d9

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

manifests/params.pp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
$purge_conf_dir = false
1010
$restart = false
1111
$root_password = 'UNSET'
12-
$install_secret_file = '/.mysql_secret'
1312
$server_package_ensure = 'present'
1413
$server_package_manage = true
1514
$server_service_manage = true

manifests/server.pp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
# The location, as a path, of !includedir for custom configuration overrides.
1818
# @param install_options
1919
# Passes [install_options](https://docs.puppetlabs.com/references/latest/type.html#package-attribute-install_options) array to managed package resources. You must pass the appropriate options for the specified package manager
20-
# @param install_secret_file
21-
# Path to secret file containing temporary root password.
2220
# @param manage_config_file
2321
# Whether the MySQL configuration file should be managed. Valid values are `true`, `false`. Defaults to `true`.
2422
# @param options
@@ -81,7 +79,6 @@
8179
$config_file_mode = $mysql::params::config_file_mode,
8280
$includedir = $mysql::params::includedir,
8381
$install_options = undef,
84-
$install_secret_file = $mysql::params::install_secret_file,
8582
$manage_config_file = $mysql::params::manage_config_file,
8683
Mysql::Options $options = {},
8784
$override_options = {},

manifests/server/root_password.pp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@
1616
}
1717

1818
$options = $mysql::server::_options
19-
$secret_file = $mysql::server::install_secret_file
2019
$login_file = $mysql::server::login_file
2120

2221
# New installations of MySQL will configure a default random password for the root user
2322
# with an expiration. No actions can be performed until this password is changed. The
2423
# below exec will remove this default password. If the user has supplied a root
2524
# password it will be set further down with the mysql_user resource.
26-
$rm_pass_cmd = join([
27-
"mysqladmin -u root --password=\$(grep -o '[^ ]\\+\$' ${secret_file}) password ''",
28-
"rm -f ${secret_file}",
29-
], ' && ')
3025
exec { 'remove install pass':
31-
command => $rm_pass_cmd,
32-
onlyif => "test -f ${secret_file}",
26+
command => "mysqladmin -u root --password=\$(grep -o '[^ ]\\+\$' /.mysql_secret) password && (rm -f /.mysql_secret; exit 0) || (rm -f /.mysql_secret; exit 1)",
27+
onlyif => [['test', '-f' ,'/.mysql_secret']],
3328
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
3429
}
3530

pdk.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
ignore: []

0 commit comments

Comments
 (0)