Skip to content
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

Allow authentication plugin to be changed #1004

Merged
merged 1 commit into from
Jan 18, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/puppet/provider/mysql_user/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ def max_updates_per_hour=(int)
(max_updates_per_hour == int) ? (return true) : (return false)
end

def plugin=(string)
merged_name = self.class.cmd_user(@resource[:name])

if (mysqld_type == 'mysql' || mysqld_type == 'percona') && Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0
sql = "ALTER USER #{merged_name} IDENTIFIED WITH '#{string}'"
sql << " AS '#{@resource[:password_hash]}'" if string == 'mysql_native_password'
else
# See https://bugs.mysql.com/bug.php?id=67449
sql = "UPDATE mysql.user SET plugin = '#{string}'"
sql << ((string == 'mysql_native_password') ? ", password = '#{@resource[:password_hash]}'" : ", password = ''")
sql << " WHERE CONCAT(user, '@', host) = '#{@resource[:name]}'"
end

mysql([defaults_file, system_database, '-e', sql].compact)
(plugin == string) ? (return true) : (return false)
end

def tls_options=(array)
merged_name = self.class.cmd_user(@resource[:name])
merged_tls_options = array.join(' AND ')
Expand Down
26 changes: 26 additions & 0 deletions spec/acceptance/types/mysql_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ class { 'mysql::server': }
end
end
end

describe 'changing authentication plugin' do
it 'should work without errors' do
pp = <<-EOS
mysql_user { 'ashp@localhost':
plugin => 'auth_socket',
}
EOS

apply_manifest(pp, :catch_failures => true)
end

it 'should have correct plugin' do
shell("mysql -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
expect(r.stdout.rstrip).to eq('auth_socket')
expect(r.stderr).to be_empty
end
end

it 'should not have a password' do
shell("mysql -NBe \"select password from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r|
expect(r.stdout.rstrip).to be_empty
expect(r.stderr).to be_empty
end
end
end
end

context 'using ashp-dash@localhost' do
Expand Down
46 changes: 46 additions & 0 deletions spec/unit/puppet/provider/mysql_user/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,52 @@
end
end

describe 'plugin=' do
context 'auth_socket' do
context 'MySQL < 5.7.6' do
it 'changes the authentication plugin' do
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string])
provider.expects(:mysql).with([defaults_file, system_database, '-e', "UPDATE mysql.user SET plugin = 'auth_socket', password = '' WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('0')

provider.expects(:plugin).returns('auth_socket')
provider.plugin = 'auth_socket'
end
end

context 'MySQL >= 5.7.6' do
it 'changes the authentication plugin' do
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string])
provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'auth_socket'"]).returns('0')

provider.expects(:plugin).returns('auth_socket')
provider.plugin = 'auth_socket'
end
end
end

context 'mysql_native_password' do
context 'MySQL < 5.7.6' do
it 'changes the authentication plugin' do
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string])
provider.expects(:mysql).with([defaults_file, system_database, '-e', "UPDATE mysql.user SET plugin = 'mysql_native_password', password = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('0')

provider.expects(:plugin).returns('mysql_native_password')
provider.plugin = 'mysql_native_password'
end
end

context 'MySQL >= 5.7.6' do
it 'changes the authentication plugin' do
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string])
provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'"]).returns('0')

provider.expects(:plugin).returns('mysql_native_password')
provider.plugin = 'mysql_native_password'
end
end
end
end

describe 'tls_options=' do
it 'adds SSL option grant in mysql 5.5' do
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.5'][:string])
Expand Down