Install and configure Audita
This commit is contained in:
6
tests/converge.yml
Normal file
6
tests/converge.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: localhost
|
||||
gather_facts: true
|
||||
roles:
|
||||
- role: ansible-role-audita
|
||||
41
tests/integration
Executable file
41
tests/integration
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
repository_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
||||
workspace_venv="$repository_root/../.venv"
|
||||
test_tmp=$(mktemp -d)
|
||||
chmod 0700 "$test_tmp"
|
||||
|
||||
export ANSIBLE_COLLECTIONS_PATH="$test_tmp/collections"
|
||||
export ANSIBLE_ROLES_PATH="$(dirname "$repository_root")"
|
||||
|
||||
inventory="$repository_root/tests/inventory"
|
||||
converge="$repository_root/tests/converge.yml"
|
||||
verify="$repository_root/tests/verify.yml"
|
||||
ansible_playbook="$workspace_venv/bin/ansible-playbook"
|
||||
default_commit=a84941d68168a1ed9ea7423b6477ae8218be73f9
|
||||
|
||||
cleanup() {
|
||||
rm -rf -- "$test_tmp"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
require_clean_recap() {
|
||||
grep -Eq 'changed=0 .*failed=0' "$1"
|
||||
}
|
||||
|
||||
cd "$repository_root"
|
||||
"$workspace_venv/bin/ansible-galaxy" collection install \
|
||||
-r collections/requirements.yml \
|
||||
-p "$ANSIBLE_COLLECTIONS_PATH"
|
||||
"$ansible_playbook" -i "$inventory" --syntax-check "$converge"
|
||||
"$workspace_venv/bin/ansible-lint" "$converge" "$verify"
|
||||
|
||||
baseline_log="$test_tmp/baseline.log"
|
||||
"$ansible_playbook" -i "$inventory" "$converge" | tee "$baseline_log"
|
||||
"$ansible_playbook" -i "$inventory" \
|
||||
-e "audita_expected_commit=$default_commit" \
|
||||
"$verify"
|
||||
baseline_repeat_log="$test_tmp/baseline-repeat.log"
|
||||
"$ansible_playbook" -i "$inventory" "$converge" | tee "$baseline_repeat_log"
|
||||
require_clean_recap "$baseline_repeat_log"
|
||||
1
tests/inventory
Normal file
1
tests/inventory
Normal file
@@ -0,0 +1 @@
|
||||
localhost ansible_connection=local
|
||||
85
tests/verify.yml
Normal file
85
tests/verify.yml
Normal file
@@ -0,0 +1,85 @@
|
||||
---
|
||||
- name: Verify Audita installation
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Confirm selected source commit
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- git
|
||||
- -C
|
||||
- /usr/local/src/audita
|
||||
- rev-parse
|
||||
- HEAD
|
||||
register: audita_commit
|
||||
changed_when: false
|
||||
|
||||
- name: Check selected source commit
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- audita_commit.stdout == audita_expected_commit
|
||||
|
||||
- name: Inspect source ownership
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- find
|
||||
- /usr/local/src/audita
|
||||
- -not
|
||||
- -user
|
||||
- root
|
||||
- -o
|
||||
- -not
|
||||
- -group
|
||||
- root
|
||||
register: audita_source_ownership
|
||||
changed_when: false
|
||||
|
||||
- name: Check source ownership
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- audita_source_ownership.stdout == ""
|
||||
|
||||
- name: Inspect binary metadata
|
||||
become: true
|
||||
ansible.builtin.stat:
|
||||
path: /usr/local/bin/audita
|
||||
register: audita_binary_metadata
|
||||
|
||||
- name: Check binary metadata
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- audita_binary_metadata.stat.pw_name == "root"
|
||||
- audita_binary_metadata.stat.gr_name == "root"
|
||||
- audita_binary_metadata.stat.mode == "0755"
|
||||
- audita_binary_metadata.stat.executable
|
||||
|
||||
- name: Inspect configuration metadata
|
||||
become: true
|
||||
ansible.builtin.stat:
|
||||
path: /usr/local/etc/audita/config.yml
|
||||
register: audita_config_metadata
|
||||
|
||||
- name: Check configuration metadata
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- audita_config_metadata.stat.pw_name == "root"
|
||||
- audita_config_metadata.stat.gr_name == "root"
|
||||
- audita_config_metadata.stat.mode == "0644"
|
||||
|
||||
- name: Validate Audita configuration
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/local/bin/audita
|
||||
- config
|
||||
- validate
|
||||
- --config
|
||||
- /usr/local/etc/audita/config.yml
|
||||
register: audita_config_validation
|
||||
changed_when: false
|
||||
|
||||
- name: Check configuration validation output
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- audita_config_validation.stdout == "config is valid"
|
||||
Reference in New Issue
Block a user