~canonical-hw-cert/charms/xenial/snappy-device-agent/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/hardening/host/checks/minimize_access.py

  • Committer: Paul Larson
  • Date: 2016-05-16 20:27:32 UTC
  • Revision ID: paul.larson@canonical.com-20160516202732-9r4nkyl2f91w9xo3
Add support for xenial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2016 Canonical Limited.
 
2
#
 
3
# This file is part of charm-helpers.
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
 
16
 
 
17
from charmhelpers.contrib.hardening.audits.file import (
 
18
    FilePermissionAudit,
 
19
    ReadOnly,
 
20
)
 
21
from charmhelpers.contrib.hardening import utils
 
22
 
 
23
 
 
24
def get_audits():
 
25
    """Get OS hardening access audits.
 
26
 
 
27
    :returns:  dictionary of audits
 
28
    """
 
29
    audits = []
 
30
    settings = utils.get_settings('os')
 
31
 
 
32
    # Remove write permissions from $PATH folders for all regular users.
 
33
    # This prevents changing system-wide commands from normal users.
 
34
    path_folders = {'/usr/local/sbin',
 
35
                    '/usr/local/bin',
 
36
                    '/usr/sbin',
 
37
                    '/usr/bin',
 
38
                    '/bin'}
 
39
    extra_user_paths = settings['environment']['extra_user_paths']
 
40
    path_folders.update(extra_user_paths)
 
41
    audits.append(ReadOnly(path_folders))
 
42
 
 
43
    # Only allow the root user to have access to the shadow file.
 
44
    audits.append(FilePermissionAudit('/etc/shadow', 'root', 'root', 0o0600))
 
45
 
 
46
    if 'change_user' not in settings['security']['users_allow']:
 
47
        # su should only be accessible to user and group root, unless it is
 
48
        # expressly defined to allow users to change to root via the
 
49
        # security_users_allow config option.
 
50
        audits.append(FilePermissionAudit('/bin/su', 'root', 'root', 0o750))
 
51
 
 
52
    return audits