Skip to content

Commit 4750787

Browse files
Merge pull request #1284 from unki/adapt-group-owner-of-config-file
Allow changing the mysql-config-file group-ownership
2 parents 2d0d0f0 + e911dc0 commit 4750787

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

manifests/params.pp

+18
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
$datadir = '/var/lib/mysql'
9797
$root_group = 'root'
9898
$mysql_group = 'mysql'
99+
$mycnf_owner = undef
100+
$mycnf_group = undef
99101
$socket = '/var/lib/mysql/mysql.sock'
100102
$ssl_ca = '/etc/mysql/cacert.pem'
101103
$ssl_cert = '/etc/mysql/server-cert.pem'
@@ -152,6 +154,8 @@
152154
}
153155
$root_group = 'root'
154156
$mysql_group = 'mysql'
157+
$mycnf_owner = undef
158+
$mycnf_group = undef
155159
$server_service_name = 'mysql'
156160

157161
if $::operatingsystem =~ /(SLES|SLED)/ {
@@ -209,6 +213,8 @@
209213
$pidfile = '/var/run/mysqld/mysqld.pid'
210214
$root_group = 'root'
211215
$mysql_group = 'adm'
216+
$mycnf_owner = undef
217+
$mycnf_group = undef
212218
$socket = '/var/run/mysqld/mysqld.sock'
213219
$ssl_ca = '/etc/mysql/cacert.pem'
214220
$ssl_cert = '/etc/mysql/server-cert.pem'
@@ -253,6 +259,8 @@
253259
$pidfile = '/var/run/mysqld/mysqld.pid'
254260
$root_group = 'root'
255261
$mysql_group = 'mysql'
262+
$mycnf_owner = undef
263+
$mycnf_group = undef
256264
$server_service_name = 'mysqld'
257265
$socket = '/var/lib/mysql/mysql.sock'
258266
$ssl_ca = '/etc/mysql/cacert.pem'
@@ -278,6 +286,8 @@
278286
$pidfile = '/run/mysqld/mysqld.pid'
279287
$root_group = 'root'
280288
$mysql_group = 'mysql'
289+
$mycnf_owner = undef
290+
$mycnf_group = undef
281291
$server_service_name = 'mysql'
282292
$socket = '/run/mysqld/mysqld.sock'
283293
$ssl_ca = '/etc/mysql/cacert.pem'
@@ -303,6 +313,8 @@
303313
$pidfile = '/var/run/mysql.pid'
304314
$root_group = 'wheel'
305315
$mysql_group = 'mysql'
316+
$mycnf_owner = undef
317+
$mycnf_group = undef
306318
$server_service_name = 'mysql-server'
307319
$socket = '/var/db/mysql/mysql.sock'
308320
$ssl_ca = undef
@@ -331,6 +343,8 @@
331343
$pidfile = '/var/mysql/mysql.pid'
332344
$root_group = 'wheel'
333345
$mysql_group = '_mysql'
346+
$mycnf_owner = undef
347+
$mycnf_group = undef
334348
$server_service_name = 'mysqld'
335349
$socket = '/var/run/mysql/mysql.sock'
336350
$ssl_ca = undef
@@ -386,6 +400,8 @@
386400
$pidfile = '/run/mysqld/mysqld.pid'
387401
$root_group = 'root'
388402
$mysql_group = 'mysql'
403+
$mycnf_owner = undef
404+
$mycnf_group = undef
389405
$server_service_name = 'mariadb'
390406
$socket = '/run/mysqld/mysqld.sock'
391407
$ssl_ca = '/etc/mysql/cacert.pem'
@@ -411,6 +427,8 @@
411427
$pidfile = '/var/run/mysqld/mysqld.pid'
412428
$root_group = 'root'
413429
$mysql_group = 'mysql'
430+
$mycnf_owner = undef
431+
$mycnf_group = undef
414432
$server_service_name = 'mysqld'
415433
$socket = '/var/lib/mysql/mysql.sock'
416434
$ssl_ca = '/etc/mysql/cacert.pem'

manifests/server.pp

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
# The name of the group used for root. Can be a group name or a group ID. See more about the [group](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-group).
4242
# @param mysql_group
4343
# The name of the group of the MySQL daemon user. Can be a group name or a group ID. See more about the [group](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-group).
44+
# @param mycnf_owner
45+
# Name or user-id who owns the mysql-config-file.
46+
# @param mycnf_group
47+
# Name or group-id which owns the mysql-config-file.
4448
# @param root_password
4549
# The MySQL root password. Puppet attempts to set the root password and update `/root/.my.cnf` with it. This is required if `create_root_user` or `create_root_my_cnf` are true. If `root_password` is 'UNSET', then `create_root_user` and `create_root_my_cnf` are assumed to be false --- that is, the MySQL root user and `/root/.my.cnf` are not created. Password changes are supported; however, the old password must be set in `/root/.my.cnf`. Effectively, Puppet uses the old password, configured in `/root/my.cnf`, to set the new password in MySQL, and then updates `/root/.my.cnf` with the new password.
4650
# @param service_enabled
@@ -85,6 +89,8 @@
8589
$restart = $mysql::params::restart,
8690
$root_group = $mysql::params::root_group,
8791
$mysql_group = $mysql::params::mysql_group,
92+
$mycnf_owner = $mysql::params::mycnf_owner,
93+
$mycnf_group = $mysql::params::mycnf_group,
8894
$root_password = $mysql::params::root_password,
8995
$service_enabled = $mysql::params::server_service_enabled,
9096
$service_manage = $mysql::params::server_service_manage,

manifests/server/config.pp

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
path => $mysql::server::config_file,
3939
content => template('mysql/my.cnf.erb'),
4040
mode => $mysql::server::config_file_mode,
41+
owner => $mysql::server::mycnf_owner,
42+
group => $mysql::server::mycnf_group,
4143
selinux_ignore_defaults => true,
4244
}
4345

spec/classes/mycnf_template_spec.rb

+31
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,37 @@
128128
is_expected.to contain_file('mysql-config-file').with(mode: '0600')
129129
end
130130
end
131+
132+
context 'user owner 12345' do
133+
let(:params) { { 'mycnf_owner' => '12345' } }
134+
135+
it do
136+
is_expected.to contain_file('mysql-config-file').with(
137+
owner: '12345',
138+
)
139+
end
140+
end
141+
142+
context 'group owner 12345' do
143+
let(:params) { { 'mycnf_group' => '12345' } }
144+
145+
it do
146+
is_expected.to contain_file('mysql-config-file').with(
147+
group: '12345',
148+
)
149+
end
150+
end
151+
152+
context 'user and group owner 12345' do
153+
let(:params) { { 'mycnf_owner' => '12345', 'mycnf_group' => '12345' } }
154+
155+
it do
156+
is_expected.to contain_file('mysql-config-file').with(
157+
owner: '12345',
158+
group: '12345',
159+
)
160+
end
161+
end
131162
end
132163
end
133164
end

0 commit comments

Comments
 (0)