Skip to content

Commit 583e16f

Browse files
authored
Merge pull request #179 from ansible-lockdown/devel
Devel to main
2 parents c91a103 + fa365a3 commit 583e16f

13 files changed

Lines changed: 250 additions & 192 deletions

.github/workflows/devel_pipeline_validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
env:
126126
ANSIBLE_HOST_KEY_CHECKING: "false"
127127
ANSIBLE_DEPRECATION_WARNINGS: "false"
128+
ANSIBLE_INJECT_FACT_VARS: "false"
128129

129130
# Remove test system - User secrets to keep if necessary
130131

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repos:
3636
args: [ '--baseline', '.config/.secrets.baseline' ]
3737

3838
- repo: https://github.com/gitleaks/gitleaks
39-
rev: v8.18.0
39+
rev: v8.18.1
4040
hooks:
4141
- id: gitleaks
4242
args: ['--baseline-path', '.config/.gitleaks-report.json']
@@ -61,6 +61,6 @@ repos:
6161
- ansible-core>=2.10.1
6262

6363
- repo: https://github.com/adrienverge/yamllint.git
64-
rev: v1.32.0 # or higher tag
64+
rev: v1.33.0 # or higher tag
6565
hooks:
6666
- id: yamllint

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Based on CIS V1.0.0
44

5+
### 1.0.8
6+
7+
- updated goss binary to 0.4.4
8+
- moved majority of audit variables to vars/audit.yml
9+
- new function to enable audit_only using remediation
10+
- removed some dupes in audit config
11+
512
### 1.0.7
613

714
Huge thanks to the discord community

defaults/main.yml

Lines changed: 36 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -52,48 +52,53 @@ ubtu22cis_uses_root: false
5252
### Settings for associated Audit role using Goss
5353
###
5454

55-
# Note that there are also variable regarding the retrieval
56-
# and configuration of Goss and the audit role at the end
57-
# of this file.
58-
59-
## Audit setup
60-
# Audits are carried out using Goss. This variable
61-
# determines whether execution of the role prepares for auditing
62-
# by installing the required binary.
55+
##########################################
56+
### Goss is required on the remote host ###
57+
## Refer to vars/auditd.yml for any other settings ##
58+
59+
# Allow audit to setup the requirements including installing git (if option chosen and downloading and adding goss binary to system)
6360
setup_audit: false
64-
## How to retrieve audit binary
65-
# Options are copy or download, using either the path
66-
# provided in variable `audit_conf_copy` for copying or
67-
# the url given in variable `audit_files_url` for downloading.
61+
62+
# enable audits to run - this runs the audit and get the latest content
63+
run_audit: false
64+
65+
# Only run Audit do not remediate
66+
audit_only: false
67+
# As part of audit_only
68+
# This will enable files to be copied back to control node
69+
fetch_audit_files: false
70+
# Path to copy the files to will create dir structure
71+
audit_capture_files_dir: /some/location to copy to on control node
72+
73+
# How to retrieve audit binary
74+
# Options are copy or download - detailed settings at the bottom of this file
75+
# you will need to access to either github or the file already dowmloaded
6876
get_audit_binary_method: download
6977

70-
## How to retrieve the audit role
71-
# The role for auditing is maintained separately.
72-
# This variable specifies the method of how to get the audit role
73-
# onto the system. The options are as follows:
74-
# - git: clone from git repository as specified in variable `audit_file_git` in
75-
# the version specified by variable `audit_git_version`
76-
# - copy: copy from path as specified in variable `audit_conf_copy`
77-
# - download: Download from url as specified in variable `audit_files_url`
78+
## if get_audit_binary_method - copy the following needs to be updated for your environment
79+
## it is expected that it will be copied from somewhere accessible to the control node
80+
## e.g copy from ansible control node to remote host
81+
audit_bin_copy_location: /some/accessible/path
82+
83+
# how to get audit files onto host options
84+
# options are git/copy/get_url other e.g. if you wish to run from already downloaded conf
7885
audit_content: git
7986

