Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions playbooks/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
- import_playbook: 'repo_remi.yml'
- import_playbook: 'repo_rpmfusion.yml'
- import_playbook: 'repo_sury.yml'
- import_playbook: 'rl9_cis.yml
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- import_playbook: 'rl9_cis.yml
- import_playbook: 'rl9_cis.yml'

- import_playbook: 'rsyslog.yml'
- import_playbook: 'selinux.yml'
- import_playbook: 'setup_basic.yml'
Expand Down
22 changes: 22 additions & 0 deletions playbooks/rl9_cis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- name: 'Playbook linuxfabrik.lfops.rl9_cis'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would like to call the playbook for cis differently (stig_cis_rocky9_v2_0_0), see https://github.com/Linuxfabrik/lfops/pull/206/changes#diff-dc630449c0998eae820ac4f10fb3ca9214dcd5a27f290ec074c2fe1f777559b8.

for now, rename this playbook to aide please. every role should have its own playbook

hosts:
- 'lfops_rl9_cis'

pre_tasks:
- ansible.builtin.import_role:
name: 'shared'
tasks_from: 'log-start.yml'
tags:
- 'always'


roles:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please include a newline after roles (same as the other playbooks do):

Suggested change
roles:
roles:

- role: 'linuxfabrik.lfops.aide'


post_tasks:
- ansible.builtin.import_role:
name: 'shared'
tasks_from: 'log-end.yml'
tags:
- 'always'
2 changes: 2 additions & 0 deletions roles/acme_sh/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

- name: 'Deploy /etc/systemd/system/acme-sh.service'
ansible.builtin.template:
backup: true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated changes, undo these

src: 'etc/systemd/system/acme-sh.service.j2'
dest: '/etc/systemd/system/acme-sh.service'
owner: 'root'
Expand All @@ -37,6 +38,7 @@

- name: 'Deploy /etc/systemd/system/acme-sh.timer'
ansible.builtin.template:
backup: true
src: 'etc/systemd/system/acme-sh.timer.j2'
dest: '/etc/systemd/system/acme-sh.timer'
owner: 'root'
Expand Down
46 changes: 46 additions & 0 deletions roles/aide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Ansible Role linuxfabrik.lfops.aide

This role ensures that AIDE is installed, configured, and scheduled for regular filesystem integrity checks.

* The initial AIDE database is created only if `/var/lib/aide/aide.db.gz` does not already exist.


## Tags

| Tag | What it does | Reload / Restart |
| --- | ------------ | ---------------- |
| `aide` | Runs all tasks of the role | - |
| `aide:configure` | Deploys the `/etc/aide.conf` configuration file | - |
| `aide:install` | Installs the AIDE package and initializes the AIDE database if it does not exist yet | - |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this tag

| `aide:update_db` | Rebuilds the AIDE database; Only runs if called explicitly | - |
| `aide:state` | Deploys and enables the `aide-check.service` and `aide-check.timer` systemd units | Reloads systemd daemon if unit files changed |


## Optional Role Variables

| Variable | Description | Default Value |
| -------- | ----------- | ------------- |
| `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'` |
| `aide__include_rules` | List of paths to monitor with their AIDE rule group. | `['/srv CONTENT_EX', '/opt/venv CONTENT']` |
| `aide__exclude_rules` | List of paths to exclude from monitoring. | `['/srv/app/tmp', '/srv/app/cache']` |
Comment on lines +23 to +25
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please sort them alphabetically


Example:
```yaml
# optional
aide__check_time_on_calendar: '03:00:00'
aide__include_rules:
- '/etc CONTENT_EX' # Extended content + file type + access
- '/srv/app/node_modules CONTENT' # Content + file type
aide__exclude_rules:
- '/var/log'
```


## License

