updates for audit section

Signed-off-by: Mark Bolwell <mark.bollyuk@gmail.com>
This commit is contained in:
Mark Bolwell 2024-04-15 09:29:19 +01:00
parent f83e73c1a1
commit 05fee15cb4
No known key found for this signature in database
GPG key ID: 1DE02A772D0908F9
5 changed files with 74 additions and 92 deletions

View file

@ -67,74 +67,56 @@ skip_reboot: true
# default value will change to true but wont reboot if not enabled but will error # default value will change to true but wont reboot if not enabled but will error
change_requires_reboot: false change_requires_reboot: false
########################################## ###########################################
### Goss is required on the remote host ### ### Goss is required on the remote host ###
## Refer to vars/auditd.yml for any other settings ## ### vars/auditd.yml for other settings ###
#### Basic external goss audit enablement settings ####
#### Precise details - per setting can be found at the bottom of this file ####
## Audit setup # Allow audit to setup the requirements including installing git (if option chosen and downloading and adding goss binary to system)
# Audits are carried out using Goss. This variable
# determines whether execution of the role prepares for auditing
# by installing the required binary.
setup_audit: false setup_audit: false
## Enable audits to run - this runs the audit and get the latest content # enable audits to run - this runs the audit and get the latest content
# This variable governs whether the audit using the
# separately maintained audit role using Goss
# is carried out.
run_audit: false run_audit: false
# Run heavy tests - some tests can have more impact on a system enabling these can have greater impact on a system
audit_run_heavy_tests: true
# Only run Audit do not remediate ## Only run Audit do not remediate
audit_only: false audit_only: false
# This will enable files to be copied back to control node(part of audit_only) ### As part of audit_only ###
# This will enable files to be copied back to control node in audit_only mode
fetch_audit_files: false fetch_audit_files: false
# Path to copy the files to will create dir structure(part of audit_only) # Path to copy the files to will create dir structure in audit_only mode
audit_capture_files_dir: /some/location to copy to on control node audit_capture_files_dir: /some/location to copy to on control node
#############################
## How to retrieve audit binary(Goss) # How to retrieve audit binary
# Options are 'copy' or 'download' - detailed settings at the bottom of this file # Options are copy or download - detailed settings at the bottom of this file
# - if 'copy': # you will need to access to either github or the file already dowmloaded
# - the filepath mentioned via the below 'audit_bin_copy_location' var will be used to access already downloaded Goss
# - if 'download':
# - the GitHub Goss-releases URL will be used for a fresh-download, via 'audit_bin_url' and 'audit_pkg_arch_name' vars
get_audit_binary_method: download get_audit_binary_method: download
## if get_audit_binary_method is 'copy', the following var needs to be updated for your environment ## if get_audit_binary_method - copy the following needs to be updated for your environment
## it is expected that it will be copied from somewhere accessible to the control node ## it is expected that it will be copied from somewhere accessible to the control node
## e.g copy from ansible control node to remote host ## e.g copy from ansible control node to remote host
audit_bin_copy_location: /some/accessible/path audit_bin_copy_location: /some/accessible/path
## How to retrieve the audit role # how to get audit files onto host options
# The role for auditing is maintained separately. # options are git/copy/archive/get_url other e.g. if you wish to run from already downloaded conf
# This variable specifies the method of how to get the audit role
# options are git/copy/get_url other e.g. if you wish to run from already downloaded conf
# onto the system. The options are as follows:
# - 'git': clone audit content from GitHub REPOSITORY, set up via `audit_file_git` var, and
# VERSION(e.g. branch, tag name), set up via `audit_git_version` var.
# - 'copy': copy from path as specified in variable `audit_conf_copy`.
# - 'archive': same as 'copy', only that the specified filepath needs to be unpacked.
# - 'get_url': Download from url as specified in variable `audit_files_url`
audit_content: git audit_content: git
# This variable(only used when 'audit_content' is 'copy' or 'archive') should # If using either archive, copy, get_url:
# contain the filepath with audit-content to be copied/unarchived on server: ## Note will work with .tar files - zip will require extra configuration
audit_conf_copy: "some path to copy from" ### If using get_url this is expecting github url in tar.gz format e.g.
### https://github.com/ansible-lockdown/UBUNTU22-CIS-Audit/archive/refs/heads/benchmark-v1.0.0.tar.gz
audit_conf_source: "some path or url to copy from"
# This variable(only used when 'audit_content' is 'get_url') should # Destination for the audit content to be placed on managed node
# contain the URL from where the audit-content must be downloaded on server: # note may not need full path e.g. /opt with the directory being the {{ benchmark }}-Audit directory
audit_files_url: "some url maybe s3?" audit_conf_dest: "/opt"
# Run heavy tests - some tests can have more impact on a system enabling these can have greater impact on a system # Where the audit logs are stored
audit_run_heavy_tests: true audit_log_dir: '/opt'
# Timeout for those cmds that take longer to run where timeout set ### Goss Settings ##
# This variable specifies the timeout (in ms) for audit commands that ####### END ########
# take a very long time: if a command takes too long to complete,
# it will be forcefully terminated after the specified duration.
audit_cmd_timeout: 120000
### End Goss enablements ####
# These variables correspond with the CIS rule IDs or paragraph numbers defined in # These variables correspond with the CIS rule IDs or paragraph numbers defined in
# the CIS benchmark documents. # the CIS benchmark documents.

