diff --git a/tasks/main.yml b/tasks/main.yml index c8fb864..8c44506 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,12 +28,12 @@ when: sshd_version.stdout >= '6.3' - name: create sshd_config and set permissions to root/600 - template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner=root group=root validate="/usr/sbin/sshd -T -f %s" + template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner="{{ ssh_owner }}" group="{{ ssh_group }}" validate="/usr/sbin/sshd -T -f %s" notify: restart sshd when: ssh_server_hardening - name: create ssh_config and set permissions to root/644 - template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner=root group=root + template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner="{{ ssh_owner }}" group="{{ ssh_group }}" when: ssh_client_hardening - name: create ssh_config and set permissions to root/644 diff --git a/templates/openssh.conf.j2 b/templates/openssh.conf.j2 index e2e97b1..55efbd6 100644 --- a/templates/openssh.conf.j2 +++ b/templates/openssh.conf.j2 @@ -45,13 +45,13 @@ StrictHostKeyChecking ask # -- see: (http://net-ssh.github.com/net-ssh/classes/Net/SSH/Transport/CipherFactory.html) # {% if ssh_client_cbc_required -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} Ciphers {{ ssh_ciphers_66_weak | join(',') }} {% else -%} Ciphers {{ ssh_ciphers_53_weak | join(',') }} {% endif %} {% else -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} Ciphers {{ ssh_ciphers_66_default | join(',') }} {% else -%} Ciphers {{ ssh_ciphers_53_default | join(',') }} @@ -63,13 +63,13 @@ StrictHostKeyChecking ask # eg Ruby's Net::SSH at around 2.2.* doesn't support sha2 for hmac, so this will have to be set true in this case. # {% if ssh_client_weak_hmac -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} MACs {{ ssh_macs_66_weak | join(',') }} {% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%} MACs {{ ssh_macs_53_default | join(',') }} {% endif %} {% else -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} MACs {{ ssh_macs_66_default | join(',') }} {% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%} MACs {{ ssh_macs_53_default | join(',') }} @@ -85,7 +85,7 @@ StrictHostKeyChecking ask # Weak kex is sometimes required if older package versions are used # eg ruby's Net::SSH at around 2.2.* doesn't support sha2 for kex, so this will have to be set true in this case. # -{% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} +{% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} {% if ssh_client_weak_kex -%} KexAlgorithms {{ ssh_kex_66_weak | join(',') }} {% else -%} diff --git a/templates/opensshd.conf.j2 b/templates/opensshd.conf.j2 index 66a346b..11087cc 100644 --- a/templates/opensshd.conf.j2 +++ b/templates/opensshd.conf.j2 @@ -49,13 +49,13 @@ LogLevel VERBOSE # -- see: (http://net-ssh.github.com/net-ssh/classes/Net/SSH/Transport/CipherFactory.html) # {% if ssh_server_cbc_required -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} Ciphers {{ ssh_ciphers_66_weak | join(',') }} {% else %} Ciphers {{ ssh_ciphers_53_weak | join(',') }} {% endif %} {% else -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} Ciphers {{ ssh_ciphers_66_default | join(',') }} {% else -%} Ciphers {{ ssh_ciphers_53_default | join(',') }} @@ -68,13 +68,13 @@ LogLevel VERBOSE # {% if ssh_server_weak_hmac -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} MACs {{ ssh_macs_66_weak | join(',') }} {% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%} MACs {{ ssh_macs_53_default | join(',') }} {% endif %} {% else -%} - {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} + {% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} MACs {{ ssh_macs_66_default | join(',') }} {% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%} MACs {{ ssh_macs_53_default | join(',') }} @@ -90,7 +90,7 @@ LogLevel VERBOSE # Weak kex is sometimes required if older package versions are used # eg ruby's Net::SSH at around 2.2.* doesn't support sha2 for kex, so this will have to be set true in this case. # based on: https://bettercrypto.org/static/applied-crypto-hardening.pdf -{% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') -%} +{% if (ansible_distribution == 'Ubuntu' and ansible_distribution_version >= '14.04') or (ansible_distribution == 'Debian' and ansible_distribution_version >= '8') or (ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version >= '7') or (ansible_distribution == 'FreeBSD' and ansible_distribution_version >= '11') -%} {% if ssh_server_weak_kex -%} KexAlgorithms {{ ssh_kex_66_weak | join(',') }} {% else -%} @@ -196,7 +196,9 @@ X11UseLocalhost yes PrintMotd {{ 'yes' if ssh_print_motd else 'no' }} +{% if ansible_os_family != 'FreeBSD' %} PrintLastLog {{ 'yes' if ssh_print_last_log else 'no' }} +{% endif %} Banner {{ '/etc/ssh/banner.txt' if ssh_banner else 'none' }} diff --git a/vars/Debian.yml b/vars/Debian.yml index c3b4148..cd26ce0 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1 +1,3 @@ sshd_service_name: ssh +ssh_owner: root +ssh_group: root diff --git a/vars/FreeBSD.yml b/vars/FreeBSD.yml new file mode 100644 index 0000000..173b78a --- /dev/null +++ b/vars/FreeBSD.yml @@ -0,0 +1,3 @@ +sshd_service_name: sshd +ssh_owner: root +ssh_group: wheel diff --git a/vars/Oracle Linux.yml b/vars/Oracle Linux.yml index f8a52d3..62dd98f 100644 --- a/vars/Oracle Linux.yml +++ b/vars/Oracle Linux.yml @@ -1 +1,3 @@ sshd_service_name: sshd +ssh_owner: root +ssh_group: root diff --git a/vars/RedHat.yml b/vars/RedHat.yml index f8a52d3..62dd98f 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1 +1,3 @@ sshd_service_name: sshd +ssh_owner: root +ssh_group: root