Giter VIP home page Giter VIP logo

ubuntu1604-cis's Introduction

Ubuntu 16.04 CIS STIG

Build Status Ansible Role

Configure Ubuntu 16.04 machine to be CIS compliant. Level 1 and 2 findings will be corrected by default.

This role will make changes to the system that could break things. This is not an auditing tool but rather a remediation tool to be used after an audit has been conducted.

IMPORTANT INSTALL STEP

If you want to install this via the ansible-galaxy command you'll need to run it like this:

ansible-galaxy install -p roles -r requirements.yml

With this in the file requirements.yml:

- src: https://github.com/florianutz/Ubuntu1604-CIS.git

Based on CIS Ubuntu Benchmark v1.1.0 - 12-28-2017 .

This repo originated from work done by MindPointGroup

Requirements

You should carefully read through the tasks to make sure these changes will not break your systems before running this playbook.

Role Variables

There are many role variables defined in defaults/main.yml. This list shows the most important.

ubuntu1604cis_notauto: Run CIS checks that we typically do NOT want to automate due to the high probability of breaking the system (Default: false)

ubuntu1604cis_section1: CIS - General Settings (Section 1) (Default: true)

ubuntu1604cis_section2: CIS - Services settings (Section 2) (Default: true)

ubuntu1604cis_section3: CIS - Network settings (Section 3) (Default: true)

ubuntu1604cis_section4: CIS - Logging and Auditing settings (Section 4) (Default: true)

ubuntu1604cis_section5: CIS - Access, Authentication and Authorization settings (Section 5) (Default: true)

ubuntu1604cis_section6: CIS - System Maintenance settings (Section 6) (Default: true)

Disable all selinux functions

ubuntu1604cis_selinux_disable: false

Service variables:
These control whether a server should or should not be allowed to continue to run these services
ubuntu1604cis_avahi_server: false  
ubuntu1604cis_cups_server: false  
ubuntu1604cis_dhcp_server: false  
ubuntu1604cis_ldap_server: false  
ubuntu1604cis_telnet_server: false  
ubuntu1604cis_nfs_server: false  
ubuntu1604cis_rpc_server: false  
ubuntu1604cis_ntalk_server: false  
ubuntu1604cis_rsyncd_server: false  
ubuntu1604cis_tftp_server: false  
ubuntu1604cis_rsh_server: false  
ubuntu1604cis_nis_server: false  
ubuntu1604cis_snmp_server: false  
ubuntu1604cis_squid_server: false  
ubuntu1604cis_smb_server: false  
ubuntu1604cis_dovecot_server: false  
ubuntu1604cis_httpd_server: false  
ubuntu1604cis_vsftpd_server: false  
ubuntu1604cis_named_server: false  
ubuntu1604cis_bind: false  
ubuntu1604cis_vsftpd: false  
ubuntu1604cis_httpd: false  
ubuntu1604cis_dovecot: false  
ubuntu1604cis_samba: false  
ubuntu1604cis_squid: false  
ubuntu1604cis_net_snmp: false  
Designate server as a Mail server

ubuntu1604cis_is_mail_server: false

System network parameters (host only OR host and router)

ubuntu1604cis_is_router: false

IPv6 required

ubuntu1604cis_ipv6_required: true

AIDE

ubuntu1604cis_config_aide: true

AIDE cron settings
ubuntu1604cis_aide_cron:
  cron_user: root
  cron_file: /etc/crontab
  aide_job: '/usr/sbin/aide --check'
  aide_minute: 0
  aide_hour: 5
  aide_day: '*'
  aide_month: '*'
  aide_weekday: '*'  
SELinux policy

ubuntu1604cis_selinux_pol: targeted

Set to 'true' if X Windows is needed in your environment

ubuntu1604cis_xwindows_required: no

Client application requirements
ubuntu1604cis_openldap_clients_required: false
ubuntu1604cis_telnet_required: false
ubuntu1604cis_talk_required: false  
ubuntu1604cis_rsh_required: false
ubuntu1604cis_ypbind_required: false
Time Synchronization
ubuntu1604cis_time_synchronization: chrony
ubuntu1604cis_time_Synchronization: ntp

ubuntu1604cis_time_synchronization_servers:
    - 0.pool.ntp.org
    - 1.pool.ntp.org
    - 2.pool.ntp.org
    - 3.pool.ntp.org  
