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/>.
17
from charmhelpers.contrib.hardening.audits.file import (
18
DirectoryPermissionAudit,
21
from charmhelpers.contrib.hardening.host import TEMPLATES_DIR
22
from charmhelpers.contrib.hardening import utils
26
"""Get OS hardening security limits audits.
28
:returns: dictionary of audits
31
settings = utils.get_settings('os')
33
# Ensure that the /etc/security/limits.d directory is only writable
34
# by the root user, but others can execute and read.
35
audits.append(DirectoryPermissionAudit('/etc/security/limits.d',
36
user='root', group='root',
39
# If core dumps are not enabled, then don't allow core dumps to be
40
# created as they may contain sensitive information.
41
if not settings['security']['kernel_enable_core_dump']:
42
audits.append(TemplatedFile('/etc/security/limits.d/10.hardcore.conf',
43
SecurityLimitsContext(),
44
template_dir=TEMPLATES_DIR,
45
user='root', group='root', mode=0o0440))
49
class SecurityLimitsContext(object):
52
settings = utils.get_settings('os')
53
ctxt = {'disable_core_dump':
54
not settings['security']['kernel_enable_core_dump']}