80-
## Enable audits to run
81-
# This variable governs whether the audit using the
82-
# separately maintained audit role using Goss
83-
# is carried out.
84-
run_audit: false
87+
# archive or copy:
88+
audit_conf_copy: "some path to copy from"
89+
90+
# get_url:
91+
audit_files_url: "some url maybe s3?"
8592

86-
## Resource-intensive Tests
87-
# This variable governs whether resource-intensive audit tests are carried out
93+
# Run heavy tests - some tests can have more impact on a system enabling these can have greater impact on a system
8894
audit_run_heavy_tests: true
95+
8996
# This variable specifies the timeout (in ms) for audit commands that
9097
# take a very long time: if a command takes too long to complete,
9198
# it will be forcefully terminated after the specified duration.
92-
audit_cmd_timeout: 60000
99+
audit_cmd_timeout: 120000
93100

94-
###
95-
### End Audit Settings for associcated Audit role using Goss
96-
###
101+
### End Goss enablements ####
97102

98103
## Running role under chroot
99104
# Tweak role to run in a chroot, such as in a kickstart %post script.
@@ -1058,56 +1063,3 @@ ubtu22cis_sgid_adjust: false
10581063
# permissions on dot files.
10591064
# Possible values are `true` and `false`.
10601065
ubtu22cis_dotperm_ansiblemanaged: true
1061-
1062-
##
1063-
## Audit Configuration Settings
1064-
##
1065-
1066-
# The settings below configure the retrieval and usage of the
1067-
# Goss-based audit role associated with this role, and the Goss-tool
1068-
# itself.
1069-
1070-
## Audit binary settings
1071-
audit_bin_version:
1072-
release: v0.4.0
1073-
checksum: 'sha256:9cb37863d3d25e2af80cb5cf55198c0c115b2477724153ba9afd0a2e544cb46e'
1074-
audit_bin_path: /usr/local/bin/
1075-
audit_bin: "{{ audit_bin_path }}goss"
1076-
audit_format: json
1077-
1078-
# if get_audit_binary_method == download change accordingly
1079-
audit_bin_url: "https://github.com/goss-org/goss/releases/download/{{ audit_bin_version.release }}/goss-linux-amd64"
1080-
1081-
# if get_audit_binary_method - copy the following needs to be updated for your environment
1082-
# it is expected that it will be copied from somewhere accessible to the control node
1083-
# e.g copy from ansible control node to remote host
1084-
audit_bin_copy_location: /some/accessible/path
1085-
1086-
## Goss Audit Benchmark file
1087-
# managed by the control audit_content
1088-
# git
1089-
audit_file_git: "https://github.com/ansible-lockdown/{{ benchmark }}-Audit.git"
1090-
audit_git_version: "benchmark-{{ benchmark_version }}"
1091-
1092-
# archive or copy:
1093-
audit_conf_copy: "some path to copy from"
1094-
1095-
# get_url:
1096-
audit_files_url: "some url maybe s3?"
1097-
1098-
## Goss configuration information
1099-
# Where the goss configs and outputs are stored
1100-
audit_out_dir: '/opt'
1101-
# Where the goss audit configuration will be stored
1102-
audit_conf_dir: "{{ audit_out_dir }}/{{ benchmark }}-Audit"
1103-
1104-
# If changed these can affect other products
1105-
pre_audit_outfile: "{{ audit_out_dir }}/{{ ansible_facts.hostname }}-{{ benchmark }}-{{ benchmark_version }}_pre_scan_{{ ansible_facts.date_time.epoch }}.{{ audit_format }}"
1106-
post_audit_outfile: "{{ audit_out_dir }}/{{ ansible_facts.hostname }}-{{ benchmark }}-{{ benchmark_version }}_post_scan_{{ ansible_facts.date_time.epoch }}.{{ audit_format }}"
1107-
1108-
## The following should not need changing
1109-
audit_vars_path: "{{ audit_conf_dir }}/vars/{{ ansible_facts.hostname }}.yml"
1110-
audit_results: |
1111-
The pre remediation results are: {{ pre_audit_summary }}.
1112-
The post remediation results are: {{ post_audit_summary }}.
1113-
Full breakdown can be found in {{ audit_out_dir }}

