hardening: updates/new vars
This commit is contained in:
parent
2db773f15a
commit
4ff53468e6
4 changed files with 67 additions and 28 deletions
|
@ -1,3 +1,4 @@
|
||||||
---
|
---
|
||||||
- name: restart sshd
|
- name: restart sshd
|
||||||
systemd: name=sshd state=restarted
|
systemd: name=sshd state=restarted
|
||||||
|
become: true
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: Install required dependency libsemanage-python
|
- name: Install required dependency libsemanage-python
|
||||||
|
become: true
|
||||||
yum:
|
yum:
|
||||||
name: libsemanage-python
|
name: libsemanage-python
|
||||||
state: latest
|
state: present
|
||||||
when: (ansible_distribution_major_version is version('7', '='))
|
when: (ansible_distribution_major_version is version('7', '='))
|
||||||
|
|
||||||
- name: Install required dependency python3-policycoreutils
|
- name: Install required dependency python3-policycoreutils
|
||||||
|
become: true
|
||||||
dnf:
|
dnf:
|
||||||
name: python3-policycoreutils
|
name: python3-policycoreutils
|
||||||
state: latest
|
state: present
|
||||||
when: (ansible_distribution_major_version is version('8', '>='))
|
when: (ansible_distribution_major_version is version('8', '>='))
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: Install required dependency python3-libsemanage
|
- name: Install required dependency python3-libsemanage
|
||||||
|
become: true
|
||||||
dnf:
|
dnf:
|
||||||
name: python3-libsemanage
|
name: python3-libsemanage
|
||||||
state: latest
|
state: present
|
||||||
when: (ansible_distribution_major_version is version('31', '>='))
|
when: (ansible_distribution_major_version is version('31', '>='))
|
||||||
|
|
||||||
- name: Install required dependency libsemanage-python
|
- name: Install required dependency libsemanage-python
|
||||||
|
become: true
|
||||||
dnf:
|
dnf:
|
||||||
name: libsemanage-python
|
name: libsemanage-python
|
||||||
state: latest
|
state: present
|
||||||
when: (ansible_distribution_major_version is version('30', '<='))
|
when: (ansible_distribution_major_version is version('30', '<='))
|
||||||
|
|
|
@ -2,48 +2,82 @@
|
||||||
|
|
||||||
- name: include SELinux package tasks for EL (CentOS/RHEL)
|
- name: include SELinux package tasks for EL (CentOS/RHEL)
|
||||||
include_tasks: centos-selinux.yml
|
include_tasks: centos-selinux.yml
|
||||||
|
tags: selinux
|
||||||
when: (ansible_distribution in ["CentOS" , "Red Hat Enterprise Linux", "RedHat"])
|
when: (ansible_distribution in ["CentOS" , "Red Hat Enterprise Linux", "RedHat"])
|
||||||
|
|
||||||
- name: include SELinux package tasks for Fedora (non-atomic)
|
- name: include SELinux package tasks for Fedora (non-atomic)
|
||||||
include_tasks: fedora-selinux.yml
|
include_tasks: fedora-selinux.yml
|
||||||
|
tags: selinux
|
||||||
when: (ansible_distribution in ["Fedora"] and not is_atomic)
|
when: (ansible_distribution in ["Fedora"] and not is_atomic)
|
||||||
|
|
||||||
# likely to break on non-RHEL/derivatives, could use improvement.
|
# likely to break on non-RHEL/derivatives, could use improvement.
|
||||||
|
- name: ensure firewalld is installed
|
||||||
|
become: true
|
||||||
|
package:
|
||||||
|
name: firewalld
|
||||||
|
state: present
|
||||||
|
|
||||||
- name: enable firewalld
|
- name: enable firewalld
|
||||||
|
become: true
|
||||||
service:
|
service:
|
||||||
name: firewalld
|
name: firewalld
|
||||||
state: started
|
state: started
|
||||||
enabled: yes
|
enabled: true
|
||||||
|
|
||||||
- name: SSH - disable password auth
|
- name: harden sshd
|
||||||
lineinfile:
|
tags: harden_sshd
|
||||||
dest: /etc/ssh/sshd_config
|
become: true
|
||||||
regexp: "^PasswordAuthentication"
|
block:
|
||||||
line: "PasswordAuthentication no"
|
- name: "SSH: disable password auth"
|
||||||
state: present
|
lineinfile:
|
||||||
notify: restart sshd
|
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
|
||||||
|
|
||||||
- name: SSH - config port 1181
|
- name: "permit custom SSH port ({{ hardened_ssh_port }})"
|
||||||
lineinfile:
|
become: true
|
||||||
path: /etc/ssh/sshd_config
|
|
||||||
regexp: '^Port '
|
|
||||||
line: 'Port 1181'
|
|
||||||
insertbefore: "(^|#)AddressFamily.*"
|
|
||||||
validate: '/usr/sbin/sshd -t -f %s'
|
|
||||||
notify: restart sshd
|
|
||||||
|
|
||||||
- name: allow custom SSH port in selinux
|
|
||||||
seport:
|
seport:
|
||||||
ports: 1181
|
ports: "{{ hardened_ssh_port }}"
|
||||||
proto: tcp
|
proto: tcp
|
||||||
setype: ssh_port_t
|
setype: ssh_port_t
|
||||||
state: present
|
state: present
|
||||||
when: (ansible_selinux is defined and ansible_selinux != False and ansible_selinux.status == 'enabled')
|
when:
|
||||||
|
- hardened_ssh_port is defined
|
||||||
|
- ansible_selinux is defined
|
||||||
|
- ansible_selinux.status == 'enabled'
|
||||||
|
tags: selinux
|
||||||
|
|
||||||
# also likely to break on non-RHEL/derivatives, could use improvement too.
|
# also likely to break on non-RHEL/derivatives, could use improvement too.
|
||||||
- name: allow custom SSH port in firewalld
|
- name: "firewalld: grant access to custom SSH port"
|
||||||
|
become: true
|
||||||
firewalld:
|
firewalld:
|
||||||
port: 1181/tcp
|
port: "{{ hardened_ssh_port }}/tcp"
|
||||||
permanent: yes
|
permanent: true
|
||||||
immediate: yes
|
immediate: true
|
||||||
state: enabled
|
state: enabled
|
||||||
|
when: (hardened_ssh_port is defined)
|
||||||
|
|
Loading…
Reference in a new issue