View file

@ -5,10 +5,10 @@
changed_when: true changed_when: true
environment: environment:
AUDIT_BIN: "{{ audit_bin }}" AUDIT_BIN: "{{ audit_bin }}"
AUDIT_CONTENT_LOCATION: "{{ audit_out_dir }}" AUDIT_CONTENT_LOCATION: "{{ audit_conf_dest | default('/opt') }}"
AUDIT_FILE: goss.yml AUDIT_FILE: goss.yml
- name: Post Audit | Ensure audit files readable by users - name: Post Audit | ensure audit files readable by users
ansible.builtin.file: ansible.builtin.file:
path: "{{ item }}" path: "{{ item }}"
mode: '0644' mode: '0644'
@ -21,14 +21,14 @@
when: when:
- audit_format == "json" - audit_format == "json"
block: block:
- name: Post Audit | Capture data {{ post_audit_outfile }} - name: capture data {{ post_audit_outfile }}
ansible.builtin.shell: cat {{ post_audit_outfile }} ansible.builtin.shell: "cat {{ post_audit_outfile }}"
register: discovered_post_audit register: post_audit
changed_when: false changed_when: false
- name: Post Audit | Capture post-audit result - name: Capture post-audit result
ansible.builtin.set_fact: ansible.builtin.set_fact:
post_audit_summary: "{{ discovered_post_audit.stdout | from_json | json_query(summary) }}" post_audit_summary: "{{ post_audit.stdout | from_json | json_query(summary) }}"
vars: vars:
summary: summary."summary-line" summary: summary."summary-line"
@ -36,11 +36,11 @@
when: when:
- audit_format == "documentation" - audit_format == "documentation"
block: block:
- name: Post Audit | Capture data {{ post_audit_outfile }} - name: Post Audit | capture data {{ post_audit_outfile }}
ansible.builtin.shell: tail -2 {{ post_audit_outfile }} ansible.builtin.shell: "tail -2 {{ post_audit_outfile }}"
register: discovered_post_audit register: post_audit
changed_when: false changed_when: false
- name: Post Audit | Capture post-audit result - name: Post Audit | Capture post-audit result
ansible.builtin.set_fact: ansible.builtin.set_fact:
post_audit_summary: "{{ discovered_post_audit.stdout_lines }}" post_audit_summary: "{{ post_audit.stdout_lines }}"

View file

