Skip to content

Commit 1529934

Browse files
Merge pull request #327 from ansible-lockdown/devel
Update latest main branch
2 parents 59aa99f + 1adc7bd commit 1529934

12 files changed

Lines changed: 139 additions & 37 deletions

File tree

.ansible-lint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22

3-
parseable: true
43
quiet: true
54
skip_list:
65
- 'package-latest'

.pre-commit-config.yaml

Lines changed: 3 additions & 3 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.28.0
44+
rev: v8.30.0
4545
hooks:
4646
- id: gitleaks
4747

4848
- repo: https://github.com/ansible-community/ansible-lint
49-
rev: v25.9.2
49+
rev: v26.1.1
5050
hooks:
5151
- id: ansible-lint
5252
name: Ansible-lint
@@ -65,7 +65,7 @@ repos:
6565
# - ansible-core>=2.10.1
6666

6767
- repo: https://github.com/adrienverge/yamllint.git
68-
rev: v1.37.1 # or higher tag
68+
rev: v1.38.0 # or higher tag
6969
hooks:
7070
- id: yamllint
7171
name: Check YAML Lint

Changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
### Do not migrate
66

7+
# Jan26
8+
pre-commits
9+
#325 nopasswd for sudoers options added
10+
chrony template tidied up
11+
12+
# Dec 25 update
13+
pre-commits
14+
15+
4.1.5 updated variables, loop and added ntp
16+
6.3.4.1/2/3 separated the tasks
17+
prelim check for pwquality changed_when logic update thanks to @FrsECM #318
18+
719
# Sept 25 updates
820

921
- 5.4.2.5 improved thanks to @numericillustration

defaults/main.yml

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,16 @@ ubtu22cis_ufw_use_sysctl: true
791791
# If you want to allow outbound traffic on all ports, set the variable to `all`, e.g.,
792792
# `ubtu22cis_ufw_allow_out_ports: "all"`.
793793
ubtu22cis_ufw_allow_out_ports:
794-
- 53
795-
- 80
796-
- 443
794+
- port: 53
795+
proto: tcp
796+
- port: 53
797+
proto: udp
798+
- port: 80
799+
proto: tcp
800+
- port: 123
801+
proto: udp
802+
- port: 443
803+
proto: tcp
797804

798805
## Controls 4.2.x - nftables
799806
# Nftables is not supported in this role. Some tasks have parts of them commented out, this is one example
@@ -902,6 +909,12 @@ ubtu22cis_sshd_deny_groups: ""
902909
# CIS recommends `sudo` or, if LDAP functionality is required, `sudo-ldap`.
903910
ubtu22cis_sudo_package: "sudo"
904911

912+
## control 5.2.4 sudoers NOPASSWD
913+
# This will leave NOPASSWD intact for these users
914+
ubtu22cis_sudoers_exclude_nopasswd_list:
915+
- ec2-user
916+
- vagrant
917+
905918
## Control 5.2.3
906919
# This variable defines the path and file name of the sudo log file.
907920
ubtu22cis_sudo_logfile: "/var/log/sudo.log"
@@ -1135,6 +1148,37 @@ ubtu22cis_aide_cron_month: '*'
11351148
# can be concatenated with commas.
11361149
ubtu22cis_aide_cron_weekday: '*'
11371150

1151+
# This variable represents the actual command or script that the systemd timer
1152+
# will execute for running AIDE in update mode.
1153+
ubtu22cis_aide_systemd_exec: '/usr/bin/aide --config /etc/aide/aide.conf --update'
1154+
1155+
# These variables define the schedule for the systemd timer job
1156+
# This variable governs the minute of the time of day when the AIDE systemd timer is run.
1157+
# It must be in the range `0-59`.
1158+
ubtu22cis_aide_systemd_minute: 0
1159+
1160+
# This variable governs the hour of the time of day when the AIDE systemd timer is run.
1161+
# It must be in the range `0-23`.
1162+
ubtu22cis_aide_systemd_hour: 5
1163+
1164+
# This variable governs the day of the month when the AIDE systemd timer is run.
1165+
# `*` signifies that the job is run on all days; furthermore, specific days
1166+
# can be given in the range `1-31`; several days can be concatenated with a comma.
1167+
# The specified day(s) must be in the range `1-31`.
1168+
ubtu22cis_aide_systemd_day: '*'
1169+
1170+
# This variable governs months when the AIDE systemd timer is run.
1171+
# `*` signifies that the job is run in every month; furthermore, specific months
1172+
# can be given in the range `1-12`; several months can be concatenated with commas.
1173+
# The specified month(s) must be in the range `1-12`.
1174+
ubtu22cis_aide_systemd_month: '*'
1175+
1176+
# This variable governs the weekdays when the AIDE systemd timer is run.
1177+
# `*` signifies that the job is run on all weekdays; furthermore, specific weekdays
1178+
# can be given in the range `0-7` (both `0` and `7` represent Sunday); several weekdays
1179+
# can be concatenated with commas.
1180+
ubtu22cis_aide_systemd_weekday: '*'
1181+
11381182
## Controls 6.2.1.x journald
11391183