[The Unlicense](https://unlicense.org/)


## Author Information

[Linuxfabrik GmbH, Zurich](https://www.linuxfabrik.ch)
10 changes: 10 additions & 0 deletions roles/aide/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
aide__check_time_on_calendar: '05:00:00' #5 AM
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally don't add comments that are "user documentation" in the defaults file - comments for the developer are fine. these comments should be contained in the README (either in the table or in the examples section)


#vars for aide.conf
aide__include_rules:
- '/srv CONTENT_EX' # Extended content + file type + access.
- '/opt/venv CONTENT' # Content + file type.

aide__exclude_rules:
- '/srv/app/tmp'
- '/srv/app/cache'
Comment on lines +4 to +10
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do these default values come from?

7 changes: 7 additions & 0 deletions roles/aide/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: 'aide: init db'
ansible.builtin.service:
name:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something is missing here ;)


- name: 'aide: enable aidecheck.service'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabling a service shouldn't be a handler (it is also never used)

ansible.builtin.service:
name: 'aidecheck.service'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please configure your editor to do the end of file correctly (consistent with our other files)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be aide-check

91 changes: 91 additions & 0 deletions roles/aide/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# CIS_Rocky_Linux_9_Benchmark_v2.0.0
- block:

- name: '6.1.1 Ensure AIDE is installed'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep the names unrelated to cis (since this could also be used without any stig, or for a different stig)

Suggested change
- name: '6.1.1 Ensure AIDE is installed'
- name: 'install aide'

ansible.builtin.package:
name:
- 'aide'
state: 'present'

- name: 'Initialize AIDE database'
ansible.builtin.command: 'aide --init --before "database_out=file:/var/lib/aide/aide.db.gz"'
args:
creates: '/var/lib/aide/aide.db.gz'

tags:
- 'aide'
- 'aide:install'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not use :install tags, since there is no real use case for them



# CIS_Rocky_Linux_9_Benchmark_v2.0.0
- block:

- name: '6.1.3 Ensure cryptographic mechanisms are used to protect the integrity of audit tools'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use CIS names in the task names - the roles should be generic

ansible.builtin.template:
backup: true
src: 'etc/aide.conf.j2'
dest: '/etc/aide.conf'
owner: 'root'
group: 'root'
mode: 0o644

tags:
- 'aide'
- 'aide:configure'


# CIS_Rocky_Linux_9_Benchmark_v2.0.0
- block:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would move this whole block to the end of the file, for cleaner separation


- name: 'Update AIDE database'
ansible.builtin.command: "aide --init --before 'database_out=file:/var/lib/aide/aide.db.gz'"
changed_when: "'AIDE initialized database at' in aide__dbupdate_result.stdout"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use [] notation for accessing subkeys

register: 'aide__dbupdate_result'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the __ prefix for internal variables (variables that are only used in the role and are not user facing)


tags:
- 'never'
- 'aide:update_db'


# 6.1.2 Ensure filesystem integrity is regularly checked
# CIS_Rocky_Linux_9_Benchmark_v2.0.0
- block:

- name: 'Create /etc/systemd/system/aide-check.service'
ansible.builtin.template:
src: 'etc/systemd/system/aide-check.service.j2'
dest: '/etc/systemd/system/aide-check.service'
owner: 'root'
group: 'root'
mode: 0o644
register: '__aide__service_unit_result'

- name: 'Create /etc/systemd/system/aide-check.timer'
ansible.builtin.template:
src: 'etc/systemd/system/aide-check.timer.j2'
dest: '/etc/systemd/system/aide-check.timer'
owner: 'root'
group: 'root'
mode: 0o644
register: '__aide__timer_unit_result'

- name: 'Reload systemd'
ansible.builtin.systemd:
daemon_reload: true
when:
- '__aide__service_unit_result is changed or __aide__timer_unit_result is changed'

- name: 'Enable aide-check.service'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to enable the service?

ansible.builtin.systemd:
name: 'aide-check.service'
enabled: true

- name: 'Enable aide-check.timer'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: 'Enable aide-check.timer'
- name: 'systemctl enable --now aide-check.timer'

ansible.builtin.systemd:
name: 'aide-check.timer'
state: 'started'
enabled: true

tags:
- 'aide'
- 'aide:state'
Loading