Skip to content

Commit

Permalink
Ensure that ssh is installed
Browse files Browse the repository at this point in the history
Signed-off-by: Sevan Murriguian-Watrin <git@byh0ki.fr>
  • Loading branch information
Byh0ki committed Jun 30, 2024
1 parent c068979 commit 02de843
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 14 deletions.
6 changes: 0 additions & 6 deletions roles/ssh_hardening/tasks/disable-systemd-socket.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@
state: stopped
enabled: false
masked: true

- name: Enable normal sshd start
ansible.builtin.systemd:
name: ssh.service
state: started
enabled: true
10 changes: 2 additions & 8 deletions roles/ssh_hardening/tasks/hardening.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@
ansible.builtin.set_fact:
sshd_version: "{{ sshd_version_raw.stderr | regex_replace('.*_([0-9]*.[0-9]).*', '\\1') }}"

# see https://github.com/dev-sec/ansible-collection-hardening/issues/763
- name: Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated
ansible.builtin.include_tasks: disable-systemd-socket.yml
when:
- ssh_server_hardening | bool
- ssh_server_enabled | bool
- (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('22.04', '>=')) or
(ansible_facts.os_family == 'Debian' and ansible_facts.distribution_major_version is version('12', '>='))
- name: Install openssh package and configure the service
ansible.builtin.include_tasks: install.yml

- name: Set default for ssh_host_key_files if not supplied
ansible.builtin.include_tasks: crypto_hostkeys.yml
Expand Down
20 changes: 20 additions & 0 deletions roles/ssh_hardening/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

- name: Install openssh package
ansible.builtin.package:
name: "{{ ssh_pkg_name }}"
state: present

# see https://github.com/dev-sec/ansible-collection-hardening/issues/763
- name: Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated
ansible.builtin.include_tasks: disable-systemd-socket.yml
when:
- ssh_server_hardening | bool
- ssh_server_enabled | bool
- (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('22.04', '>=')) or
(ansible_facts.os_family == 'Debian' and ansible_facts.distribution_major_version is version('12', '>='))

- name: Enable or disable sshd service
ansible.builtin.service:
name: "{{ sshd_service_name }}"
enabled: "{{ ssh_server_service_enabled }}"
1 change: 1 addition & 0 deletions roles/ssh_hardening/vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
ssh_pkg_name: "openssh-server openssh-client"
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: /etc/ssh
sshd_service_name: ssh
Expand Down
1 change: 1 addition & 0 deletions roles/ssh_hardening/vars/Fedora.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
ssh_pkg_name: ssh
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: /etc/ssh
sshd_service_name: sshd
Expand Down
1 change: 1 addition & 0 deletions roles/ssh_hardening/vars/Fedora_37.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
ssh_pkg_name: ssh
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: /etc/ssh
sshd_service_name: sshd
Expand Down
1 change: 1 addition & 0 deletions roles/ssh_hardening/vars/FreeBSD.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
ssh_pkg_name: openssh-portable
sshd_path: /usr/sbin/sshd
ssh_host_keys_dir: /etc/ssh
sshd_service_name: sshd
Expand Down
2 changes: 2 additions & 0 deletions roles/ssh_hardening/vars/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
ssh_pkg_name: "openssh-server openssh-client"
3 changes: 3 additions & 0 deletions roles/ssh_hardening/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---

ssh_pkg_name: openssh

ssh_macs_53_default:
- hmac-ripemd160
- hmac-sha1
Expand Down

0 comments on commit 02de843

Please sign in to comment.