2019-02-26 03:49:51 +00:00
|
|
|
---
|
|
|
|
|
2021-04-05 05:21:25 +00:00
|
|
|
- name: include SELinux package tasks for EL (CentOS/RHEL)
|
|
|
|
include_tasks: centos-selinux.yml
|
2023-08-31 01:29:05 +00:00
|
|
|
tags: selinux
|
2021-04-05 05:21:25 +00:00
|
|
|
when: (ansible_distribution in ["CentOS" , "Red Hat Enterprise Linux", "RedHat"])
|
2019-02-26 03:49:51 +00:00
|
|
|
|
2021-04-05 05:21:25 +00:00
|
|
|
- name: include SELinux package tasks for Fedora (non-atomic)
|
|
|
|
include_tasks: fedora-selinux.yml
|
2023-08-31 01:29:05 +00:00
|
|
|
tags: selinux
|
2021-04-05 05:21:25 +00:00
|
|
|
when: (ansible_distribution in ["Fedora"] and not is_atomic)
|
|
|
|
|
|
|
|
# likely to break on non-RHEL/derivatives, could use improvement.
|
2023-08-31 01:29:05 +00:00
|
|
|
- name: ensure firewalld is installed
|
|
|
|
become: true
|
|
|
|
package:
|
|
|
|
name: firewalld
|
|
|
|
state: present
|
|
|
|
|
2021-04-05 05:21:25 +00:00
|
|
|
- name: enable firewalld
|
2023-08-31 01:29:05 +00:00
|
|
|
become: true
|
2019-02-26 03:49:51 +00:00
|
|
|
service:
|
2021-04-05 05:21:25 +00:00
|
|
|
name: firewalld
|
|
|
|
state: started
|
2023-08-31 01:29:05 +00:00
|
|
|
enabled: true
|
2019-02-26 03:49:51 +00:00
|
|
|
|
2023-08-31 01:29:05 +00:00
|
|
|
- name: harden sshd
|
|
|
|
tags: harden_sshd
|
|
|
|
become: true
|
|
|
|
block:
|
|
|
|
- name: "SSH: disable password auth"
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
regexp: "^PasswordAuthentication"
|
|
|
|
line: "PasswordAuthentication no"
|
|
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
|
|
notify: restart sshd
|
|
|
|
- name: "SSH: config custom port"
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
regexp: '^Port '
|
|
|
|
line: "Port {{ hardened_ssh_port }}"
|
|
|
|
insertbefore: "(^|#)AddressFamily.*"
|
|
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
|
|
when: (hardened_ssh_port is defined)
|
|
|
|
notify: restart sshd
|
|
|
|
- name: "only allow root logins with keys"
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
regexp: '^PermitRootLogin '
|
|
|
|
line: 'PermitRootLogin prohibit-password'
|
|
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
|
|
notify: restart sshd
|
|
|
|
- name: "disallow keyboard interactive auth to address some PAM edge cases"
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
regexp: '^KbdInteractiveAuthentication '
|
|
|
|
line: 'KbdInteractiveAuthentication no'
|
|
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
|
|
notify: restart sshd
|
2021-04-05 05:21:25 +00:00
|
|
|
|
2023-08-31 01:29:05 +00:00
|
|
|
- name: "permit custom SSH port ({{ hardened_ssh_port }})"
|
|
|
|
become: true
|
2021-04-05 05:21:25 +00:00
|
|
|
seport:
|
2023-08-31 01:29:05 +00:00
|
|
|
ports: "{{ hardened_ssh_port }}"
|
2021-04-05 05:21:25 +00:00
|
|
|
proto: tcp
|
|
|
|
setype: ssh_port_t
|
|
|
|
state: present
|
2023-08-31 01:29:05 +00:00
|
|
|
when:
|
|
|
|
- hardened_ssh_port is defined
|
|
|
|
- ansible_selinux is defined
|
|
|
|
- ansible_selinux.status == 'enabled'
|
|
|
|
tags: selinux
|
2019-02-26 03:49:51 +00:00
|
|
|
|
2021-04-05 05:21:25 +00:00
|
|
|
# also likely to break on non-RHEL/derivatives, could use improvement too.
|
2023-08-31 01:29:05 +00:00
|
|
|
- name: "firewalld: grant access to custom SSH port"
|
|
|
|
become: true
|
2021-04-05 05:21:25 +00:00
|
|
|
firewalld:
|
2023-08-31 01:29:05 +00:00
|
|
|
port: "{{ hardened_ssh_port }}/tcp"
|
|
|
|
permanent: true
|
|
|
|
immediate: true
|
2021-04-05 05:21:25 +00:00
|
|
|
state: enabled
|
2023-08-31 01:29:05 +00:00
|
|
|
when: (hardened_ssh_port is defined)
|