tasks/LE_audit_setup.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
---
22

3+
- name: Pre Audit Setup | Set audit package name
4+
block:
5+
- name: Pre Audit Setup | Set audit package name | 64bit
6+
ansible.builtin.set_fact:
7+
audit_pkg_arch_name: AMD64
8+
when: ansible_facts.machine == "x86_64"
9+
10+
- name: Pre Audit Setup | Set audit package name | ARM64
11+
ansible.builtin.set_fact:
12+
audit_pkg_arch_name: ARM64
13+
when: ansible_facts.machine == "arm64"
14+
315
- name: Pre Audit Setup | Download audit binary
416
ansible.builtin.get_url:
5-
url: "{{ audit_bin_url }}"
17+
url: "{{ audit_bin_url }}{{ audit_pkg_arch_name }}"
618
dest: "{{ audit_bin }}"
719
owner: root
820
group: root
9-
checksum: "{{ audit_bin_version.checksum }}"
21+
checksum: "{{ audit_bin_version[audit_pkg_arch_name + '_checksum'] }}"
1022
mode: '0555'
1123
when:
1224
- get_audit_binary_method == 'download'
1325

14-
- name: Pre Audit Setup | copy audit binary
26+
- name: Pre Audit Setup | Copy audit binary
1527
ansible.builtin.copy:
1628
src: "{{ audit_bin_copy_location }}"
1729
dest: "{{ audit_bin }}"
30+
mode: '0555'
1831
owner: root
1932
group: root
20-
mode: '0555'
2133
when:
2234
- get_audit_binary_method == 'copy'

tasks/audit_only.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
3+
- name: Audit_Only | Create local Directories for hosts
4+
ansible.builtin.file:
5+
mode: '0755'
6+
path: "{{ audit_capture_files_dir }}/{{ inventory_hostname }}"
7+
recurse: true
8+
state: directory
9+
when: fetch_audit_files
10+
delegate_to: localhost
11+
become: false
12+
13+
- name: Audit_only | Get audits from systems and put in group dir
14+
ansible.builtin.fetch:
15+
dest: "{{ audit_capture_files_dir }}/{{ inventory_hostname }}/"
16+
flat: true
17+
mode: '0644'
18+
src: "{{ pre_audit_outfile }}"
19+
when: fetch_audit_files
20+
21+
- name: Audit_only | Show Audit Summary
22+
when:
23+
- audit_only
24+
ansible.builtin.debug:
25+
msg: "The Audit results are: {{ pre_audit_summary }}."
26+
27+
- name: Audit_only | Stop Playbook Audit Only selected
28+
when:
29+
- audit_only
30+
ansible.builtin.meta: end_play

tasks/main.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
---
22

3-
- name: Gather distribution info
4-
# we need:
5-
# - hardware for ansible_facts.mounts
6-
# - platform for ansible_architecture (ansible internal)
7-
# - virtual for ansible_facts.virtualization_type
8-
ansible.builtin.setup:
9-
gather_subset: distribution,hardware,platform,virtual,!all,!min
10-
when:
11-
- ansible_facts.distribution is not defined
12-
tags:
13-
- always
14-
153
- name: Check OS version and family
164
ansible.builtin.fail:
175
msg: "This role can only be run against Ubuntu 22. {{ ansible_facts.distribution }} {{ ansible_facts.distribution_major_version }} is not supported."
@@ -131,11 +119,20 @@
131119
tags:
132120
- always
133121

134-
- name: Run pre-remediation audit
135-
ansible.builtin.import_tasks:
136-
file: pre_remediation_audit.yml
122+
- name: Include audit specific variables
123+
ansible.builtin.include_vars: audit.yml
137124
when:
125+
- run_audit or audit_only
126+
- setup_audit
127+
tags:
128+
- setup_audit
138129
- run_audit
130+
131+
- name: Include pre-remediation audit tasks
132+
ansible.builtin.import_tasks: pre_remediation_audit.yml
133+
when:
134+
- run_audit or audit_only
135+
- setup_audit
139136
tags:
140137
- run_audit
141138

