Skip to content

Commit 89d96bc

Browse files
committed
updated tls_options return to match MySQL documentation, added spec and acceptance tests
1 parent 9b76718 commit 89d96bc

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

lib/puppet/provider/mysql_user/mysql.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ def self.parse_tls_options(ssl_type, ssl_cipher, x509_issuer, x509_subject)
244244
['X509']
245245
elsif ssl_type == 'SPECIFIED'
246246
options = []
247-
options << "CIPHER #{ssl_cipher}" if !ssl_cipher.nil? && !ssl_cipher.empty?
248-
options << "ISSUER #{x509_issuer}" if !x509_issuer.nil? && !x509_issuer.empty?
249-
options << "SUBJECT #{x509_subject}" if !x509_subject.nil? && !x509_subject.empty?
247+
options << "CIPHER '#{ssl_cipher}'" if !ssl_cipher.nil? && !ssl_cipher.empty?
248+
options << "ISSUER '#{x509_issuer}'" if !x509_issuer.nil? && !x509_issuer.empty?
249+
options << "SUBJECT '#{x509_subject}'" if !x509_subject.nil? && !x509_subject.empty?
250250
options
251251
else
252252
['NONE']

spec/acceptance/types/mysql_user_spec.rb

+54
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,58 @@ class { 'mysql::server': * => $ed25519_opts }
199199
end
200200
end
201201
end
202+
context 'using user-w-subject@localhost with ISSUER and SUBJECT' do
203+
describe 'adding user' do
204+
pp_six = <<-MANIFEST
205+
mysql_user { 'user-w-subject@localhost':
206+
plugin => 'mysql_native_password',
207+
password_hash => '',
208+
tls_options => [
209+
"SUBJECT '/OU=MySQL Users/CN=username'",
210+
"ISSUER '/CN=Certificate Authority'",
211+
"CIPHER 'EDH-RSA-DES-CBC3-SHA'",
212+
],
213+
}
214+
MANIFEST
215+
216+
it 'works without errors' do
217+
idempotent_apply(pp_six)
218+
end
219+
220+
it 'finds the user #stdout' do
221+
run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r|
222+
expect(r.stdout).to match(%r{^1$})
223+
expect(r.stderr).to be_empty
224+
end
225+
end
226+
227+
it 'shows correct ssl_type #stdout' do
228+
run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r|
229+
expect(r.stdout).to match(%r{^SPECIFIED$})
230+
expect(r.stderr).to be_empty
231+
end
232+
end
233+
234+
it 'shows correct x509_issuer #stdout' do
235+
run_shell("mysql -NBe \"select X509_ISSUER from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r|
236+
expect(r.stdout).to match(%r{^/CN=Certificate Authority$})
237+
expect(r.stderr).to be_empty
238+
end
239+
end
240+
241+
it 'shows correct x509_subject #stdout' do
242+
run_shell("mysql -NBe \"select X509_SUBJECT from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r|
243+
expect(r.stdout).to match(%r{^/OU=MySQL Users/CN=username$})
244+
expect(r.stderr).to be_empty
245+
end
246+
end
247+
248+
it 'shows correct ssl_cipher #stdout' do
249+
run_shell("mysql -NBe \"select SSL_CIPHER from mysql.user where CONCAT(user, '@', host) = 'user-w-subject@localhost'\"") do |r|
250+
expect(r.stdout).to match(%r{^EDH-RSA-DES-CBC3-SHA$})
251+
expect(r.stderr).to be_empty
252+
end
253+
end
254+
end
255+
end
202256
end

spec/unit/puppet/provider/mysql_user/mysql_spec.rb

+38
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,44 @@
439439
end
440440
end
441441

442+
describe 'tls_options=required' do
443+
it 'adds mTLS option grant in mysql 5.5' do
444+
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.5'][:string])
445+
provider.class.expects(:mysql_caller).with("GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE ISSUER '/CN=Certificate Authority' AND SUBJECT '/OU=MySQL Users/CN=Username'", 'system').returns('0')
446+
447+
provider.expects(:tls_options).returns(['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\''])
448+
provider.tls_options = ['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\'']
449+
end
450+
it 'adds mTLS option grant in mysql 5.6' do
451+
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.6'][:string])
452+
provider.class.expects(:mysql_caller).with("GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE ISSUER '/CN=Certificate Authority' AND SUBJECT '/OU=MySQL Users/CN=Username'", 'system').returns('0')
453+
454+
provider.expects(:tls_options).returns(['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\''])
455+
provider.tls_options = ['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\'']
456+
end
457+
it 'adds mTLS option grant in mysql < 5.7.6' do
458+
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string])
459+
provider.class.expects(:mysql_caller).with("GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE ISSUER '/CN=Certificate Authority' AND SUBJECT '/OU=MySQL Users/CN=Username'", 'system').returns('0')
460+
461+
provider.expects(:tls_options).returns(['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\''])
462+
provider.tls_options = ['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\'']
463+
end
464+
it 'adds mTLS option grant in mysql >= 5.7.6' do
465+
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string])
466+
provider.class.expects(:mysql_caller).with("ALTER USER 'joe'@'localhost' REQUIRE ISSUER '/CN=Certificate Authority' AND SUBJECT '/OU=MySQL Users/CN=Username'", 'system').returns('0')
467+
468+
provider.expects(:tls_options).returns(['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\''])
469+
provider.tls_options = ['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\'']
470+
end
471+
it 'adds mTLS option grant in mariadb-10.0' do
472+
provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mariadb-10.0'][:string])
473+
provider.class.expects(:mysql_caller).with("GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE ISSUER '/CN=Certificate Authority' AND SUBJECT '/OU=MySQL Users/CN=Username'", 'system').returns('0')
474+
475+
provider.expects(:tls_options).returns(['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\''])
476+
provider.tls_options = ['ISSUER \'/CN=Certificate Authority\'', 'SUBJECT \'/OU=MySQL Users/CN=Username\'']
477+
end
478+
end
479+
442480
['max_user_connections', 'max_connections_per_hour', 'max_queries_per_hour', 'max_updates_per_hour'].each do |property|
443481
describe property do
444482
it "returns #{property}" do

0 commit comments

Comments
 (0)