3.4.2 | PATCH | Ensure /etc/hosts.allow is configured
ubuntu1604cis_host_allow:
  - "10.0.0.0/255.0.0.0"  
  - "172.16.0.0/255.240.0.0"  
  - "192.168.0.0/255.255.0.0"    
ubuntu1604cis_firewall: firewalld
ubuntu1604cis_firewall: iptables

Dependencies

Ansible > 2.2

Example Playbook

- name: Harden Server
  hosts: servers
  become: yes

  roles:
    - Ubuntu1604-CIS

Tags

Many tags are available for precise control of what is and is not changed.

Some examples of using tags:

    # Audit and patch the site
    ansible-playbook site.yml --tags="patch"

License

MIT

ubuntu1604-cis's People

Contributors

caglarsayin avatar dependabot[bot] avatar florianutz avatar isaacbentley avatar j00k avatar jalev avatar smiller171 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ubuntu1604-cis's Issues

Requirement.yml is missing

HI Florian ,

  1. ansible-galaxy install -p roles -r requirements.yml in this command requirement.yml is missing .

  2. ERROR! 'register' is not a valid attribute for a Play

The error appears to have been in '/etc/ansible/Sango/Ubuntu1604-CIS/tasks/prelim.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.


The offending line appears to be:


  • name: PRELIM | List users accounts
    ^ here

I am geeting this issue , can you please help me here .

NTP configuration fails (chronyd)

This list syntax produce wrong output to the chrony.conf file (possible other files, that are using FOR loop). To be more precise it loops through the addresses as each letter is a separate string and this results a new row for each of them.
E.g.
server 0 minpoll 8
server . minpoll 8
server p minpoll 8
server o minpoll 8
...
etc.
This seems to occur after this commit.

Undefined variable grub_cfg & grub2-mkconfig doesn't exist

I get this error:

RUNNING HANDLER [Ubuntu1604-CIS : generate new grub config] **************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'grub_cfg' is undefined\n\nThe error appears to have been in '/root/smtt/ansible/Ubuntu1604-CIS/handlers/main.yml': line 29, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: generate new grub config\n ^ here\n"}

Also, the command grub2-mkconfig should be renamed to grub-mkconfig:

$ grub2-mkconfig
No command 'grub2-mkconfig' found, did you mean:
Command 'grub-mkconfig' from package 'grub-common' (main)
grub2-mkconfig: command not found

ubuntu1604cis_aide_cron

default value for ubuntu1604cis_aide_cron[aide_job] contains a wrong value
there must be /usr/bin/aide --check instead of /usr/sbin/aide --check

Idempotence test failed

ERROR: Idempotence test failed because of the following tasks:

  • [instance] => Ubuntu1604-CIS : SCORED | 1.1.1.4 | PATCH | Ensure mounting of hfs filesystems is disabled
  • [instance] => Ubuntu1604-CIS : SCORED | 1.1.1.5 | PATCH | Ensure mounting of hfsplus filesystems is disabled
  • [instance] => Ubuntu1604-CIS : NOTSCORED | 4.3 | PATCH | Ensure logrotate.conf exists

Vaildate SSH config file after changes

When running the section5 SSH tasks, the sshd configuration file is not validated. The ssh daemon may not be restarted, because not all tasks contain the notify statement and the error remains silently in the configuration file.

This can cause, that sshd configuration file is misconfigured and ssh daemon will not start after system restart.

This is major issue, since the administrator has to log into the machine via single user mode, serial console or another type of alternative access to fix the misconfigured file. This happened to me today on GCP platform, where the end of the SSH file is by default configured properly, but if another line is added to it, it breaks the syntax.

Example of valid ending of SSH config file:

# Create chrooted directory
Match Group scponly
    ChrootDirectory %h
    passwordAuthentication yes
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no

By adding for example line PermitUserEnvironment no, the Match block is not closed with Match all statement and the configuration file is invalid.

# Create chrooted directory
Match Group scponly
    ChrootDirectory %h
    passwordAuthentication yes
    ForceCommand internal-sftp
    AllowTcpForwarding no
PermitUserEnvironment no

Error when running sshd -t:

/etc/ssh/sshd_config line 69: Directive 'PermitUserEnvironment' is not allowed within a Match block.

As remediation I propose:

  • There should be SSH validation run sshd -t after tasks or in handler
  • If the validation is run on handler, all tasks, that alter sshd config file should notify for daemon restart.

Use version tags in Galaxy

