Skip to content

Commit 896be2f

Browse files
Byh0kimillerthegorilla
authored andcommitted
Ensure that ssh is installed (dev-sec#774)
Signed-off-by: Sevan Murriguian-Watrin <[email protected]> Signed-off-by: James Miller <[email protected]>
1 parent 44d9aa2 commit 896be2f

File tree

16 files changed

+53
-15
lines changed

16 files changed

+53
-15
lines changed

roles/ssh_hardening/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
23
# true if IPv6 is needed
34
network_ipv6_enable: true # sshd + ssh
45

roles/ssh_hardening/tasks/disable-systemd-socket.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@
1010
state: stopped
1111
enabled: false
1212
masked: true
13-
14-
- name: Enable normal sshd start
15-
ansible.builtin.systemd:
16-
name: ssh.service
17-
state: started
18-
enabled: true

roles/ssh_hardening/tasks/hardening.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
with_dict: "{{ os_vars }}"
2323
tags: always
2424

25+
- name: Install openssh package and configure the service
26+
ansible.builtin.include_tasks: install.yml
27+
2528
- name: Get openssh-version
2629
ansible.builtin.command: ssh -V
2730
register: sshd_version_raw
@@ -32,15 +35,6 @@
3235
ansible.builtin.set_fact:
3336
sshd_version: "{{ sshd_version_raw.stderr | regex_replace('.*_([0-9]*.[0-9]).*', '\\1') }}"
3437

35-
# see https://github.com/dev-sec/ansible-collection-hardening/issues/763
36-
- name: Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated
37-
ansible.builtin.include_tasks: disable-systemd-socket.yml
38-
when:
39-
- ssh_server_hardening | bool
40-
- ssh_server_enabled | bool
41-
- (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('22.04', '>=')) or
42-
(ansible_facts.os_family == 'Debian' and ansible_facts.distribution_major_version is version('12', '>='))
43-
4438
- name: Set default for ssh_host_key_files if not supplied
4539
ansible.builtin.include_tasks: crypto_hostkeys.yml
4640
when:

roles/ssh_hardening/tasks/install.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
3+
- name: Install openssh package(s)
4+
ansible.builtin.package:
5+
name: "{{ pkg }}"
6+
state: present
7+
loop: "{{ ssh_pkgs }}"
8+
loop_control:
9+
loop_var: pkg
10+
11+
# see https://github.com/dev-sec/ansible-collection-hardening/issues/763
12+
- name: Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated
13+
ansible.builtin.include_tasks: disable-systemd-socket.yml
14+
when:
15+
- ssh_server_hardening | bool
16+
- ssh_server_enabled | bool
17+
- (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('22.04', '>=')) or
18+
(ansible_facts.os_family == 'Debian' and ansible_facts.distribution_major_version is version('12', '>='))
19+
20+
- name: Enable or disable sshd service
21+
ansible.builtin.service:
22+
name: "{{ sshd_service_name }}"
23+
enabled: "{{ ssh_server_service_enabled }}"

roles/ssh_hardening/vars/Amazon_2.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/Archlinux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/Debian.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
ssh_pkgs:
3+
- openssh-server
4+
- openssh-client
25
sshd_path: /usr/sbin/sshd
36
ssh_host_keys_dir: /etc/ssh
47
sshd_service_name: ssh

roles/ssh_hardening/vars/Fedora.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/Fedora_37.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/FreeBSD.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh-portable
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/OpenBSD.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
# It seems that OpenBSD comes with openssh in the base install so we can't
3+
# really install it as a separated package. Feel free to patch this if it's
4+
# not the expected way to handle that on OpenBSD
5+
ssh_pkgs: []
26
sshd_path: /usr/sbin/sshd
37
ssh_host_keys_dir: /etc/ssh
48
sshd_service_name: sshd

roles/ssh_hardening/vars/RedHat.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/RedHat_9.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/SmartOS.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/lib/ssh/sshd
35
ssh_host_keys_dir: /var/ssh
46
sshd_service_name: ssh

roles/ssh_hardening/vars/Suse.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2+
ssh_pkgs:
3+
- openssh
24
sshd_path: /usr/sbin/sshd
35
ssh_host_keys_dir: /etc/ssh
46
sshd_service_name: sshd

roles/ssh_hardening/vars/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
23
ssh_macs_53_default:
34
- hmac-ripemd160
45
- hmac-sha1

0 commit comments

Comments
 (0)