示例#1
0
def get_audits():
    """Get OS hardening access audits.

    :returns:  dictionary of audits
    """
    audits = []
    settings = utils.get_settings('os')

    # Remove write permissions from $PATH folders for all regular users.
    # This prevents changing system-wide commands from normal users.
    path_folders = {
        '/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/bin'
    }
    extra_user_paths = settings['environment']['extra_user_paths']
    path_folders.update(extra_user_paths)
    audits.append(ReadOnly(path_folders))

    # Only allow the root user to have access to the shadow file.
    audits.append(FilePermissionAudit('/etc/shadow', 'root', 'root', 0o0600))

    if 'change_user' not in settings['security']['users_allow']:
        # su should only be accessible to user and group root, unless it is
        # expressly defined to allow users to change to root via the
        # security_users_allow config option.
        audits.append(FilePermissionAudit('/bin/su', 'root', 'root', 0o750))

    return audits
示例#2
0
def get_audits():
    """Get Apache hardening config audits.

    :returns:  dictionary of audits
    """
    if subprocess.call(['which', 'apache2'], stdout=subprocess.PIPE) != 0:
        log(
            "Apache server does not appear to be installed on this node - "
            "skipping apache hardening",
            level=INFO)
        return []

    context = ApacheConfContext()
    settings = utils.get_settings('apache')
    audits = [
        FilePermissionAudit(paths=os.path.join(
            settings['common']['apache_dir'], 'apache2.conf'),
                            user='******',
                            group='root',
                            mode=0o0640),
        TemplatedFile(os.path.join(settings['common']['apache_dir'],
                                   'mods-available/alias.conf'),
                      context,
                      TEMPLATES_DIR,
                      mode=0o0640,
                      user='******',
                      service_actions=[{
                          'service': 'apache2',
                          'actions': ['restart']
                      }]),
        TemplatedFile(os.path.join(settings['common']['apache_dir'],
                                   'conf-enabled/99-hardening.conf'),
                      context,
                      TEMPLATES_DIR,
                      mode=0o0640,
                      user='******',
                      service_actions=[{
                          'service': 'apache2',
                          'actions': ['restart']
                      }]),
        DirectoryPermissionAudit(settings['common']['apache_dir'],
                                 user='******',
                                 group='root',
                                 mode=0o0750),
        DisabledModuleAudit(settings['hardening']['modules_to_disable']),
        NoReadWriteForOther(settings['common']['apache_dir']),
        DeletedFile(['/var/www/html/index.html'])
    ]

    return audits
示例#3
0
def get_audits():
    """Get MySQL hardening config audits.

    :returns:  dictionary of audits
    """
    if subprocess.call(['which', 'mysql'], stdout=subprocess.PIPE) != 0:
        log(
            "MySQL does not appear to be installed on this node - "
            "skipping mysql hardening",
            level=WARNING)
        return []

    settings = utils.get_settings('mysql')
    hardening_settings = settings['hardening']
    my_cnf = hardening_settings['mysql-conf']

    audits = [
        FilePermissionAudit(paths=[my_cnf],
                            user='******',
                            group='root',
                            mode=0o0600),
        TemplatedFile(hardening_settings['hardening-conf'],
                      MySQLConfContext(),
                      TEMPLATES_DIR,
                      mode=0o0750,
                      user='******',
                      group='root',
                      service_actions=[{
                          'service': 'mysql',
                          'actions': ['restart']
                      }]),

        # MySQL and Percona charms do not allow configuration of the
        # data directory, so use the default.
        DirectoryPermissionAudit('/var/lib/mysql',
                                 user='******',
                                 group='mysql',
                                 recursive=False,
                                 mode=0o755),
        DirectoryPermissionAudit('/etc/mysql',
                                 user='******',
                                 group='root',
                                 recursive=False,
                                 mode=0o700),
    ]

    return audits
示例#4
0
def get_audits():
    """Get OS hardening sysctl audits.

    :returns:  dictionary of audits
    """
    audits = []
    settings = utils.get_settings('os')

    # Apply the sysctl settings which are configured to be applied.
    audits.append(SysctlConf())
    # Make sure that only root has access to the sysctl.conf file, and
    # that it is read-only.
    audits.append(
        FilePermissionAudit('/etc/sysctl.conf',
                            user='******',
                            group='root',
                            mode=0o0440))
    # If module loading is not enabled, then ensure that the modules
    # file has the appropriate permissions and rebuild the initramfs
    if not settings['security']['kernel_enable_module_loading']:
        audits.append(ModulesTemplate())

    return audits