11401184
# This variable specifies the address of the remote log host where logs are being sent.
@@ -1276,9 +1320,16 @@ ubtu22cis_dotperm_ansiblemanaged: true
12761320

12771321
## Section 7
12781322

1279-
# 7.1.12 Ensure no files or directories without an owner and a group exist
1280-
ubtu22cis_exclude_unowned_search_path: (! -path "/run/user/*" -a ! -path "/proc/*" -a ! -path "*/containerd/*" -a ! -path "*/kubelet/pods/*" -a ! -path "*/kubelet/plugins/*" -a ! -path "/sys/fs/cgroup/memory/*" -a ! -path "/var/*/private/*")
1323+
# 7.1.12
1324+
# Ensure no files or directories without an owner and a group exist
1325+
# Extend the list as required adding the the current list e.g. "-a ! -path "/somedir/*"
1326+
# Note Ensure to document all exclusions that do not match the benchmark
1327+
ubtu22cis_exclude_unowned_search_path: '\( ! -path "/run/user/*" -a ! -path "/proc/*" -a ! -path "*/containerd/*" -a ! -path "*/kubelet/pods/*" -a ! -path "*/kubelet/plugins/*" -a ! -path "/sys/fs/cgroup/memory/*" -a ! -path "/var/*/private/*" \)'
12811328

1329+
# This can be extended as seen fit
1330+
# NFS added as starter to be extended with "-a -not -fstype CIFS"
1331+
# Note Ensure to document all exclusions that do not match the benchmark
1332+
ubtu22cis_exclude_unowned_filesystem_types: '\( -not -fstype nfs \)'
12821333
# Control 7.1.12
12831334
# The value of this variable specifies the owner that will be set for unowned files and directories.
12841335
ubtu22cis_unowned_owner: root

tasks/prelim.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
modification_time: preserve
169169
access_time: preserve
170170
register: prelim_pwquality_dummy
171-
changed_when: prelim_pwquality_dummy.diff == "absent"
171+
changed_when: prelim_pwquality_dummy.changed
172172
loop:
173173
- { path: '/etc/security/pwquality.conf.d', state: 'directory' }
174174
- { path: '/etc/security/pwquality.conf.d/cis_dummy.conf', state: 'touch' }

tasks/section_4/cis_4.1.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-
- "{{ ubtu22cis_ufw_allow_out_ports }}"
113+
proto: "{{ item.proto }}"
114+
to_port: '{{ item.port }}'
115+
loop: "{{ ubtu22cis_ufw_allow_out_ports }}"
116+
loop_control:
117+
label: "{{ item.port }}"
116118
notify: Reload ufw
117119

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

