Skip to content

Commit

Permalink
When fqdn==localhost account security breaks
Browse files Browse the repository at this point in the history
This is because the root@localhost account is already
defined.

Remove localdomain accounts if fqdn is localhost
  • Loading branch information
dveeden committed Jan 18, 2015
1 parent 23c192d commit c04fed1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
26 changes: 21 additions & 5 deletions manifests/server/account_security.pp
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
class mysql::server::account_security {
mysql_user {
[ "root@${::fqdn}",
'[email protected]',
[ '[email protected]',
'root@::1',
"@${::fqdn}",
'@localhost',
'@%']:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
if ($::fqdn != $::hostname) {
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
if ($::fqdn != 'localhost.localdomain') {
mysql_user {
[ "[email protected]",
"@localhost.localdomain"]:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
}
if ($::fqdn != 'localhost') {
mysql_user {
[ "root@${::fqdn}",
"@${::fqdn}"]:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
}
if ($::fqdn != $::hostname) {
if ($::hostname != 'localhost') {
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
}
}
mysql_database { 'test':
ensure => 'absent',
require => Anchor['mysql::server::end'],
Expand Down
36 changes: 34 additions & 2 deletions spec/classes/mysql_server_account_security_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'@localhost',
'@%',
].each do |user|
it 'removes Mysql_User[#{user}]' do
it "removes Mysql_User[#{user}]" do
is_expected.to contain_mysql_user(user).with_ensure('absent')
end
end
Expand All @@ -22,7 +22,7 @@
# We don't need to test the inverse as when they match they are
# covered by the above list.
[ 'root@myhost', '@myhost' ].each do |user|
it 'removes Mysql_User[#{user}]' do
it "removes Mysql_User[#{user}]" do
is_expected.to contain_mysql_user(user).with_ensure('absent')
end
end
Expand All @@ -31,6 +31,38 @@
is_expected.to contain_mysql_database('test').with_ensure('absent')
end
end

describe "on #{pe_version} #{pe_platform} with fqdn==localhost" do
let(:facts) { facts.merge({:fqdn => 'localhost', :hostname => 'localhost'}) }

[ '[email protected]',
'root@::1',
'@localhost',
'[email protected]',
'@localhost.localdomain',
'@%',
].each do |user|
it "removes Mysql_User[#{user}]" do
is_expected.to contain_mysql_user(user).with_ensure('absent')
end
end
end

describe "on #{pe_version} #{pe_platform} with fqdn==localhost.localdomain" do
let(:facts) { facts.merge({:fqdn => 'localhost.localdomain', :hostname => 'localhost'}) }

[ '[email protected]',
'root@::1',
'@localhost',
'[email protected]',
'@localhost.localdomain',
'@%',
].each do |user|
it "removes Mysql_User[#{user}]" do
is_expected.to contain_mysql_user(user).with_ensure('absent')
end
end
end
end
end
end

0 comments on commit c04fed1

Please sign in to comment.