Skip to content

Commit eb21b4a

Browse files
authored
Merge pull request #300 from ansible-lockdown/devel
Devel updates to main
2 parents fe4776b + 86a06b8 commit eb21b4a

16 files changed

Lines changed: 252 additions & 104 deletions

.github/workflows/devel_pipeline_validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
types: [opened, reopened, synchronize]
88
branches:
99
- devel
10+
- benchmark*
1011
paths:
1112
- '**.yml'
1213
- '**.sh'
@@ -70,7 +71,6 @@
7071
echo IAC_BRANCH=main >> $GITHUB_ENV
7172
fi
7273
73-
7474
# Pull in terraform code for linux servers
7575
- name: Clone GitHub IaC plan
7676
uses: actions/checkout@v4

.github/workflows/main_pipeline_validation.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
types: [opened, reopened, synchronize]
88
branches:
99
- main
10+
- latest
1011
paths:
1112
- '**.yml'
1213
- '**.sh'
@@ -23,17 +24,6 @@
2324
# A workflow run is made up of one or more jobs
2425
# that can run sequentially or in parallel
2526
jobs:
26-
# This will create messages for first time contributers and direct them to the Discord server
27-
welcome:
28-
runs-on: self-hosted
29-
30-
steps:
31-
- uses: actions/first-interaction@main
32-
with:
33-
repo-token: ${{ secrets.GITHUB_TOKEN }}
34-
pr-message: |-
35-
Congrats on opening your first pull request and thank you for taking the time to help improve Ansible-Lockdown!
36-
Please join in the conversation happening on the [Discord Server](https://www.lockdownenterprise.com/discord) as well.
3727

3828
# This workflow contains a single job that tests the playbook
3929
playbook-test:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ benchparse/
4343

4444
# GitHub Action/Workflow files
4545
.github/
46+
47+
# ansible-lint cache
48+
.ansible/

.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.23.3
44+
rev: v8.28.0
4545
hooks:
4646
- id: gitleaks
4747

4848
- repo: https://github.com/ansible-community/ansible-lint
49-
rev: v25.1.2
49+
rev: v25.7.0
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.35.1 # or higher tag
68+
rev: v1.37.1 # or higher tag
6969
hooks:
7070
- id: yamllint
7171
name: Check YAML Lint

defaults/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ skip_reboot: true
2020
# The audit variable found at the base
2121
benchmark: UBUNTU22-CIS
2222
benchmark_version: v2.0.0
23+
24+
# Create managed not custom local_facts files
25+
create_benchmark_facts: true
26+
ansible_facts_path: /etc/ansible/facts.d
27+
2328
# Used for audit
2429
ubtu22cis_level_1: true
2530
ubtu22cis_level_2: true
@@ -101,6 +106,20 @@ audit_conf_dest: "/opt"
101106
# Where the audit logs are stored
102107
audit_log_dir: '/opt'
103108

109+
## Ability to collect and take audit files moving to a centralised location
110+
# This enables the collection of the files from the host
111+
fetch_audit_output: false
112+
113+
# Method of getting,uploading the summary files
114+
## Ensure access and permissions are avaiable for these to occur.
115+
## options are
116+
# fetch - fetches from server and moves to location on the ansible controller (could be a mount point available to controller)
117+
# copy - copies file to a location available to the managed node
118+
audit_output_collection_method: fetch
119+
120+
# Location to put the audit files
121+
audit_output_destination: /opt/audit_summaries/
122+
104123
### Goss Settings ##
105124
####### END ########
106125

@@ -609,6 +628,10 @@ ubtu22cis_desktop_required: false
609628
# This will also purge any packages not removed via this playbook
610629
ubtu22cis_purge_apt: false
611630

631+
## Ignore change_when for apt update task
632+
# Modifies behavior of 'changed_when' for 'apt update' task in prelim that always changes
633+
ubtu22cis_ignore_apt_update_changed_when: false
634+
612635
##
613636
## Section 1 Control Variables
614637
##

tasks/fetch_audit_output.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
3+
# Stage to copy audit output to a centralised location
4+
5+
- name: "POST | FETCH | Fetch files and copy to controller"
6+
when: audit_output_collection_method == "fetch"
7+
ansible.builtin.fetch:
8+
src: "{{ item }}"
9+
dest: "{{ audit_output_destination }}"
10+
flat: true
11+
failed_when: false
12+
register: discovered_audit_fetch_state
13+
loop:
14+
- "{{ pre_audit_outfile }}"
15+
- "{{ post_audit_outfile }}"
16+
become: false
17+
18+
# Added this option for continuity but could be changed by adjusting the variable audit_conf_dest
19+
# Allowing backup to one location
20+
- name: "POST | FETCH | Copy files to location available to managed node"
21+
when: audit_output_collection_method == "copy"
22+
ansible.builtin.copy:
23+
src: "{{ item }}"
24+
dest: "{{ audit_output_destination }}"
25+
mode: 'u-x,go-wx'
26+
flat: true
27+
failed_when: false
28+
register: discovered_audit_copy_state
29+
loop:
30+
- "{{ pre_audit_outfile }}"
31+
- "{{ post_audit_outfile }}"
32+
33+
- name: "POST | FETCH | Fetch files and copy to controller | Warning if issues with fetch_audit_files"
34+
when:
35+
- (audit_output_collection_method == "fetch" and not discovered_audit_fetch_state.changed) or
36+
(audit_output_collection_method == "copy" and not discovered_audit_copy_state.changed)
37+
block:
38+
- name: "POST | FETCH | Fetch files and copy to controller | Warning if issues with fetch_audit_files"
39+
ansible.builtin.debug:
40+
msg: "Warning!! Unable to write to localhost {{ audit_output_destination }} for audit file copy"
41+
42+
- name: "POST | FETCH | Fetch files and copy to controller | Warning if issues with fetch_audit_files"
43+
vars:
44+
warn_control_id: "FETCH_AUDIT_FILES"
45+
ansible.builtin.import_tasks:
46+
file: warning_facts.yml

tasks/main.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
- name: Setup rules if container
9292
when:
9393
- ansible_connection == 'docker' or
94-
ansible_facts.virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
94+
(ansible_facts.virtualization_type is defined and
95+
ansible_facts.virtualization_type in ["docker", "lxc", "openvz", "podman", "container"])
9596
tags:
9697
- container_discovery
9798
- always
@@ -210,6 +211,39 @@
210211
ansible.builtin.import_tasks:
211212
file: post_remediation_audit.yml
212213

214+
- name: Add ansible file showing Benchmark and levels applied if audit details not present
215+
when:
216+
- create_benchmark_facts
217+
- (post_audit_summary is defined) or
218+
(ansible_local['compliance_facts']['lockdown_audit_details']['audit_summary'] is undefined and post_audit_summary is undefined)
219+
tags:
220+
- always
221+
- benchmark
222+
block:
223+
- name: Create ansible facts directory if audit facts not present
224+
ansible.builtin.file:
225+
path: "{{ ansible_facts_path }}"
226+
state: directory
227+
owner: root
228+
group: root
229+
mode: 'u=rwx,go=rx'
230+
231+
- name: Create ansible facts file and levels applied if audit facts not present
232+
ansible.builtin.template:
233+
src: etc/ansible/compliance_facts.j2
234+
dest: "{{ ansible_facts_path }}/compliance_facts.fact"
235+
owner: root
236+
group: root
237+
mode: 'u-x,go=r'
238+
239+
- name: Fetch audit files
240+
when:
241+
- fetch_audit_output
242+
- run_audit
243+
tags: always
244+
ansible.builtin.import_tasks:
245+
file: fetch_audit_output.yml
246+
213247
- name: Show Audit Summary
214248
when: run_audit
215249
tags: run_audit

tasks/prelim.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
ansible.builtin.debug:
4848
msg: "{{ prelim_mount_point_fs_and_options }}"
4949

50+
- name: "PRELIM | PATCH | Run apt update"
51+
tags: always
52+
ansible.builtin.package:
53+
update_cache: true
54+
changed_when: not ubtu22cis_ignore_apt_update_changed_when
55+
5056
- name: Include audit specific variables
5157
when:
5258
- run_audit or audit_only
@@ -141,6 +147,14 @@
141147
check_mode: false
142148
register: prelim_sudoers_files
143149

150+
- name: "PRELIM | AUDIT | Capture pam configs related files"
151+
tags: always
152+
ansible.builtin.find:
153+
paths:
154+
- '/usr/share/pam-configs/'
155+
- '/etc/pam.d/'
156+
register: prelim_pam_conf_files
157+
144158
- name: PRELIM | PATCH | Ensure conf.d directory exists required for 5.3.3.2.x
145159
when:
146160
- ubtu22cis_rule_5_3_3_2_1 or
@@ -151,11 +165,26 @@
151165
ubtu22cis_rule_5_3_3_2_6
152166
tags: always
153167
ansible.builtin.file:
154-
path: '/etc/security/pwquality.conf.d'
155-
state: directory
168+
path: "{{ item.path }}"
169+
state: "{{ item.state }}"
156170
owner: root
157171
group: root
158172
mode: 'g-w,o-rwx'
173+
modification_time: preserve
174+
access_time: preserve
175+
register: prelim_pwquality_dummy
176+
changed_when: prelim_pwquality_dummy.diff == "absent"
177+
loop:
178+
- { path: '/etc/security/pwquality.conf.d', state: 'directory' }
179+
- { path: '/etc/security/pwquality.conf.d/cis_dummy.conf', state: 'touch' }
180+
181+
- name: "PRELIM | AUDIT | Capture pam security related files"
182+
tags: always
183+
ansible.builtin.find:
184+
paths:
185+
- /etc/security/pwquality.conf.d/
186+
patterns: '*.conf'
187+
register: prelim_pam_pwquality_confs
159188

160189
- name: PRELIM | AUDIT | Discover Interactive UID MIN and MIN from logins.def
161190
when: not discover_int_uid

tasks/section_1/cis_1.1.2.1.x.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@
128128
dest: /etc/systemd/system/tmp.mount
129129
owner: root
130130
group: root
131-
mode: "go-wx"
131+
mode: 'go-wx'
132132
notify: *mount_option_notify

tasks/section_1/cis_1.4.x.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
dest: "{{ ubtu22cis_grub_user_file }}"
1919
owner: root
2020
group: root
21-
mode: 'go-w'
21+
mode: 'go-w,u+x'
2222
notify: Grub update
2323

2424
- name: "1.4.1 | PATCH | Ensure bootloader password is set | allow unrestricted boot"

0 commit comments

Comments
 (0)