@ -33,23 +33,25 @@
when: when:
- audit_content == 'copy' - audit_content == 'copy'
ansible.builtin.copy: ansible.builtin.copy:
src: "{{ audit_local_copy }}" src: "{{ audit_conf_source }}"
dest: "{{ audit_conf_dest }}" dest: "{{ audit_conf_dest }}"
mode: preserve mode: preserve
- name: Pre Audit Setup | Unarchive audit content files on server - name: Pre Audit Setup | Unarchive audit content files on server
when: when:
- audit_content == 'archived' - audit_content == 'archive'
ansible.builtin.unarchive: ansible.builtin.unarchive:
src: "{{ audit_conf_copy }}" src: "{{ audit_conf_source }}"
dest: "{{ audit_conf_dir }}" dest: "{{ audit_conf_dest }}"
- name: Pre Audit Setup | Get audit content from url - name: Pre Audit Setup | Get audit content from url
when: when:
- audit_content == 'get_url' - audit_content == 'get_url'
ansible.builtin.get_url: ansible.builtin.unarchive:
url: "{{ audit_files_url }}" src: "{{ audit_conf_source }}"
dest: "{{ audit_conf_dir }}" dest: "{{ audit_conf_dest }}/{{ benchmark }}-Audit"
remote_src: "{{ ( audit_conf_source is contains ('http'))| ternary(true, false ) }}"
extra_opts: "{{ (audit_conf_source is contains ('github')) | ternary('--strip-components=1', [] ) }}"
- name: Pre Audit Setup | Check Goss is available - name: Pre Audit Setup | Check Goss is available
when: when:
@ -58,19 +60,20 @@
- name: Pre Audit Setup | Check for goss file - name: Pre Audit Setup | Check for goss file
ansible.builtin.stat: ansible.builtin.stat:
path: "{{ audit_bin }}" path: "{{ audit_bin }}"
register: discovered_goss_available register: goss_available
- name: Pre Audit Setup | If audit ensure goss is available - name: Pre Audit Setup | If audit ensure goss is available
when:
- not goss_available.stat.exists
ansible.builtin.assert: ansible.builtin.assert:
that: discovered_goss_available.stat.exists
msg: "Audit has been selected: unable to find goss binary at {{ audit_bin }}" msg: "Audit has been selected: unable to find goss binary at {{ audit_bin }}"
- name: Pre Audit Setup | Copy ansible default vars values to test audit - name: Pre Audit Setup | Copy ansible default vars values to test audit
when:
- run_audit
tags: tags:
- goss_template - goss_template
- run_audit - run_audit
when:
- run_audit
ansible.builtin.template: ansible.builtin.template:
src: ansible_vars_goss.yml.j2 src: ansible_vars_goss.yml.j2
dest: "{{ audit_vars_path }}" dest: "{{ audit_vars_path }}"
@ -81,7 +84,7 @@
changed_when: true changed_when: true
environment: environment:
AUDIT_BIN: "{{ audit_bin }}" AUDIT_BIN: "{{ audit_bin }}"
AUDIT_CONTENT_LOCATION: "{{ audit_out_dir }}" AUDIT_CONTENT_LOCATION: "{{ audit_conf_dest | default('/opt') }}"
AUDIT_FILE: goss.yml AUDIT_FILE: goss.yml
- name: Pre Audit | Capture audit data if json format - name: Pre Audit | Capture audit data if json format
@ -89,13 +92,13 @@
- audit_format == "json" - audit_format == "json"
block: block:
- name: Pre Audit | Capture data {{ pre_audit_outfile }} - name: Pre Audit | Capture data {{ pre_audit_outfile }}
ansible.builtin.shell: cat {{ pre_audit_outfile }} ansible.builtin.shell: "cat {{ pre_audit_outfile }}"
register: discovered_pre_audit register: pre_audit
changed_when: false changed_when: false
- name: Pre Audit | Capture pre-audit result - name: Pre Audit | Capture pre-audit result
ansible.builtin.set_fact: ansible.builtin.set_fact:
pre_audit_summary: "{{ discovered_pre_audit.stdout | from_json | json_query(summary) }}" pre_audit_summary: "{{ pre_audit.stdout | from_json | json_query(summary) }}"
vars: vars:
summary: summary."summary-line" summary: summary."summary-line"
@ -104,16 +107,15 @@
- audit_format == "documentation" - audit_format == "documentation"
block: block:
- name: Pre Audit | Capture data {{ pre_audit_outfile }} | documentation format - name: Pre Audit | Capture data {{ pre_audit_outfile }} | documentation format
ansible.builtin.shell: tail -2 {{ pre_audit_outfile }} ansible.builtin.shell: "tail -2 {{ pre_audit_outfile }}"
register: discovered_pre_audit register: pre_audit
changed_when: false changed_when: false
- name: Pre Audit | Capture pre-audit result | documentation format - name: Pre Audit | Capture pre-audit result | documentation format
ansible.builtin.set_fact: ansible.builtin.set_fact:
pre_audit_summary: "{{ discovered_pre_audit.stdout_lines }}" pre_audit_summary: "{{ pre_audit.stdout_lines }}"
- name: Audit_Only | Run Audit Only - name: Audit_Only | Run Audit Only
when: when:
- audit_only - audit_only
ansible.builtin.import_tasks: ansible.builtin.import_tasks: audit_only.yml
file: audit_only.yml