tasks/post_remediation_audit.yml

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,46 @@
11
---
22

3+
- name: Post Audit | Run post_remediation {{ benchmark }} audit
4+
ansible.builtin.shell: "{{ audit_conf_dir }}/run_audit.sh -v {{ audit_vars_path }} -o {{ post_audit_outfile }} -g {{ group_names }}"
5+
changed_when: true
6+
environment:
7+
AUDIT_BIN: "{{ audit_bin }}"
8+
AUDIT_CONTENT_LOCATION: "{{ audit_out_dir }}"
9+
AUDIT_FILE: goss.yml
10+
11+
- name: Post Audit | ensure audit files readable by users
12+
ansible.builtin.file:
13+
path: "{{ item }}"
14+
mode: '0644'
15+
state: file
16+
loop:
17+
- "{{ post_audit_outfile }}"
18+
- "{{ pre_audit_outfile }}"
19+
320
- name: Post Audit | Capture audit data if json format
21+
when:
22+
- audit_format == "json"
423
block:
5-
6-
- name: "Post Audit | Run post_remediation {{ benchmark }} audit"
7-
ansible.builtin.shell: "{{ audit_conf_dir }}/run_audit.sh -v {{ audit_vars_path }} -o {{ post_audit_outfile }} -g {{ group_names }}"
8-
changed_when: true
9-
environment:
10-
AUDIT_BIN: "{{ audit_bin }}"
11-
AUDIT_CONTENT_LOCATION: "{{ audit_out_dir }}"
12-
AUDIT_FILE: "goss.yml"
13-
14-
- name: "Capture data {{ post_audit_outfile }}"
15-
ansible.builtin.shell: "cat {{ post_audit_outfile }}"
24+
- name: capture data {{ post_audit_outfile }}
25+
ansible.builtin.shell: cat {{ post_audit_outfile }}
1626
register: post_audit
1727
changed_when: false
1828

1929
- name: Capture post-audit result
2030
ansible.builtin.set_fact:
2131
post_audit_summary: "{{ post_audit.stdout | from_json | json_query(summary) }}"
2232
vars:
23-
summary: 'summary."summary-line"'
24-
when:
25-
- audit_format == "json"
33+
summary: summary."summary-line"
2634

2735
- name: Post Audit | Capture audit data if documentation format
36+
when:
37+
- audit_format == "documentation"
2838
block:
29-
30-
- name: "Post Audit | Run post_remediation {{ benchmark }} audit"
31-
ansible.builtin.shell: "{{ audit_conf_dir }}/run_audit.sh -v {{ audit_vars_path }} -o {{ post_audit_outfile }} -g {{ group_names }} -f documentation"
32-
changed_when: true
33-
environment:
34-
AUDIT_BIN: "{{ audit_bin }}"
35-
AUDIT_CONTENT_LOCATION: "{{ audit_out_dir }}"
36-
AUDIT_FILE: "goss.yml"
37-
38-
- name: "Post Audit | Capture data {{ post_audit_outfile }}"
39-
ansible.builtin.shell: "tail -2 {{ post_audit_outfile }}"
39+
- name: Post Audit | capture data {{ post_audit_outfile }}
40+
ansible.builtin.shell: tail -2 {{ post_audit_outfile }}
4041
register: post_audit
4142
changed_when: false
4243

4344
- name: Post Audit | Capture post-audit result
4445
ansible.builtin.set_fact:
4546
post_audit_summary: "{{ post_audit.stdout_lines }}"
46-
when:
47-
- audit_format == "documentation"
48-
49-
- name: Post Audit | Ensure audit files readable by users
50-
ansible.builtin.file:
51-
path: "{{ item }}"
52-
mode: '0644'
53-
state: file
54-
loop:
55-
- "{{ post_audit_outfile }}"
56-
- "{{ pre_audit_outfile }}"

0 commit comments

Comments
 (0)