Skip to content

Commit c04fed1

Browse files
committed
When fqdn==localhost account security breaks
This is because the root@localhost account is already defined. Remove localdomain accounts if fqdn is localhost
1 parent 23c192d commit c04fed1

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

manifests/server/account_security.pp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
class mysql::server::account_security {
22
mysql_user {
3-
[ "root@${::fqdn}",
4-
3+
54
'root@::1',
6-
"@${::fqdn}",
75
'@localhost',
86
'@%']:
97
ensure => 'absent',
108
require => Anchor['mysql::server::end'],
119
}
12-
if ($::fqdn != $::hostname) {
13-
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
10+
if ($::fqdn != 'localhost.localdomain') {
11+
mysql_user {
12+
13+
"@localhost.localdomain"]:
14+
ensure => 'absent',
15+
require => Anchor['mysql::server::end'],
16+
}
17+
}
18+
if ($::fqdn != 'localhost') {
19+
mysql_user {
20+
[ "root@${::fqdn}",
21+
"@${::fqdn}"]:
1422
ensure => 'absent',
1523
require => Anchor['mysql::server::end'],
1624
}
1725
}
26+
if ($::fqdn != $::hostname) {
27+
if ($::hostname != 'localhost') {
28+
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
29+
ensure => 'absent',
30+
require => Anchor['mysql::server::end'],
31+
}
32+
}
33+
}
1834
mysql_database { 'test':
1935
ensure => 'absent',
2036
require => Anchor['mysql::server::end'],

spec/classes/mysql_server_account_security_spec.rb

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'@localhost',
1414
'@%',
1515
].each do |user|
16-
it 'removes Mysql_User[#{user}]' do
16+
it "removes Mysql_User[#{user}]" do
1717
is_expected.to contain_mysql_user(user).with_ensure('absent')
1818
end
1919
end
@@ -22,7 +22,7 @@
2222
# We don't need to test the inverse as when they match they are
2323
# covered by the above list.
2424
[ 'root@myhost', '@myhost' ].each do |user|
25-
it 'removes Mysql_User[#{user}]' do
25+
it "removes Mysql_User[#{user}]" do
2626
is_expected.to contain_mysql_user(user).with_ensure('absent')
2727
end
2828
end
@@ -31,6 +31,38 @@
3131
is_expected.to contain_mysql_database('test').with_ensure('absent')
3232
end
3333
end
34+
35+
describe "on #{pe_version} #{pe_platform} with fqdn==localhost" do
36+
let(:facts) { facts.merge({:fqdn => 'localhost', :hostname => 'localhost'}) }
37+
38+
39+
'root@::1',
40+
'@localhost',
41+
42+
'@localhost.localdomain',
43+
'@%',
44+
].each do |user|
45+
it "removes Mysql_User[#{user}]" do
46+
is_expected.to contain_mysql_user(user).with_ensure('absent')
47+
end
48+
end
49+
end
50+
51+
describe "on #{pe_version} #{pe_platform} with fqdn==localhost.localdomain" do
52+
let(:facts) { facts.merge({:fqdn => 'localhost.localdomain', :hostname => 'localhost'}) }
53+
54+
55+
'root@::1',
56+
'@localhost',
57+
58+
'@localhost.localdomain',
59+
'@%',
60+
].each do |user|
61+
it "removes Mysql_User[#{user}]" do
62+
is_expected.to contain_mysql_user(user).with_ensure('absent')
63+
end
64+
end
65+
end
3466
end
3567
end
3668
end

0 commit comments

Comments
 (0)