Skip to content

Commit 5c2faa1

Browse files
Merge pull request #125 from ansible-lockdown/pub_dec25_tweaks
Pub dec25 tweaks
2 parents 41e6e43 + 3396f56 commit 5c2faa1

9 files changed

Lines changed: 170 additions & 100 deletions

File tree

Changelog.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,31 @@
22

33
## Based on CIS v1.0.0
44

5+
## based on benchmark CIS 1.0.0
6+
precommit update Public issues address
7+
8+
4.2.5 ufw port variables and improvements to include ntp and protocol options
9+
10+
Many thanks to @DianaMariaDDM for the issues or PRs for following:
11+
- #109 6.3.1 - Enhancements
12+
- #110 6.2.3.6 - improvement to privilege command collection
13+
- #111 6.3.2 - template for service fixed
14+
- #112 7.1.2 - Enhancements
15+
- #113 variable documentation tidy up
16+
- #114 sshd tidy up of variables
17+
- #119 tidy up typos
18+
- #120 3.3.3.1/5/8 - fix variables used
19+
- #121 6.1.1.4 added missing control
20+
- #122 separate 6.2.4.1/2/3
21+
- #124 removed unused template
22+
523
### 1.0.5 - based on benchmark CIS 1.0.0
6-
#92 1.1.1.7 logic improved and updating inline with audit branches - thanks @jbruno
7-
#93 ufw logic improved thanks to @ToonSpinTUe
8-
#94 Fixed var names dailychecktimer thanks to #94 @huan086
9-
pre-commit updates
24+
25+
- #92 1.1.1.7 logic improved and updating inline with audit branches - thanks @jbruno
26+
- #93 ufw logic improved thanks to @ToonSpinTUe
27+
- #94 Fixed var names dailychecktimer thanks to #94 @huan086
28+
- pre-commit updates
29+
1030
typo fixes
1131

1232
1.0.4 - based on Benchmark CIS 1.0.0
@@ -39,7 +59,6 @@ thanks to @huan086
3959
- 76
4060
- 77
4161

42-
4362
### 1.0.3 - based on Benchmark CIS 1.0.0
4463
pre-commit updates
4564
password data variable update - 7.2.10

defaults/main.yml

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,20 @@ ubtu24cis_firewall_package: "ufw"
804804
ubtu24cis_ufw_use_sysctl: true
805805

806806
## Control 4.1.5 - Ensure ufw outbound connections are configured
807-
# The value of this variable represents the ports for the firewall to allow oubound traffic from.
807+
# The value of this variable represents the ports for the firewall to allow outbound traffic from.
808808
# If you want to allow outbound traffic on all ports, set the variable to `all`, e.g.,
809809
# `ubtu24cis_ufw_allow_out_ports: "all"`.
810810
ubtu24cis_ufw_allow_out_ports:
811-
- 53
812-
- 80
813-
- 443
811+
- port: 53
812+
proto: tcp
813+
- port: 53
814+
proto: udp
815+
- port: 80
816+
proto: tcp
817+
- port: 123
818+
proto: udp
819+
- port: 443
820+
proto: tcp
814821

815822
## Controls 4.2.x - nftables
816823
# Nftables is not supported in this role. Some tasks have parts of them commented out, this is one example
@@ -824,27 +831,27 @@ ubtu24cis_ufw_allow_out_ports:
824831
## Section 5 Control Variables
825832
##
826833
## Controls 5.1.x -- various sshd settings
827-
ubtu24cis_sshd_default_log_level: "INFO"
828-
ubtu24cis_sshd_default_max_auth_tries: 4
829-
ubtu24cis_sshd_default_max_sessions: 8
830-
ubtu24cis_sshd_default_login_grace_time: 60
831-
ubtu24cis_sshd_default_client_alive_interval: 300
832-
ubtu24cis_sshd_default_client_alive_count_max: 3
834+
ubtu24cis_sshd_log_level: "INFO"
835+
ubtu24cis_sshd_max_auth_tries: 4
836+
ubtu24cis_sshd_max_sessions: 8
837+
ubtu24cis_sshd_login_grace_time: 60
838+
ubtu24cis_sshd_client_alive_interval: 300
839+
ubtu24cis_sshd_client_alive_count_max: 3
833840
# Removed chacha20-poly1305 due to cve2023-48795
834841
# all Ciphers, KEX and Macs set to FIPS 140
835842
# This will nee dto be adjusted according to your site requirements
836-
ubtu24cis_sshd_default_ciphers:
843+
ubtu24cis_sshd_ciphers:
837844
- aes256-gcm@openssh.com
838845
- aes128-gcm@openssh.com
839846
- aes256-ctr
840847
- aes192-ctr
841848
- aes128-ctr
842-
ubtu24cis_sshd_default_macs:
849+
ubtu24cis_sshd_macs:
843850
- hmac-sha1
844851
- hmac-sha2-256
845852
# - hmac-sha2-384 # hashed out seen as bad ssh2 MAC
846853
- hmac-sha2-512
847-
ubtu24cis_sshd_default_kex_algorithms:
854+
ubtu24cis_sshd_kex_algorithms:
848855
- ecdh-sha2-nistp256
849856
- ecdh-sha2-nistp384
850857
- ecdh-sha2-nistp521
@@ -853,41 +860,6 @@ ubtu24cis_sshd_default_kex_algorithms:
853860
- diffie-hellman-group18-sha512
854861
- diffie-hellman-group14-sha256
855862

