Skip to content

Commit 18813a1

Browse files
authored
Merge pull request #1485 from puppetlabs/maint-harden_root_password_class
Harden root password class
2 parents f83792b + f2b3bde commit 18813a1

File tree

6 files changed

+7
-24
lines changed

6 files changed

+7
-24
lines changed

manifests/params.pp

-1
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

-3
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

+2-7
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

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
ignore: []

spec/acceptance/01_mysql_db_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class { 'mysql::server':
3737
class { 'mysql::server': override_options => { 'root_password' => 'password' } }
3838
file { '/tmp/spec.sql':
3939
ensure => file,
40-
content => 'CREATE TABLE table1 (id int);',
40+
content => 'CREATE TABLE IF NOT EXISTS table1 (id int);',
4141
before => Mysql::Db['spec2'],
4242
}
4343
mysql::db { 'spec2':

spec/classes/mysql_server_spec.rb

+2-12
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@
158158
describe 'when defaults' do
159159
it {
160160
is_expected.to contain_exec('remove install pass').with(
161-
command: 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /.mysql_secret) password \'\' && rm -f /.mysql_secret',
162-
onlyif: 'test -f /.mysql_secret',
161+
command: "mysqladmin -u root --password=\$(grep -o '[^ ]\\+\$' /.mysql_secret) password && (rm -f /.mysql_secret; exit 0) || (rm -f /.mysql_secret; exit 1)",
162+
onlyif: [['test', '-f', '/.mysql_secret']],
163163
path: '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
164164
)
165165
}
@@ -198,16 +198,6 @@
198198
it { is_expected.not_to contain_mysql_user('root@localhost') }
199199
it { is_expected.not_to contain_file('/root/.my.cnf') }
200200
end
201-
describe 'when install_secret_file set to /root/.mysql_secret' do
202-
let(:params) { { install_secret_file: '/root/.mysql_secret' } }
203-
204-
it {
205-
is_expected.to contain_exec('remove install pass').with(
206-
command: 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /root/.mysql_secret) password \'\' && rm -f /root/.mysql_secret',
207-
onlyif: 'test -f /root/.mysql_secret',
208-
)
209-
}
210-
end
211201
end
212202

213203
context 'mysql::server::providers' do

0 commit comments

Comments
 (0)