Currently you have version tags in GitHub, but those versions are not reflected in Ansible Galaxy. It would be very helpful for me if you would set up Galaxy to use those version tags.

Changing password fails

the password fails the dictionary check - error loading dictionary

ensure that cracklib-runtime is installed

tasks/main.yml has type section issues

root@server-ubuntu-1604:~# ansible-playbook --version
ansible-playbook 2.0.0.2
root@log-server-ubuntu-1604:~# ansible-playbook --check /etc/ansible/roles/florianutz.ubuntu1604-cis/tasks/main.yml
 [WARNING]: provided hosts list is empty, only localhost is available

ERROR! 'fail' is not a valid attribute for a Play

The error appears to have been in '/etc/ansible/roles/florianutz.ubuntu1604-cis/tasks/main.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# tasks file for Ubuntu1604-CIS
- name: Check OS version and family
  ^ here

root@log-server-ubuntu-1604:~# ansible-playbook site.yml
 [WARNING]: provided hosts list is empty, only localhost is available

ERROR! The handlers/main.yml file for role 'florianutz.ubuntu1604-cis' must contain a list of tasks

The error appears to have been in '/etc/ansible/roles/florianutz.ubuntu1604-cis/tasks/main.yml': line 3, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# tasks file for Ubuntu1604-CIS
- name: Check OS version and family
^ here

I was able to successfully run this on a machine the other day and on another system with the same configuration it's not failing. I doubt this is an issue with the file, as I have been able to get this to run, but I haven't the foggiest idea why it would suddenly be failing like this. Any ideas?

6.2.6 Leaves empty secure path, breaks playbook

When running against a Ubuntu 16.04.4 machine that was upgraded from a clean 16.04.3 installation, 6.2.6 doesn't update secure path with anything. The resulting /etc/sudoers file results in this on line 11:

Defaults        secure_path=""

At this point, Ansible is unable to continue and the connection is broken.

Link to CIS Guide doesn't work.

The link to the CIS guide doesn't work anymore.

On their current version of this it, the ubuntu 16 guide is hidden behind an email registration here: https://www.cisecurity.org/benchmark/ubuntu_linux/

The page is branded for Ubuntu 18, and has a back link for Ubuntu 14, but if you register, you get an email with a link to a download archive where Ubuntu the Ubuntu 16 PDF is available.

Why can't these fail?

I can't find any tasks checking the registered vars, and yet these tasks are set to never fail. As far as I can tell these are scored rules that are being allowed to pass unchecked.

- name: "SCORED | 1.1.5 | PATCH | Ensure separate partition exists for /var"
shell: mount | grep "on /var "
register: var_mounted
changed_when: false
failed_when: false
when:
- ubuntu1604cis_rule_1_1_5
tags:
- level2
- scored
- patch
- rule_1.1.5
- skip_ansible_lint
- name: "SCORED | 1.1.6 | PATCH | Ensure separate partition exists for /var/tmp"
shell: mount | grep "on /var/tmp "
register: var_tmp_mounted
changed_when: false
failed_when: false
when:
- ubuntu1604cis_rule_1_1_6
tags:
- level2
- scored
- patch
- rule_1.1.6
- skip_ansible_lint

- name: "SCORED | 1.1.10 | PATCH | Ensure separate partition exists for /var/log"
shell: mount | grep "on /var/log "
register: var_log_mounted
changed_when: false
failed_when: false
when:
- ubuntu1604cis_rule_1_1_10
tags:
- level2
- scored
- patch
- rule_1.1.10
- skip_ansible_lint
- name: "SCORED | 1.1.11 | PATCH | Ensure separate partition exists for /var/log/audit"
shell: mount | grep "on /var/log/audit "
register: var_log_audit_mounted
changed_when: false
failed_when: false
when:
- ubuntu1604cis_rule_1_1_11
tags:
- level2
- scored
- patch
- rule_1.1.11
- skip_ansible_lint
- name: "SCORED | 1.1.12 | PATCH | Ensure separate partition exists for /home"
shell: mount | grep "on /home "
register: home_mounted
changed_when: false
failed_when: false
when:
- ubuntu1604cis_rule_1_1_12
tags:
- level2
- scored
- patch
- rule_1.1.12
- skip_ansible_lint

Section 1.1.1 does not match CIS Guide

In the playbook task 1.1.1.6 is handling disabling squashfs, in the guide it handles udf, and squashfs is never disabled.

Similarly 1.1.1.8 removes FAT, which is again, not addressed in the CIS guide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.