View file

@ -9,10 +9,6 @@
- name: "1.3.1 | PATCH | Ensure AIDE is installed | Build AIDE DB" - name: "1.3.1 | PATCH | Ensure AIDE is installed | Build AIDE DB"
ansible.builtin.shell: /usr/sbin/aide --init ansible.builtin.shell: /usr/sbin/aide --init
changed_when: false
failed_when: false
async: 45
poll: 0
args: args:
creates: /var/lib/aide/aide.db.new.gz creates: /var/lib/aide/aide.db.new.gz
when: not ansible_check_mode when: not ansible_check_mode

View file

@ -2,6 +2,9 @@
#### Audit Configuration Settings #### #### Audit Configuration Settings ####
# Timeout for those cmds that take longer to run where timeout set
audit_cmd_timeout: 120000
# if get_audit_binary_method == download change accordingly # if get_audit_binary_method == download change accordingly
audit_bin_url: "https://github.com/goss-org/goss/releases/download/{{ audit_bin_version.release }}/goss-linux-" audit_bin_url: "https://github.com/goss-org/goss/releases/download/{{ audit_bin_version.release }}/goss-linux-"
@ -9,17 +12,15 @@ audit_bin_url: "https://github.com/goss-org/goss/releases/download/{{ audit_bin_
## managed by the control audit_content ## managed by the control audit_content
# git # git
audit_file_git: "https://github.com/ansible-lockdown/{{ benchmark }}-Audit.git" audit_file_git: "https://github.com/ansible-lockdown/{{ benchmark }}-Audit.git"
audit_git_version: "benchmark_{{ benchmark_version }}" audit_git_version: "benchmark-{{ benchmark_version }}"
## Goss configuration information ## Goss configuration information
# Where the goss configs and outputs are stored # Where the goss audit configuration will be stored - NOTE benchmark-audit is expected
audit_out_dir: '/opt' audit_conf_dir: "{{ audit_conf_dest | default('/opt') }}/{{ benchmark }}-Audit"
# Where the goss audit configuration will be stored
audit_conf_dir: "{{ audit_out_dir }}/{{ benchmark }}-Audit"
# If changed these can affect other products # If changed these can affect other products
pre_audit_outfile: "{{ audit_out_dir }}/{{ ansible_facts.hostname }}-{{ benchmark }}-{{ benchmark_version }}_pre_scan_{{ ansible_facts.date_time.epoch }}.{{ audit_format }}" pre_audit_outfile: "{{ audit_log_dir }}/{{ ansible_facts.hostname }}-{{ benchmark }}-{{ benchmark_version }}_pre_scan_{{ ansible_facts.date_time.epoch }}.{{ audit_format }}"
post_audit_outfile: "{{ audit_out_dir }}/{{ ansible_facts.hostname }}-{{ benchmark }}-{{ benchmark_version }}_post_scan_{{ ansible_facts.date_time.epoch }}.{{ audit_format }}" post_audit_outfile: "{{ audit_log_dir }}/{{ ansible_facts.hostname }}-{{ benchmark }}-{{ benchmark_version }}_post_scan_{{ ansible_facts.date_time.epoch }}.{{ audit_format }}"
## The following should not need changing ## The following should not need changing
@ -33,6 +34,7 @@ audit_format: json
audit_vars_path: "{{ audit_conf_dir }}/vars/{{ ansible_facts.hostname }}.yml" audit_vars_path: "{{ audit_conf_dir }}/vars/{{ ansible_facts.hostname }}.yml"
audit_results: | audit_results: |
The pre remediation results are: {{ pre_audit_summary }}. The audit results are: {{ pre_audit_summary }}
The post remediation results are: {{ post_audit_summary }}. {% if not audit_only %}The post remediation audit results are: {{ post_audit_summary }}{% endif %}
Full breakdown can be found in {{ audit_out_dir }}
Full breakdown can be found in {{ audit_log_dir }}