856-
# SSH Settings
857-
# This variable is used to control the verbosity of the logging produced by the SSH server.
858-
# The options for setting it are as follows:
859-
# - `QUIET`: Minimal logging;
860-
# - `FATAL`: logs only fatal errors;
861-
# - `ERROR`: logs error messages;
862-
# - `INFO`: logs informational messages in addition to errors;
863-
# - `VERBOSE`: logs a higher level of detail, including login attempts and key exchanges;
864-
# - `DEBUG`: generates very detailed debugging information including sensitive information.
865-
ubtu24cis_sshd_log_level: "{{ ubtu24cis_sshd_default_log_level }}"
866-
# This variable specifies the maximum number of authentication attempts that are
867-
# allowed for a single SSH session.
868-
ubtu24cis_sshd_max_auth_tries: "{{ ubtu24cis_sshd_default_max_auth_tries }}"
869-
# This variable specifies the encryption algorithms that can be used for securing
870-
# data transmission.
871-
ubtu24cis_sshd_ciphers: "{{ ubtu24cis_sshd_default_ciphers }}"
872-
# This variable specifies a list of message authentication code algorithms (MACs) that are allowed for verifying
873-
# the integrity of data exchanged.
874-
ubtu24cis_sshd_macs: "{{ ubtu24cis_sshd_default_macs }}"
875-
# This variable is used to state the key exchange algorithms used to establish secure encryption
876-
# keys during the initial connection setup.
877-
ubtu24cis_sshd_kex_algorithms: "{{ ubtu24cis_sshd_default_kex_algorithms }}"
878-
# This variable sets the time interval in seconds between sending "keep-alive"
879-
# messages from the server to the client. These types of messages are intended to
880-
# keep the connection alive and prevent it being terminated due to inactivity.
881-
ubtu24cis_sshd_client_alive_interval: "{{ ubtu24cis_sshd_default_client_alive_interval }}"
882-
# This variable sets the maximum number of unresponsive "keep-alive" messages
883-
# that can be sent from the server to the client before the connection is considered
884-
# inactive and thus, closed.
885-
ubtu24cis_sshd_client_alive_count_max: "{{ ubtu24cis_sshd_default_client_alive_count_max }}"
886-
# This variable specifies the amount of seconds allowed for successful authentication to
887-
# the SSH server.
888-
ubtu24cis_sshd_login_grace_time: "{{ ubtu24cis_sshd_default_login_grace_time }}"
889-
# This variables is used to set the maximum number of open sessions per connection.
890-
ubtu24cis_sshd_max_sessions: "{{ ubtu24cis_sshd_default_max_sessions }}"
891863
# This variable, if specified, configures a list of USER name patterns, separated by spaces, to allow SSH
892864
# access for users whose user name matches one of the patterns. This is done
893865
# by setting the value of `AllowUsers` option in `/etc/ssh/sshd_config` file.

tasks/section_4/cis_4.2.x.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@
110110
community.general.ufw:
111111
rule: allow
112112
direction: out
113-
to_port: '{{ item }}'
114-
with_items:
115-
- "{{ ubtu24cis_ufw_allow_out_ports }}"
113+
proto: "{{ item.proto }}"
114+
to_port: '{{ item.port }}'
115+
loop: "{{ ubtu24cis_ufw_allow_out_ports }}"
116+
loop_control:
117+
label: "{{ item.port }}"
116118
notify: Reload ufw
117119

118120
- name: "4.2.5 | PATCH | Ensure ufw outbound connections are configured | Allow all"

tasks/section_5/cis_5.1.x.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
when: "ubtu24cis_sshd_allow_users| default('') | length > 0 "
106106
ansible.builtin.lineinfile:
107107
path: /etc/ssh/sshd_config
108-
regexp: '(?i)^(#|)\s*AllowUsers'
108+
regexp: '(?i)^(#?)\s*AllowUsers'
109109
line: 'AllowUsers {{ ubtu24cis_sshd_allow_users }}'
110110
validate: 'sshd -t -f %s'
111111
notify: Restart sshd
@@ -114,7 +114,7 @@
114114
when: "ubtu24cis_sshd_allow_groups| default('') | length > 0"
115115
ansible.builtin.lineinfile:
116116
path: /etc/ssh/sshd_config
117-
regexp: '(?i)^(#|)\s*AllowGroups'
117+
regexp: '(?i)^(#?)\s*AllowGroups'
118118
line: 'AllowGroups {{ ubtu24cis_sshd_allow_groups }}'
119119
validate: 'sshd -t -f %s'
120120
notify: Restart sshd
@@ -123,7 +123,7 @@
123123
when: "ubtu24cis_sshd_deny_users| default('') | length > 0"
124124
ansible.builtin.lineinfile:
125125
path: /etc/ssh/sshd_config
126-
regexp: '(?i)^(#|)\s*DenyUsers'
126+
regexp: '(?i)^(#?)\s*DenyUsers'
127127
line: 'DenyUsers {{ ubtu24cis_sshd_deny_users }}'
128128
validate: 'sshd -t -f %s'
129129
notify: Restart sshd
@@ -194,8 +194,8 @@
194194
line: "{{ item.line }}"
195195
validate: 'sshd -t -f %s'
196196
with_items:
197-
- { regexp: '^ClientAliveInterval', line: 'ClientAliveInterval {{ ubtu24cis_sshd_client_alive_interval | default(ubtu24cis_sshd_default_client_alive_interval) }}' }
198-
- { regexp: '^ClientAliveCountMax', line: 'ClientAliveCountMax {{ ubtu24cis_sshd_client_alive_count_max | default(ubtu24cis_sshd_default_client_alive_count_max) }}' }
197+
- { regexp: '^ClientAliveInterval', line: 'ClientAliveInterval {{ ubtu24cis_sshd_client_alive_interval }}' }
198+
- { regexp: '^ClientAliveCountMax', line: 'ClientAliveCountMax {{ ubtu24cis_sshd_client_alive_count_max }}' }
199199
notify: Restart sshd
200200

201201
- name: "5.1.8 | PATCH | Ensure sshd DisableForwarding is enabled"
@@ -209,7 +209,7 @@
209209
- sshd
210210
ansible.builtin.lineinfile:
211211
path: /etc/ssh/sshd_config
212-
regexp: (?i)^(#|)\s*DisableForwarding
212+
regexp: (?i)^(#?)\s*DisableForwarding
213213
line: 'DisableForwarding yes'
214214
validate: 'sshd -t -f %s'
215215
notify: Restart sshd
@@ -229,7 +229,7 @@
229229
- sshd
230230
ansible.builtin.lineinfile:
231231
path: /etc/ssh/sshd_config
232-
regexp: (?i)^(#|)\s*GSSAPIAuthentication
232+
regexp: (?i)^(#?)\s*GSSAPIAuthentication
233233
line: 'GSSAPIAuthentication no'
234234
validate: 'sshd -t -f %s'
235235
notify: Restart sshd
@@ -249,7 +249,7 @@
249249
- sshd
250250
ansible.builtin.lineinfile:
251251
path: /etc/ssh/sshd_config
252-
regexp: (?i)^(#|)\s*HostbasedAuthentication
252+
regexp: (?i)^(#?)\s*HostbasedAuthentication
253253
line: 'HostbasedAuthentication no'
254254
validate: 'sshd -t -f %s'
255255
notify: Restart sshd
@@ -269,7 +269,7 @@
269269
- sshd
270270
ansible.builtin.lineinfile:
271271
path: /etc/ssh/sshd_config
272-
regexp: (?i)^(#|)\s*IgnoreRhosts
272+
regexp: (?i)^(#?)\s*IgnoreRhosts
273273
line: 'IgnoreRhosts yes'
274274
validate: 'sshd -t -f %s'
275275
notify: Restart sshd
@@ -285,8 +285,8 @@
285285
- sshd
286286
ansible.builtin.lineinfile:
287287
path: /etc/ssh/sshd_config
288-
regexp: (?i)^(#|)\s*KexAlgorithms
289-
line: "KexAlgorithms {{ ubtu24cis_sshd_kex_algorithms | default(ubtu24cis_sshd_default_kex_algorithms) | join(',') }}"
288+
regexp: (?i)^(#?)\s*KexAlgorithms
289+
line: "KexAlgorithms {{ ubtu24cis_sshd_kex_algorithms | join(',') }}"
290290
insertafter: '^# Ciphers and keying'
291291
validate: 'sshd -t -f %s'
292292
notify: Restart sshd
@@ -302,8 +302,8 @@
302302
- sshd
303303
ansible.builtin.lineinfile:
304304
path: /etc/ssh/sshd_config
305-
regexp: (?i)^(#|)\s*LoginGraceTime
306-
line: 'LoginGraceTime {{ ubtu24cis_sshd_login_grace_time | default(ubtu24cis_sshd_default_login_grace_time) }}'
305+
regexp: (?i)^(#?)\s*LoginGraceTime
306+
line: 'LoginGraceTime {{ ubtu24cis_sshd_login_grace_time }}'
307307
insertafter: '^# Authentication'
308308
validate: 'sshd -t -f %s'
309309
notify: Restart sshd
@@ -321,8 +321,8 @@
321321
- sshd
322322
ansible.builtin.lineinfile:
323323
path: /etc/ssh/sshd_config
324-
regexp: (?i)^(#|)\s*LogLevel
325-
line: 'LogLevel {{ ubtu24cis_sshd_log_level | default(ubtu24cis_sshd_default_log_level) }}'
324+
regexp: (?i)^(#?)\s*LogLevel
325+
line: 'LogLevel {{ ubtu24cis_sshd_log_level }}'
326326
insertafter: '^# Logging'
327327
validate: 'sshd -t -f %s'
328328
notify: Restart sshd
@@ -342,8 +342,8 @@
342342
- sshd
343343
ansible.builtin.lineinfile:
344344
path: /etc/ssh/sshd_config
345-
regexp: (?i)^(#|)\s*MACs
346-
line: "MACs {{ ubtu24cis_sshd_macs | default(ubtu24cis_sshd_default_macs) | join(',') }}"
345+
regexp: (?i)^(#?)\s*MACs
346+
line: "MACs {{ ubtu24cis_sshd_macs | join(',')}}"
347347
insertafter: '^# Ciphers and keying'
348348
validate: 'sshd -t -f %s'
349349
notify: Restart sshd
@@ -359,8 +359,8 @@
359359
- sshd
360360
ansible.builtin.lineinfile:
361361
path: /etc/ssh/sshd_config
362-
regexp: (?i)^(#|)\s*MaxAuthTries
363-
line: 'MaxAuthTries {{ ubtu24cis_sshd_max_auth_tries | default(ubtu24cis_sshd_default_max_auth_tries) }}'
362+
regexp: (?i)^(#?)\s*MaxAuthTries
363+
line: 'MaxAuthTries {{ ubtu24cis_sshd_max_auth_tries }}'
364364
insertafter: '^# Authentication'
365365
validate: 'sshd -t -f %s'
366366
notify: Restart sshd
@@ -380,8 +380,8 @@
380380
- sshd
381381
ansible.builtin.lineinfile:
382382
path: /etc/ssh/sshd_config
383-
regexp: (?i)^(#|)\s*MaxSessions
384-
line: 'MaxSessions {{ ubtu24cis_sshd_max_sessions | default(ubtu24cis_sshd_default_max_sessions) }}'
383+
regexp: (?i)^(#?)\s*MaxSessions
384+
line: 'MaxSessions {{ ubtu24cis_sshd_max_sessions }}'
385385
insertafter: '^# Authentication'
386386
validate: 'sshd -t -f %s'
387387
notify: Restart sshd
@@ -401,7 +401,7 @@
401401
- sshd
402402
ansible.builtin.lineinfile:
403403
path: /etc/ssh/sshd_config
404-
regexp: (?i)^(#|)\s*MaxStartups
404+
regexp: (?i)^(#?)\s*MaxStartups
405405
line: 'MaxStartups 10:30:60'
406406
validate: 'sshd -t -f %s'
407407
notify: Restart sshd
@@ -421,7 +421,7 @@
421421
- sshd
422422
ansible.builtin.lineinfile:
423423
path: /etc/ssh/sshd_config
424-
regexp: (?i)^(#|)\s*PermitEmptyPasswords
424+
regexp: (?i)^(#?)\s*PermitEmptyPasswords
425425
line: 'PermitEmptyPasswords no'
426426
insertafter: '# To disable tunneled clear text passwords'
427427
validate: 'sshd -t -f %s'
@@ -438,7 +438,7 @@
438438
- sshd
439439
ansible.builtin.lineinfile:
440440
path: /etc/ssh/sshd_config
441-
regexp: (?i)^(#|)\s*PermitRootLogin
441+
regexp: (?i)^(#?)\s*PermitRootLogin
442442
line: 'PermitRootLogin no'
443443
validate: 'sshd -t -f %s'
444444
notify: Restart sshd
@@ -458,7 +458,7 @@
458458
- sshd
459459
ansible.builtin.lineinfile:
460460
path: /etc/ssh/sshd_config
461-
regexp: (?i)^(#|)\s*PermitUserEnvironment
461+
regexp: (?i)^(#?)\s*PermitUserEnvironment
462462
line: 'PermitUserEnvironment no'
463463
validate: 'sshd -t -f %s'
464464
notify: Restart sshd
@@ -479,7 +479,7 @@
479479
- pam
480480
ansible.builtin.lineinfile:
481481
path: /etc/ssh/sshd_config
482-
regexp: (?i)^(#|)\s*UsePAM
482+
regexp: (?i)^(#?)\s*UsePAM
483483
line: 'UsePAM yes'
484484
insertafter: '^# and ChallengeResponseAuthentication'
485485
validate: 'sshd -t -f %s'

tasks/section_6/cis_6.1.1.x.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,49 @@
9696
- '^(\s*RuntimeMaxUse\s*=)'
9797
- '^(\s*RuntimeKeepFree\s*=.*)'
9898
- '^(\s*MaxFileSec\s*=.*)'
99+
100+
- name: "6.1.1.4 | PATCH | Ensure only one logging system is in use"
101+
when: ubtu24cis_rule_6_1_1_4
102+
tags:
103+
- level1-server
104+
- level1-workstation
105+
- patch
106+
- journald
107+
- rule_6.1.1.4
108+
- NIST800-53R5_AU-2
109+
- NIST800-53R5_AU-7
110+
- NIST800-53R5_AU-12
111+
block:
112+
- name: "6.1.1.4 | PATCH | Ensure only one logging system is in use | If journald"
113+
when: ubtu24cis_syslog_service == "journald"
114+
block:
115+
- name: "6.1.1.4 | PATCH | Ensure only one logging system is in use | If journald"
116+
ansible.builtin.systemd:
117+
name: systemd-journald.service
118+
state: started
119+
enabled: true
120+
121+
- name: "6.1.1.4 | PATCH | Ensure only one logging system is in use | If journald"
122+
when: "'rsyslog' in ansible_facts.packages"
123+
ansible.builtin.systemd:
124+
name: rsyslog.service
125+
state: stopped
126+
enabled: false
127+
128+
- name: "6.1.1.4 | PATCH | Ensure only one logging system is in use | If rsyslog"
129+
when: ubtu24cis_syslog_service == "rsyslog"
130+
block:
131+
- name: "6.1.1.4 | PATCH | Ensure only one logging system is in use | If rsyslog"
132+
ansible.builtin.systemd:
133+
name: rsyslog.service
134+
state: started
135+
enabled: true
136+
137+
- name: "6.1.1.4 | PATCH | Ensure only one logging system is in use | If rsyslog"
138+
when: "'systemd-journal' in ansible_facts.packages"
139+
ansible.builtin.systemd:
140+
name: systemd-journald.service
141+
state: stopped
142+
enabled: false
143+
failed_when: discovered_missing_service.changed or "'Could not find' not in discovered_missing_service.msg"
144+
register: discovered_missing_service

0 commit comments

Comments
 (0)