tasks/section_5/cis_5.2.x.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,22 @@
5353
- sudo
5454
- rule_5.2.4
5555
- NIST800-53R5_AC-6
56-
ansible.builtin.replace:
57-
path: "{{ item }}"
58-
regexp: '^([^#|{% if system_is_ec2 %}ec2-user{% endif %}].*)NOPASSWD(.*)'
59-
replace: '\1PASSWD\2'
60-
validate: '/usr/sbin/visudo -cf %s'
61-
loop: "{{ prelim_sudoers_files.stdout_lines }}"
56+
block:
57+
- name: "5.2.4 | AUDIT | Ensure users must provide password for escalation | discover accts with NOPASSWD"
58+
ansible.builtin.shell: grep -Ei '(nopasswd)' /etc/sudoers /etc/sudoers.d/* | cut -d':' -f1
59+
become: true
60+
changed_when: false
61+
failed_when: false
62+
register: discovered_sudoers_nopasswd
63+
64+
- name: "5.2.4 | PATCH | Ensure users must provide password for escalation"
65+
when: discovered_sudoers_nopasswd.stdout | length > 0
66+
ansible.builtin.replace:
67+
path: "{{ item }}"
68+
regexp: '^((?!#|{% for name in ubtu22cis_sudoers_exclude_nopasswd_list %}{{ name }}{% if not loop.last -%}|{%- endif -%}{% endfor %}).*)NOPASSWD(.*)'
69+
replace: '\1PASSWD\2'
70+
validate: '/usr/sbin/visudo -cf %s'
71+
loop: "{{ discovered_sudoers_nopasswd.stdout_lines }}"
6272

6373
- name: "5.2.5 | PATCH | Ensure re-authentication for privilege escalation is not disabled globally"
6474
when: ubtu22cis_rule_5_2_5

tasks/section_6/cis_6.3.4.x.yml

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,57 @@
11
---
22

3-
- name: |
4-
"6.3.4.1 | PATCH | Ensure audit log files mode is configured"
5-
"6.3.4.2 | PATCH | Ensure audit log files owner is configured"
6-
"6.3.4.3 | PATCH | Ensure audit log files group owner is configured"
7-
when:
8-
- ubtu22cis_rule_6_3_4_1 or
9-
ubtu22cis_rule_6_3_4_2 or
10-
ubtu22cis_rule_6_3_4_3
3+
- name: "6.3.4.1 | PATCH | Ensure audit log files mode is configured"
4+
when: ubtu22cis_rule_6_3_4_1
115
tags:
126
- level1-server
137
- level1-workstation
148
- patch
159
- auditd
1610
- rule_6.3.4.1
11+
- NIST800-53R5_AU-3
12+
ansible.builtin.file:
13+
path: "{{ prelim_auditd_logfile.stdout | dirname }}"
14+
recurse: true
15+
mode: 'u-x,g-wx,o-rwx'
16+
17+
- name: "6.3.4.2 | PATCH | Ensure audit log files owner is configured"
18+
when: ubtu22cis_rule_6_3_4_2
19+
tags:
20+
- level1-server
21+
- level1-workstation
22+
- patch
23+
- auditd
1724
- rule_6.3.4.2
18-
- rule_6.3.4.3
1925
- NIST800-53R5_AU-3
2026
ansible.builtin.file:
21-
path: "{{ prelim_auditd_logfile.stdout }}"
27+
path: "{{ prelim_auditd_logfile.stdout | dirname }}"
28+
recurse: true
2229
owner: root
23-
group: root
24-
mode: 'u-x,g-wx,o-rwx'
30+
31+
- name: "6.3.4.3 | PATCH | Ensure audit log files group owner is configured"
32+
when: ubtu22cis_rule_6_3_4_3
33+
tags:
34+
- level1-server
35+
- level1-workstation
36+
- patch
37+
- auditd
38+
- rule_6.3.4.3
39+
- NIST800-53R5_AU-3
40+
block:
41+
- name: "6.3.4.3 | AUDIT | Ensure audit log files group owner is configured | stat logfile"
42+
ansible.builtin.find:
43+
path: "{{ prelim_auditd_logfile.stdout | dirname }}"
44+
file_type: file
45+
register: discovered_auditd_logs
46+
47+
- name: "6.3.4.3 | PATCH | Ensure audit log files group owner is configured"
48+
when: item.gr_name not in [ 'root', 'adm' ]
49+
ansible.builtin.file:
50+
path: "{{ item.path }}"
51+
group: root
52+
loop: "{{ discovered_auditd_logs.files }}"
53+
loop_control:
54+
label: "{{ item.path }}"
2555

2656
- name: "6.3.4.4 | PATCH | Ensure the audit log file directory mode is configured"
2757
when: ubtu22cis_rule_6_3_4_4

tasks/section_7/cis_7.1.x.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
warn_control_id: '7.1.12'
221221
block:
222222
- name: "7.1.12 | AUDIT | Ensure no files or directories without an owner and a group exist | Get list files or directories"
223-
ansible.builtin.command: 'find {{ ubtu22cis_exclude_unowned_search_path }} {{ item.mount }} -xdev \( -nouser -o -nogroup \) -not -fstype nfs'
223+
ansible.builtin.command: find {{ ubtu22cis_exclude_unowned_search_path }} {{ item.mount }} -xdev \( -nouser -o -nogroup \) {{ ubtu22cis_exclude_unowned_filesystem_types }}
224224
changed_when: false
225225
failed_when: false
226226
check_mode: false

templates/chrony.conf.j2

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Welcome to the chrony configuration file. See chrony.conf(5) for more
2-
# information about usuable directives.
2+
# information about useable directives.
33

44
# This will use (up to):
55
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
@@ -89,5 +89,3 @@ logchange 0.5
8989
# chrony postinst based on what it found in /etc/default/rcS. You may
9090
# change it if necessary.
9191
rtconutc
92-
93-
user {{ ubtu22cis_chrony_user }}

0 commit comments

Comments
 (0)