Skip to content

Commit 8518a8a

Browse files
committed
feat(aide): add role and playbook
1 parent b5b82f7 commit 8518a8a

File tree

9 files changed

+537
-0
lines changed

9 files changed

+537
-0
lines changed

playbooks/aide.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- name: 'Playbook linuxfabrik.lfops.aide'
2+
hosts:
3+
- 'aide'
4+
5+
pre_tasks:
6+
- ansible.builtin.import_role:
7+
name: 'shared'
8+
tasks_from: 'log-start.yml'
9+
tags:
10+
- 'always'
11+
12+
13+
roles:
14+
15+
- role: 'linuxfabrik.lfops.aide'
16+
17+
18+
post_tasks:
19+
- ansible.builtin.import_role:
20+
name: 'shared'
21+
tasks_from: 'log-end.yml'
22+
tags:
23+
- 'always'

playbooks/all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- import_playbook: 'acme_sh.yml'
2+
- import_playbook: 'aide.yml'
23
- import_playbook: 'alternatives.yml'
34
- import_playbook: 'ansible_init.yml'
45
- import_playbook: 'apache_httpd.yml'

roles/aide/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Ansible Role linuxfabrik.lfops.aide
2+
3+
This role ensures that AIDE is installed, configured, and scheduled for regular filesystem integrity checks.
4+
5+
* The initial AIDE database is created only if `/var/lib/aide/aide.db.gz` does not already exist.
6+
7+
8+
## Tags
9+
10+
| Tag | What it does | Reload / Restart |
11+
| --- | ------------ | ---------------- |
12+
| `aide` | Runs all tasks of the role | - |
13+
| `aide:configure` | Deploys the `/etc/aide.conf` configuration file | - |
14+
| `aide:install` | Installs the AIDE package and initializes the AIDE database if it does not exist yet | - |
15+
| `aide:update_db` | Rebuilds the AIDE database; Only runs if called explicitly | - |
16+
| `aide:state` | Deploys and enables the `aide-check.service` and `aide-check.timer` systemd units | Reloads systemd daemon if unit files changed |
17+
18+
19+
## Optional Role Variables
20+
21+
| Variable | Description | Default Value |
22+
| -------- | ----------- | ------------- |
23+
| `aide__check_time_on_calendar` | Specifies at what time of the day the aide check runs. Have a look at [systemd.time(7)](https://www.freedesktop.org/software/systemd/man/systemd.time.html) for the format. | `'05:00:00'` |
24+
25+
Example:
26+
```yaml
27+
# optional
28+
aide__check_time_on_calendar: '03:00:00' #3 AM
29+
```
30+
31+
32+
## License
33+
34+
[The Unlicense](https://unlicense.org/)
35+
36+
37+
## Author Information
38+
39+
[Linuxfabrik GmbH, Zurich](https://www.linuxfabrik.ch)

roles/aide/defaults/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
aide__check_time_on_calendar: '05:00:00'
2+
3+
#vars for aide.conf
4+
aide__include_rules:
5+
- '/srv CONTENT_EX' # Extended content + file type + access.
6+
- '/opt/venv CONTENT' # Content + file type.
7+
8+
#for excluding paths prefixing path with ! is necessary
9+
aide__exclude_rules:
10+
- '!/srv/app/tmp'
11+
- '!/srv/app/cache'

roles/aide/handlers/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- name: 'aide: init db'
2+
ansible.builtin.service:
3+
name:
4+
5+
- name: 'aide: enable aidecheck.service'
6+
ansible.builtin.service:
7+
name: 'aidecheck.service'

roles/aide/tasks/main.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# CIS_Rocky_Linux_9_Benchmark_v2.0.0
2+
- block:
3+
4+
- name: '6.1.1 Ensure AIDE is installed'
5+
ansible.builtin.package:
6+
name:
7+
- 'aide'
8+
state: 'present'
9+
10+
- name: 'Initialize AIDE database'
11+
ansible.builtin.command: 'aide --init --before "database_out=file:/var/lib/aide/aide.db.gz"'
12+
args:
13+
creates: '/var/lib/aide/aide.db.gz'
14+
15+
tags:
16+
- 'aide'
17+
- 'aide:install'
18+
19+
20+
# CIS_Rocky_Linux_9_Benchmark_v2.0.0
21+
- block:
22+
23+
- name: '6.1.3 Ensure cryptographic mechanisms are used to protect the integrity of audit tools'
24+
ansible.builtin.template:
25+
backup: true
26+
src: 'etc/aide.conf.j2'
27+
dest: '/etc/aide.conf'
28+
owner: 'root'
29+
group: 'root'
30+
mode: 0o644
31+
32+
tags:
33+
- 'aide'
34+
- 'aide:configure'
35+
36+
37+
# CIS_Rocky_Linux_9_Benchmark_v2.0.0
38+
- block:
39+
40+
- name: 'Update AIDE database'
41+
ansible.builtin.command: "aide --init --before 'database_out=file:/var/lib/aide/aide.db.gz'"
42+
43+
tags:
44+
- 'never'
45+
- 'aide:update_db'
46+
47+
48+
# 6.1.2 Ensure filesystem integrity is regularly checked
49+
# CIS_Rocky_Linux_9_Benchmark_v2.0.0
50+
- block:
51+
52+
- name: 'Create /etc/systemd/system/aide-check.service'
53+
ansible.builtin.template:
54+
src: 'etc/systemd/system/aide-check.service.j2'
55+
dest: '/etc/systemd/system/aide-check.service'
56+
owner: 'root'
57+
group: 'root'
58+
mode: 0o644
59+
register: '__aide__service_unit_result'
60+
61+
- name: 'Create /etc/systemd/system/aide-check.timer'
62+
ansible.builtin.template:
63+
src: 'etc/systemd/system/aide-check.timer.j2'
64+
dest: '/etc/systemd/system/aide-check.timer'
65+
owner: 'root'
66+
group: 'root'
67+
mode: 0o644
68+
register: '__aide__timer_unit_result'
69+
70+
- name: 'Reload systemd'
71+
ansible.builtin.systemd:
72+
daemon_reload: true
73+
when:
74+
- '__aide__service_unit_result is changed or __aide__timer_unit_result is changed'
75+
76+
- name: 'Enable aide-check.service'
77+
ansible.builtin.systemd:
78+
name: 'aide-check.service'
79+
enabled: true
80+
81+
- name: 'Enable aide-check.timer'
82+
ansible.builtin.systemd:
83+
name: 'aide-check.timer'
84+
state: 'started'
85+
enabled: true
86+
87+
tags:
88+
- 'aide'
89+
- 'aide:state'

0 commit comments

Comments
 (0)