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 subprocess import (
22
from charmhelpers.core.hookenv import (
27
from charmhelpers.fetch import (
32
from charmhelpers.contrib.hardening.audits.file import (
36
from charmhelpers.contrib.hardening import utils
37
from charmhelpers.contrib.hardening.host import TEMPLATES_DIR
41
"""Get OS hardening PAM authentication audits.
43
:returns: dictionary of audits
47
settings = utils.get_settings('os')
49
if settings['auth']['pam_passwdqc_enable']:
50
audits.append(PasswdqcPAM('/etc/passwdqc.conf'))
52
if settings['auth']['retries']:
53
audits.append(Tally2PAM('/usr/share/pam-configs/tally2'))
55
audits.append(DeletedFile('/usr/share/pam-configs/tally2'))
60
class PasswdqcPAMContext(object):
64
settings = utils.get_settings('os')
66
ctxt['auth_pam_passwdqc_options'] = \
67
settings['auth']['pam_passwdqc_options']
72
class PasswdqcPAM(TemplatedFile):
73
"""The PAM Audit verifies the linux PAM settings."""
74
def __init__(self, path):
75
super(PasswdqcPAM, self).__init__(path=path,
76
template_dir=TEMPLATES_DIR,
77
context=PasswdqcPAMContext(),
84
for pkg in ['libpam-ccreds', 'libpam-cracklib']:
85
log("Purging package '%s'" % pkg, level=DEBUG),
88
apt_update(fatal=True)
89
for pkg in ['libpam-passwdqc']:
90
log("Installing package '%s'" % pkg, level=DEBUG),
94
"""Updates the PAM configuration after the file has been written"""
96
check_output(['pam-auth-update', '--package'])
97
except CalledProcessError as e:
98
log('Error calling pam-auth-update: %s' % e, level=ERROR)
101
class Tally2PAMContext(object):
105
settings = utils.get_settings('os')
107
ctxt['auth_lockout_time'] = settings['auth']['lockout_time']
108
ctxt['auth_retries'] = settings['auth']['retries']
113
class Tally2PAM(TemplatedFile):
114
"""The PAM Audit verifies the linux PAM settings."""
115
def __init__(self, path):
116
super(Tally2PAM, self).__init__(path=path,
117
template_dir=TEMPLATES_DIR,
118
context=Tally2PAMContext(),
125
apt_purge('libpam-ccreds')
126
apt_update(fatal=True)
127
apt_install('libpam-modules')
129
def post_write(self):
130
"""Updates the PAM configuration after the file has been written"""
132
check_output(['pam-auth-update', '--package'])
133
except CalledProcessError as e:
134
log('Error calling pam-auth-update: %s' % e, level=ERROR)