mirror of
https://github.com/ansible-lockdown/RHEL9-CIS.git
synced 2025-12-24 22:23:06 +00:00
#30 thanks to @smatterchew sshd config file dropin ability
Signed-off-by: Mark Bolwell <mark.bollyuk@gmail.com>
This commit is contained in:
parent
2b906aa3a6
commit
a14e9c5dbe
3 changed files with 40 additions and 21 deletions
|
|
@ -175,6 +175,22 @@
|
|||
- rule_5.1.1
|
||||
- cron
|
||||
|
||||
# Added to ensure ssh drop in file exists if not default /etc/ssh/sshd_config
|
||||
- name: "PRELIM | Section 5.2 | SSH"
|
||||
ansible.builtin.file:
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
state: touch
|
||||
when:
|
||||
- rhel9_cis_sshd_config_file != '/etc/ssh/sshd_config'
|
||||
- "'openssh-server' in ansible_facts.packages"
|
||||
tags:
|
||||
- ssh
|
||||
- level1_server
|
||||
- level1_workstation
|
||||
|
||||
- name: "PRELIM | Install authconfig"
|
||||
ansible.builtin.package:
|
||||
name: authconfig
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
- name: "5.2.1 | Ensure permissions on /etc/ssh/sshd_config are configured"
|
||||
ansible.builtin.file:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "/etc/ssh/sshd_config"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
|
|
@ -77,7 +77,7 @@
|
|||
block:
|
||||
- name: "5.2.4 | PATCH | Ensure SSH access is limited | Add line to sshd_config for allowusers"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^AllowUsers"
|
||||
line: "AllowUsers {{ rhel9cis_sshd['allowusers'] }}"
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
|
||||
- name: "5.2.4 | PATCH | Ensure SSH access is limited | Add line to sshd_config for allowgroups"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^AllowGroups"
|
||||
line: "AllowGroups {{ rhel9cis_sshd['allowgroups'] }}"
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -95,7 +95,7 @@
|
|||
|
||||
- name: "5.2.4 | PATCH | Ensure SSH access is limited | Add line to sshd_config for denyusers"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^DenyUsers"
|
||||
line: "DenyUsers {{ rhel9cis_sshd['denyusers'] }}"
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
|
||||
- name: "5.2.4 | PATCH | Ensure SSH access is limited | Add line to sshd_config for denygroups"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^DenyGroups"
|
||||
line: "DenyGroups {{ rhel9cis_sshd['denygroups'] }}"
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -121,7 +121,7 @@
|
|||
|
||||
- name: "5.2.5 | PATCH | Ensure SSH LogLevel is appropriate"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#LogLevel|^LogLevel"
|
||||
line: 'LogLevel {{ rhel9cis_ssh_loglevel }}'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -136,7 +136,7 @@
|
|||
|
||||
- name: "5.2.6 | PATCH | Ensure SSH PAM is enabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#UsePAM|^UsePAM"
|
||||
line: 'UsePAM yes'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -151,7 +151,7 @@
|
|||
|
||||
- name: "5.2.7 | PATCH | Ensure SSH root login is disabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#PermitRootLogin|^PermitRootLogin"
|
||||
line: 'PermitRootLogin no'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -166,7 +166,7 @@
|
|||
|
||||
- name: "5.2.8 | PATCH | Ensure SSH HostbasedAuthentication is disabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#HostbasedAuthentication|^HostbasedAuthentication"
|
||||
line: 'HostbasedAuthentication no'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -181,7 +181,7 @@
|
|||
|
||||
- name: "5.2.9 | PATCH | Ensure SSH PermitEmptyPasswords is disabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#PermitEmptyPasswords|^PermitEmptyPasswords"
|
||||
line: 'PermitEmptyPasswords no'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -196,7 +196,7 @@
|
|||
|
||||
- name: "5.2.10 | PATCH | Ensure SSH PermitUserEnvironment is disabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#PermitUserEnvironment|^PermitUserEnvironment"
|
||||
line: 'PermitUserEnvironment no'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -211,7 +211,7 @@
|
|||
|
||||
- name: "5.2.11 | PATCH | Ensure SSH IgnoreRhosts is enabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#IgnoreRhosts|^IgnoreRhosts"
|
||||
line: 'IgnoreRhosts yes'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -226,7 +226,7 @@
|
|||
|
||||
- name: "5.2.12 | PATCH | Ensure SSH X11 forwarding is disabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#X11Forwarding|^X11Forwarding"
|
||||
line: 'X11Forwarding no'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -241,7 +241,7 @@
|
|||
|
||||
- name: "5.2.13 | PATCH | Ensure SSH AllowTcpForwarding is disabled"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#AllowTcpForwarding|^AllowTcpForwarding"
|
||||
line: 'AllowTcpForwarding no'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -277,7 +277,7 @@
|
|||
|
||||
- name: "5.2.15 | PATCH | Ensure SSH warning banner is configured"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: '^Banner'
|
||||
line: 'Banner /etc/issue.net'
|
||||
when:
|
||||
|
|
@ -291,7 +291,7 @@
|
|||
|
||||
- name: "5.2.16 | PATCH | Ensure SSH MaxAuthTries is set to 4 or less"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: '^(#)?MaxAuthTries \d'
|
||||
line: 'MaxAuthTries 4'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -306,7 +306,7 @@
|
|||
|
||||
- name: "5.2.17 | PATCH | Ensure SSH MaxStartups is configured"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#MaxStartups|^MaxStartups"
|
||||
line: 'MaxStartups 10:30:60'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -321,7 +321,7 @@
|
|||
|
||||
- name: "5.2.18 | PATCH | Ensure SSH MaxSessions is set to 10 or less"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#MaxSessions|^MaxSessions"
|
||||
line: 'MaxSessions {{ rhel9cis_ssh_maxsessions }}'
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -336,7 +336,7 @@
|
|||
|
||||
- name: "5.2.19 | PATCH | Ensure SSH LoginGraceTime is set to one minute or less"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: "^#LoginGraceTime|^LoginGraceTime"
|
||||
line: "LoginGraceTime {{ rhel9cis_sshd['logingracetime'] }}"
|
||||
validate: sshd -t -f %s
|
||||
|
|
@ -353,14 +353,14 @@
|
|||
block:
|
||||
- name: "5.2.20 | PATCH | Ensure SSH Idle Timeout Interval is configured | Add line in sshd_config for ClientAliveInterval"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: '^ClientAliveInterval'
|
||||
line: "ClientAliveInterval {{ rhel9cis_sshd['clientaliveinterval'] }}"
|
||||
validate: sshd -t -f %s
|
||||
|
||||
- name: "5.2.20 | PATCH | Ensure SSH Idle Timeout Interval is configured | Ensure SSH ClientAliveCountMax set to <= 3"
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
path: "{{ rhel9_cis_sshd_config_file }}"
|
||||
regexp: '^ClientAliveCountMax'
|
||||
line: "ClientAliveCountMax {{ rhel9cis_sshd['clientalivecountmax'] }}"
|
||||
validate: sshd -t -f %s
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue