Skip to content

Commit 14aa65c

Browse files
authored
Merge pull request #57 from ansible-lockdown/devel
Release to main
2 parents 23b208f + e584025 commit 14aa65c

File tree

9 files changed

+77
-38
lines changed

9 files changed

+77
-38
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ repos:
4141
- id: detect-secrets
4242

4343
- repo: https://github.com/gitleaks/gitleaks
44-
rev: v8.26.0
44+
rev: v8.28.0
4545
hooks:
4646
- id: gitleaks
4747

4848
- repo: https://github.com/ansible-community/ansible-lint
49-
rev: v25.4.0
49+
rev: v25.7.0
5050
hooks:
5151
- id: ansible-lint
5252
name: Ansible-lint

.yamllint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rules:
1616
comments:
1717
ignore-shebangs: true
1818
min-spaces-from-content: 1 # prettier compatibility
19-
comments-indentation: enable
19+
comments-indentation: disable
2020
empty-lines:
2121
max: 1
2222
indentation:

tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
tags: always
4545
block:
4646
- name: Ensure root password is set
47-
ansible.builtin.shell: passwd -S root | egrep -e "(Password set, SHA512 crypt|root P |Password locked)"
47+
ansible.builtin.shell: LC_ALL=C passwd -S root | grep -E "(Password set, SHA512 crypt|root P |root L |Password locked)"
4848
changed_when: false
4949
failed_when: false
5050
register: prelim_root_passwd_set

tasks/parse_etc_password.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
- name: "PRELIM | Parse /etc/passwd | Split passwd entries"
1414
ansible.builtin.set_fact:
15-
ubtu24cis_passwd: "{{ prelim_passwd_file_audit.stdout_lines | map('regex_replace', ld_passwd_regex, ld_passwd_yaml) | map('from_yaml') | list }}"
15+
prelim_captured_passwd_data: "{{ prelim_passwd_file_audit.stdout_lines | map('regex_replace', ld_passwd_regex, ld_passwd_yaml) | map('from_yaml') | list }}"
1616
vars:
1717
ld_passwd_regex: >-
1818
^(?P<id>[^:]*):(?P<password>[^:]*):(?P<uid>[^:]*):(?P<gid>[^:]*):(?P<gecos>[^:]*):(?P<dir>[^:]*):(?P<shell>[^:]*)

tasks/section_2/cis_2.4.1.x.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: "2.4.1.1 | PATCH | Ensure cron daemon is enabled and running"
43
when: ubtu24cis_rule_2_4_1_1
54
tags:
@@ -32,7 +31,7 @@
3231
path: /etc/crontab
3332
owner: root
3433
group: root
35-
mode: 'go-rwx'
34+
mode: "go-rwx"
3635

3736
- name: "2.4.1.3 | PATCH | Ensure permissions on /etc/cron.hourly are configured"
3837
when: ubtu24cis_rule_2_4_1_3
@@ -48,7 +47,7 @@
4847
path: /etc/cron.hourly
4948
owner: root
5049
group: root
51-
mode: 'u+x,go-rwx'
50+
mode: "u+x,go-rwx"
5251
state: directory
5352

5453
- name: "2.4.1.4 | PATCH | Ensure permissions on /etc/cron.daily are configured"
@@ -65,7 +64,7 @@
6564
path: /etc/cron.daily
6665
owner: root
6766
group: root
68-
mode: 'u+x,go-rwx'
67+
mode: "u+x,go-rwx"
6968
state: directory
7069

7170
- name: "2.4.1.5 | PATCH | Ensure permissions on /etc/cron.weekly are configured"
@@ -82,7 +81,7 @@
8281
path: /etc/cron.weekly
8382
owner: root
8483
group: root
85-
mode: 'u+x,go-rwx'
84+
mode: "u+x,go-rwx"
8685
state: directory
8786

8887
- name: "2.4.1.6 | PATCH | Ensure permissions on /etc/cron.monthly are configured"
@@ -99,7 +98,7 @@
9998
path: /etc/cron.monthly
10099
owner: root
101100
group: root
102-
mode: 'u+x,go-rwx'
101+
mode: "u+x,go-rwx"
103102
state: directory
104103

105104
- name: "2.4.1.7 | PATCH | Ensure permissions on /etc/cron.d are configured"
@@ -116,7 +115,7 @@
116115
path: /etc/cron.d
117116
owner: root
118117
group: root
119-
mode: 'u+x,go-rwx'
118+
mode: "u+x,go-rwx"
120119
state: directory
121120

122121
- name: "2.4.1.8 | PATCH | Ensure cron is restricted to authorized users"
@@ -146,13 +145,13 @@
146145
path: /etc/cron.allow
147146
owner: root
148147
group: root
149-
mode: 'u-x,g-wx,o-rwx'
148+
mode: "u-x,g-wx,o-rwx"
150149
state: touch
151150

152151
- name: "2.4.1.8 | PATCH | Ensure cron is restricted to authorized users | Update cron.allow if exists"
153152
when: discovered_cron_allow_status.stat.exists
154153
ansible.builtin.file:
155154
path: /etc/cron.allow
156155
owner: root
157-
group: '{{ (discovered_cron_allow_status.stat.gr_name == "crontab") | ternary(omit,"root") }}'
158-
mode: 'u-x,g-wx,o-rwx'
156+
group: '{{ (discovered_cron_allow_status.stat.gr_name == "crontab") | ternary(omit, "root") }}'
157+
mode: "u-x,g-wx,o-rwx"

tasks/section_5/cis_5.4.1.x.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
changed_when: true
157157
failed_when: false
158158
with_items:
159-
- "{{ ubtu24cis_passwd | map(attribute='id') | list | intersect(discovered_passwd_inactive_users.stdout_lines) | list }}"
159+
- "{{ prelim_captured_passwd_data | map(attribute='id') | list | intersect(discovered_passwd_inactive_users.stdout_lines) | list }}"
160160

161161
- name: "5.4.1.6 | PATCH | Ensure all users last password change date is in the past"
162162
when:

tasks/section_5/cis_5.4.2.x.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
regexp: \s*umask
197197
line: "umask {{ ubtu24cis_root_umask }}"
198198
create: true
199-
mode: 'u+x,go-rwx'
199+
mode: 'go-rwx'
200200

201201
- name: "5.4.2.7 | PATCH | Ensure system accounts do not have a valid login shell"
202202
when:
@@ -217,7 +217,7 @@
217217
ansible.builtin.user:
218218
name: "{{ item.id }}"
219219
shell: /usr/sbin/nologin
220-
loop: "{{ ubtu24cis_passwd }}"
220+
loop: "{{ prelim_captured_passwd_data }}"
221221
loop_control:
222222
label: "{{ item.id }}"
223223

@@ -240,6 +240,6 @@
240240
ansible.builtin.user:
241241
name: "{{ item.id }}"
242242
password_lock: true
243-
loop: "{{ ubtu24cis_passwd }}"
243+
loop: "{{ prelim_captured_passwd_data }}"
244244
loop_control:
245245
label: "{{ item.id }}"

tasks/section_7/cis_7.2.x.yml

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
owner: "{{ item.id }}"
266266
group: "{{ item.gid }}"
267267
mode: 'g-w,o-rwx'
268-
loop: "{{ ubtu24cis_passwd | selectattr('uid', '>=', min_int_uid | int) | selectattr('uid', '<=', max_int_uid | int) | list }}"
268+
loop: "{{ prelim_captured_passwd_data | selectattr('uid', '>=', min_int_uid | int) | selectattr('uid', '<=', max_int_uid | int) | list }}"
269269
loop_control:
270270
label: "{{ item.id }}"
271271

@@ -308,33 +308,73 @@
308308
vars:
309309
warn_control_id: '7.2.10'
310310
block:
311-
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured | Check for files"
312-
ansible.builtin.shell: find /home/ /root/ -name "\.*" -type f -perm /u+x,g+wx,o+wx
311+
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured"
312+
ansible.builtin.shell: find {{ prelim_interactive_users_home.stdout_lines | list | join(' ') }} -name "\.*" -type f
313313
changed_when: false
314-
failed_when: discovered_homedir_dot_files.rc not in [ 0, 1 ]
314+
failed_when: discovered_homedir_hidden_files.rc not in [ 0, 1 ]
315315
check_mode: false
316-
register: discovered_homedir_dot_files
316+
register: discovered_homedir_hidden_files
317317

318318
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured | Warning on files found"
319319
when:
320-
- discovered_homedir_dot_files.stdout | length > 0
321-
- ubtu24cis_dotperm_ansiblemanaged
320+
- discovered_homedir_hidden_files.stdout | length > 0
321+
- not ubtu24cis_dotperm_ansiblemanaged
322322
ansible.builtin.debug:
323323
msg:
324-
- "Warning!! We have discovered group or world-writable dot files on your system and this host is configured for manual intervention. Please investigate these files further."
324+
- "Warning!! Please investigate that hidden files found in users home directories match control requirements."
325325

326-
- name: "7.2.10 | PATCH | Ensure local interactive user dot files access is configured | Set warning count"
326+
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured | Set warning count"
327327
when:
328-
- discovered_homedir_dot_files.stdout | length > 0
329-
- ubtu24cis_dotperm_ansiblemanaged
328+
- discovered_homedir_hidden_files.stdout | length > 0
329+
- not ubtu24cis_dotperm_ansiblemanaged
330330
ansible.builtin.import_tasks:
331331
file: warning_facts.yml
332332

333-
- name: "7.2.10 | PATCH | Ensure local interactive user dot files access is configured | Changes files if configured"
333+
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured"
334334
when:
335-
- discovered_homedir_dot_files.stdout | length > 0
335+
- discovered_homedir_hidden_files.stdout | length > 0
336336
- ubtu24cis_dotperm_ansiblemanaged
337-
ansible.builtin.file:
338-
path: '{{ item }}'
339-
mode: 'u-x,go-wx'
340-
with_items: "{{ discovered_homedir_dot_files.stdout_lines }}"
337+
block:
338+
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured | Changes files if configured .bash_history & .netrc"
339+
when:
340+
- discovered_homedir_hidden_files.stdout | length > 0
341+
- item | basename in ['.bash_history','.netrc']
342+
ansible.builtin.file:
343+
path: "{{ item }}"
344+
mode: 'u-x,go-rwx'
345+
failed_when: discovered_dot_bash_history_to_change.state not in '[ file, absent ]'
346+
register: discovered_dot_bash_history_to_change
347+
loop: "{{ discovered_homedir_hidden_files.stdout_lines }}"
348+
349+
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured | Changes files if configured file mode"
350+
ansible.builtin.file:
351+
path: '{{ item }}'
352+
mode: 'u-x,go-wx'
353+
failed_when: discovered_dot_bash_history_to_change.state not in '[ file, absent ]'
354+
register: discovered_dot_bash_history_to_change
355+
loop: "{{ discovered_homedir_hidden_files.stdout_lines }}"
356+
357+
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured | Changes files ownerships"
358+
ansible.builtin.file:
359+
path: "{{ item }}"
360+
owner: "{{ prelim_captured_passwd_data | selectattr('dir', 'in', prelim_interactive_users_home.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='uid') | last }}"
361+
group: "{{ prelim_captured_passwd_data | selectattr('dir', 'in', prelim_interactive_users_home.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='gid') | last }}"
362+
failed_when: discovered_dot_bash_history_to_change.state not in '[ file, absent ]'
363+
register: discovered_dot_bash_history_to_change
364+
loop: "{{ discovered_homedir_hidden_files.stdout_lines }}"
365+
366+
- name: "7.2.10 | PATCH | Ensure local interactive user dot files access is configured | Changes files if configured"
367+
ansible.builtin.file:
368+
path: '{{ item }}'
369+
mode: 'go-w'
370+
owner: "{{ prelim_captured_passwd_data | selectattr('dir', 'in', prelim_interactive_users_home.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='uid') | last }}"
371+
group: "{{ prelim_captured_passwd_data | selectattr('dir', 'in', prelim_interactive_users_home.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='gid') | last }}"
372+
with_items: "{{ discovered_homedir_hidden_files.stdout_lines }}"
373+
374+
- name: "7.2.10 | AUDIT | Ensure local interactive user dot files access is configured | rename .forward or .rhosts files"
375+
when:
376+
- item | basename in ['.forward','.rhosts']
377+
- item is not search ("CIS")
378+
ansible.builtin.command: "mv {{ item }} {{ item }}_CIS_TOBEREVIEWED"
379+
changed_when: true
380+
loop: "{{ discovered_homedir_hidden_files.stdout_lines }}"

templates/usr/share/pam-configs/pam_unix.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ Session-Initial:
1818
required pam_unix.so
1919
Password-Type: Primary
2020
Password:
21-
[success=end default=ignore] pam_unix.so obscure{% if ubtu24cis_rule_5.3.3.4.4 %} use_authtok{% endif %} try_first_pass{% if ubtu24cis_rule_5.3.3.4.3 %} {{ ubtu24cis_passwd_hash_algo }}{% endif %}
21+
[success=end default=ignore] pam_unix.so obscure{% if ubtu24cis_rule_5_3_3_4_4 %} use_authtok{% endif %} try_first_pass{% if ubtu24cis_rule_5_3_3_4_3 %} {{ ubtu24cis_passwd_hash_algo }}{% endif %}
2222
Password-Initial:
23-
[success=end default=ignore] pam_unix.so obscure{% if ubtu24cis_rule_5.3.3.4.3 %} {{ ubtu24cis_passwd_hash_algo }}{% endif %}
23+
[success=end default=ignore] pam_unix.so obscure{% if ubtu24cis_rule_5_3_3_4_3 %} {{ ubtu24cis_passwd_hash_algo }}{% endif %}

0 commit comments

Comments
 (0)