Skip to content
This repository was archived by the owner on Dec 26, 2020. It is now read-only.

Commit 86b7301

Browse files
authored
Merge pull request #95 from jbenden/freebsd-support
Add support for FreeBSD OpenSSH server and client
2 parents a3ccd8f + 4fea608 commit 86b7301

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

tasks/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
when: sshd_version.stdout >= '6.3'
2929

3030
- name: create sshd_config and set permissions to root/600
31-
template: src='opensshd.conf.j2' dest='/etc/ssh/sshd_config' mode=0600 owner=root group=root validate="/usr/sbin/sshd -T -f %s"
31+
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"
3232
notify: restart sshd
3333
when: ssh_server_hardening
3434

3535
- name: create ssh_config and set permissions to root/644
36-
template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner=root group=root
36+
template: src='openssh.conf.j2' dest='/etc/ssh/ssh_config' mode=0644 owner="{{ ssh_owner }}" group="{{ ssh_group }}"
3737
when: ssh_client_hardening
3838

3939
- name: create ssh_config and set permissions to root/644

templates/openssh.conf.j2

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ StrictHostKeyChecking ask
4545
# -- see: (http://net-ssh.github.com/net-ssh/classes/Net/SSH/Transport/CipherFactory.html)
4646
#
4747
{% if ssh_client_cbc_required -%}
48-
{% 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') -%}
48+
{% 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') -%}
4949
Ciphers {{ ssh_ciphers_66_weak | join(',') }}
5050
{% else -%}
5151
Ciphers {{ ssh_ciphers_53_weak | join(',') }}
5252
{% endif %}
5353
{% else -%}
54-
{% 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') -%}
54+
{% 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') -%}
5555
Ciphers {{ ssh_ciphers_66_default | join(',') }}
5656
{% else -%}
5757
Ciphers {{ ssh_ciphers_53_default | join(',') }}
@@ -63,13 +63,13 @@ StrictHostKeyChecking ask
6363
# 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.
6464
#
6565
{% if ssh_client_weak_hmac -%}
66-
{% 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') -%}
66+
{% 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') -%}
6767
MACs {{ ssh_macs_66_weak | join(',') }}
6868
{% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%}
6969
MACs {{ ssh_macs_53_default | join(',') }}
7070
{% endif %}
7171
{% else -%}
72-
{% 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') -%}
72+
{% 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') -%}
7373
MACs {{ ssh_macs_66_default | join(',') }}
7474
{% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%}
7575
MACs {{ ssh_macs_53_default | join(',') }}
@@ -85,7 +85,7 @@ StrictHostKeyChecking ask
8585
# Weak kex is sometimes required if older package versions are used
8686
# 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.
8787
#
88-
{% 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') -%}
88+
{% 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') -%}
8989
{% if ssh_client_weak_kex -%}
9090
KexAlgorithms {{ ssh_kex_66_weak | join(',') }}
9191
{% else -%}

templates/opensshd.conf.j2

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ LogLevel VERBOSE
4949
# -- see: (http://net-ssh.github.com/net-ssh/classes/Net/SSH/Transport/CipherFactory.html)
5050
#
5151
{% if ssh_server_cbc_required -%}
52-
{% 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') -%}
52+
{% 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') -%}
5353
Ciphers {{ ssh_ciphers_66_weak | join(',') }}
5454
{% else %}
5555
Ciphers {{ ssh_ciphers_53_weak | join(',') }}
5656
{% endif %}
5757
{% else -%}
58-
{% 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') -%}
58+
{% 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') -%}
5959
Ciphers {{ ssh_ciphers_66_default | join(',') }}
6060
{% else -%}
6161
Ciphers {{ ssh_ciphers_53_default | join(',') }}
@@ -68,13 +68,13 @@ LogLevel VERBOSE
6868
#
6969

7070
{% if ssh_server_weak_hmac -%}
71-
{% 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') -%}
71+
{% 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') -%}
7272
MACs {{ ssh_macs_66_weak | join(',') }}
7373
{% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%}
7474
MACs {{ ssh_macs_53_default | join(',') }}
7575
{% endif %}
7676
{% else -%}
77-
{% 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') -%}
77+
{% 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') -%}
7878
MACs {{ ssh_macs_66_default | join(',') }}
7979
{% elif ansible_os_family in ['Oracle Linux', 'RedHat'] and ansible_distribution_major_version <= '6' -%}
8080
MACs {{ ssh_macs_53_default | join(',') }}
@@ -90,7 +90,7 @@ LogLevel VERBOSE
9090
# Weak kex is sometimes required if older package versions are used
9191
# 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.
9292
# based on: https://bettercrypto.org/static/applied-crypto-hardening.pdf
93-
{% 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') -%}
93+
{% 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') -%}
9494
{% if ssh_server_weak_kex -%}
9595
KexAlgorithms {{ ssh_kex_66_weak | join(',') }}
9696
{% else -%}
@@ -196,7 +196,9 @@ X11UseLocalhost yes
196196

197197
PrintMotd {{ 'yes' if ssh_print_motd else 'no' }}
198198

199+
{% if ansible_os_family != 'FreeBSD' %}
199200
PrintLastLog {{ 'yes' if ssh_print_last_log else 'no' }}
201+
{% endif %}
200202

201203
Banner {{ '/etc/ssh/banner.txt' if ssh_banner else 'none' }}
202204

vars/Debian.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
sshd_service_name: ssh
2+
ssh_owner: root
3+
ssh_group: root

vars/FreeBSD.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sshd_service_name: sshd
2+
ssh_owner: root
3+
ssh_group: wheel

vars/Oracle Linux.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
sshd_service_name: sshd
2+
ssh_owner: root
3+
ssh_group: root

vars/RedHat.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
sshd_service_name: sshd
2+
ssh_owner: root
3+
ssh_group: root

0 commit comments

Comments
 (0)