1
# Copyright 2016 Canonical Limited.
3
# This file is part of charm-helpers.
5
# charm-helpers is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3 as
7
# published by the Free Software Foundation.
9
# charm-helpers is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
20
from charmhelpers.core.hookenv import (
24
from charmhelpers.contrib.hardening.audits.file import (
26
DirectoryPermissionAudit,
29
from charmhelpers.contrib.hardening.mysql import TEMPLATES_DIR
30
from charmhelpers.contrib.hardening import utils
34
"""Get MySQL hardening config audits.
36
:returns: dictionary of audits
38
if subprocess.call(['which', 'mysql'], stdout=subprocess.PIPE) != 0:
39
log("MySQL does not appear to be installed on this node - "
40
"skipping mysql hardening", level=WARNING)
43
settings = utils.get_settings('mysql')
44
hardening_settings = settings['hardening']
45
my_cnf = hardening_settings['mysql-conf']
48
FilePermissionAudit(paths=[my_cnf], user='root',
49
group='root', mode=0o0600),
51
TemplatedFile(hardening_settings['hardening-conf'],
57
service_actions=[{'service': 'mysql',
58
'actions': ['restart']}]),
60
# MySQL and Percona charms do not allow configuration of the
61
# data directory, so use the default.
62
DirectoryPermissionAudit('/var/lib/mysql',
68
DirectoryPermissionAudit('/etc/mysql',
78
class MySQLConfContext(object):
79
"""Defines the set of key/value pairs to set in a mysql config file.
81
This context, when called, will return a dictionary containing the
82
key/value pairs of setting to specify in the
83
/etc/mysql/conf.d/hardening.cnf file.
86
settings = utils.get_settings('mysql')
87
# Translate for python3
88
return {'mysql_settings':
89
[(k, v) for k, v in six.iteritems(settings['security'])]}