Skip to content

Do the right thing when fqdn==localhost #637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}",
'root@127.0.0.1',
[ 'root@127.0.0.1',
'root@::1',
"@${::fqdn}",
'@localhost',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need root@localhost too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root@localhost should not be removed. That's the main account which is used if you connect over a UNIX socket, which is the default.

'@%']:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
if ($::fqdn != $::hostname) {
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
if ($::fqdn != 'localhost.localdomain') {
mysql_user {
[ "root@localhost.localdomain",
"@localhost.localdomain"]:
ensure => 'absent',
require => Anchor['mysql::server::end'],
}
}
if ($::fqdn != 'localhost') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if fqdn is localhost.localdomain? It would create duplicates in that case.

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'}) }

[ 'root@127.0.0.1',
'root@::1',
'@localhost',
'root@localhost.localdomain',
'@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'}) }

[ 'root@127.0.0.1',
'root@::1',
'@localhost',
'root@localhost.localdomain',
'@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