Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* **role:lynis**: The daily audit no longer empties the AIDE report on RHEL 8, which made the aide-logfile monitoring plugin warn every morning until the next AIDE check.
* **role:aide**: The check no longer reports renewed certificates in `/etc/pki/tls/certs` and `/etc/ssl/certs`, such as those of acme.sh every 60 days, while their permissions, the private keys and the trust bundles stay fully checked.
* **role:grav, playbook:setup_grav**: OPcache no longer fills up with recompiled copies of Grav's file list caches and no longer throws away its whole cache every few days.
* **role:repo_epel**: On Rocky 10 and RHEL 10, EPEL follows the minor release of the host, so the daily system update no longer fails on EPEL packages built for a RHEL minor release the host does not have yet.
* **role:mariadb_server**: With `skip_name_resolve`, the `proxies_priv` warning in the MariaDB error log also goes away on servers that carry the entry for `root` instead of `mysql`.
Expand Down
21 changes: 21 additions & 0 deletions extensions/molecule/aide/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@
mode: 0o644


# Two certificates that the database has to contain from the start, so that verify.yml can renew
# one of them, which the default rule '<certificate directory>/[^/]+\.crt$ PERMS' does not
# report, and change the mode of the other, which it does. The content is no real certificate,
# aide does not parse it.
- name: 'Deploy the probe certificates'
hosts: 'systems_under_test'

tasks:

- name: 'Deploy the probe certificates'
ansible.builtin.copy:
content: 'lfops-molecule'
dest: '{{ (ansible_facts["os_family"] == "RedHat") | ternary("/etc/pki/tls/certs", "/etc/ssl/certs") }}/{{ item }}'
owner: 'root'
group: 'root'
mode: 0o644
loop:
- 'lfops-molecule.crt'
- 'lfops-molecule-chain.crt'


# A file on the EFI system partition that the database has to contain from the start, so that
# verify.yml can show that the default rule '/boot/efi DATAONLY' ignores the inode numbers vfat
# hands out anew, but still reports a changed content. No owner, group or mode: vfat has none
Expand Down
78 changes: 76 additions & 2 deletions extensions/molecule/aide/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
# keyboxd or a new LVM metadata archive, while a new file next to the sockets is. A content
# change of /root/.lfops-molecule is reported, which only its own rule does, not the default
# '/root/\..* PERMS' of the same directory, and so is a content change of
# /boot/efi/lfops-molecule. This only works if the rules and the raw part from the inventory are
# in effect, since /srv is not monitored otherwise and /opt is by default.
# /boot/efi/lfops-molecule. A certificate renewed in place is not reported, while a certificate
# with a changed mode and a changed trust bundle in the same directory are. This only works if
# the rules and the raw part from the inventory are in effect, since /srv is not monitored
# otherwise and /opt is by default.
# In between, the role is run again twice, each time after a change it has to revert, to
# prove that its handler leaves the database alone in both cases where re-baselining would
# accept unvetted changes: a database found without the role's check unit, and a last check
Expand Down Expand Up @@ -379,6 +381,47 @@
when:
- '__molecule__efi_fstype_result["stdout"] == "vfat"'

- name: 'Set the paths of the certificate directory and the trust bundle'
ansible.builtin.set_fact:
__molecule__aide_cert_dir: '{{ (ansible_facts["os_family"] == "RedHat") | ternary("/etc/pki/tls/certs", "/etc/ssl/certs") }}'
__molecule__aide_trust_bundle: '{{ (ansible_facts["os_family"] == "RedHat") | ternary("/etc/pki/tls/certs/ca-bundle.crt", "/etc/ssl/certs/ca-certificates.crt") }}'

# in place, as acme.sh does on a renewal (`cat "$CERT_PATH" >"$_real_cert"`)
- name: 'echo lfops-molecule-renewed > lfops-molecule.crt (renew the probe certificate)'
ansible.builtin.shell:
cmd: 'echo lfops-molecule-renewed > {{ __molecule__aide_cert_dir }}/lfops-molecule.crt'
executable: '/bin/bash'
changed_when: true # the content changes on every run

- name: 'chmod 0600 lfops-molecule-chain.crt'
ansible.builtin.file:
path: '{{ __molecule__aide_cert_dir }}/lfops-molecule-chain.crt'
mode: 0o600

- name: 'stat the trust bundle'
ansible.builtin.stat:
path: '{{ __molecule__aide_trust_bundle }}'
register: '__molecule__aide_trust_bundle_result'

# a symlink on the Red Hat family. Pointing it to the same file by another path changes the
# link without breaking the trust store for the rest of the run.
- name: 'ln -sfn the trust bundle to the same file by another path'
ansible.builtin.file:
src: '{{ __molecule__aide_trust_bundle_result["stat"]["lnk_target"] | dirname }}/./{{ __molecule__aide_trust_bundle_result["stat"]["lnk_target"] | basename }}'
dest: '{{ __molecule__aide_trust_bundle }}'
state: 'link'
force: true
when:
- '__molecule__aide_trust_bundle_result["stat"]["islnk"]'

# a comment outside the PEM blocks, which OpenSSL skips
- name: 'Append a comment to the trust bundle'
ansible.builtin.lineinfile:
path: '{{ __molecule__aide_trust_bundle }}'
line: '# lfops-molecule'
when:
- 'not __molecule__aide_trust_bundle_result["stat"]["islnk"]'

- name: 'systemctl start --wait aidecheck.service (changed host)' # noqa command-instead-of-module (wait for the check to finish and read its Result)
ansible.builtin.command: 'systemctl start --wait aidecheck.service'
changed_when: false
Expand Down Expand Up @@ -414,6 +457,9 @@
- '"/root/.gnupg/public-keys.d/.#lk" not in __molecule__aide_changed_log_result["stdout"]'
- '"/root/.gnupg/public-keys.d/pubring.db.lock" not in __molecule__aide_changed_log_result["stdout"]'
- '"/root/.gnupg/lfops-molecule-key" in __molecule__aide_changed_log_result["stdout"]'
- '(__molecule__aide_cert_dir ~ "/lfops-molecule.crt") not in __molecule__aide_changed_log_result["stdout"]'
- '(__molecule__aide_cert_dir ~ "/lfops-molecule-chain.crt") in __molecule__aide_changed_log_result["stdout"]'
- '__molecule__aide_trust_bundle in __molecule__aide_changed_log_result["stdout"]'
- '__molecule__aide_changed_log_result["stdout"] is not search("/var/log\\s*(:|$)", multiline=True)'
fail_msg: '{{ __molecule__aide_changed_log_result["stdout"] }}'

Expand Down Expand Up @@ -496,6 +542,34 @@
when:
- '__molecule__efi_fstype_result["stdout"] == "vfat"'

- name: 'Restore the probe certificates'
ansible.builtin.copy:
content: 'lfops-molecule'
dest: '{{ __molecule__aide_cert_dir }}/{{ item }}'
owner: 'root'
group: 'root'
mode: 0o644
loop:
- 'lfops-molecule.crt'
- 'lfops-molecule-chain.crt'

- name: 'ln -sfn the trust bundle back to its original path'
ansible.builtin.file:
src: '{{ __molecule__aide_trust_bundle_result["stat"]["lnk_target"] }}'
dest: '{{ __molecule__aide_trust_bundle }}'
state: 'link'
force: true
when:
- '__molecule__aide_trust_bundle_result["stat"]["islnk"]'

- name: 'Remove the comment from the trust bundle'
ansible.builtin.lineinfile:
path: '{{ __molecule__aide_trust_bundle }}'
line: '# lfops-molecule'
state: 'absent'
when:
- 'not __molecule__aide_trust_bundle_result["stat"]["islnk"]'

# the last check failed, so the tasks `--tags aide:update_db` runs must leave the database
# alone and say so
- name: 'sha256sum /var/lib/aide/aide.db.gz (before update-db-if-clean after a failed check)'
Expand Down
1 change: 1 addition & 0 deletions roles/aide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ This role is compatible with the following aide versions:
* `/boot/efi` is checked without the inode (`DATAONLY`), since the kernel assigns new inode numbers on the vfat EFI system partition at runtime.
* `/etc/aliases.db` is checked for permissions only (`PERMS`), since postfix on the Red Hat family rebuilds it on its start.
* `/etc/resolv.conf` is checked for permissions only (`PERMS`), since DHCP clients and NetworkManager rewrite it at runtime.
* The certificates `*.crt` in `/etc/pki/tls/certs` and `/etc/ssl/certs` are checked for permissions only (`PERMS`), since acme.sh and other tools renew them in place. The trust bundles `ca-bundle.crt`, `ca-bundle.trust.crt` and `ca-certificates.crt` and the private keys stay fully checked, so a replaced key or a new trusted CA is still reported.
* `/etc/fwupd/fwupd.conf` is checked without its mode, since fwupd sets the file to 0640 whenever its daemon starts.
* `/var/log` itself is checked without its link count, which follows its subdirectories.
* `/etc/lvm/archive` allows added and removed files, since LVM archives the metadata of a VG before every change and removes old archives itself.
Expand Down
18 changes: 18 additions & 0 deletions roles/aide/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,24 @@ aide__rules__role_var:
# secrets
- path: '/etc/pkcs11'
attributes: 'NORMAL'
# Not in the shipped list. Server certificates are renewed in place, by acme.sh every 60 days
# (`cat "$CERT_PATH" >"$_real_cert"` in _installcert(), verified against acme.sh 3.1.6), with
# the same owner, mode and SELinux context, so PERMS still reports anything but the new
# content. Their keys below /etc/pki/tls/private and /etc/ssl/private keep NORMAL, since
# acme.sh reuses the key on a renewal. The trust bundles in the same directories (symlinks on
# the Red Hat family, a file written by update-ca-certificates on Debian and Ubuntu) keep
# NORMAL and have to come first, aide applies the first matching rule of a directory.
# /etc/ssl/certs is a symlink to /etc/pki/tls/certs on the Red Hat family, which aide does not
# follow. Verified with aide 0.16 to 0.19.2 on Rocky 8, 9 and 10, Debian 12 and 13 and Ubuntu
# 22.04, 24.04 and 26.04.
- path: '/etc/pki/tls/certs/ca-bundle(\.trust)?\.crt$'
attributes: 'NORMAL'
- path: '/etc/pki/tls/certs/[^/]+\.crt$'
attributes: 'PERMS'
- path: '/etc/ssl/certs/ca-certificates\.crt$'
attributes: 'NORMAL'
- path: '/etc/ssl/certs/[^/]+\.crt$'
attributes: 'PERMS'
- path: '/etc/pki'
attributes: 'NORMAL'
- path: '/etc/ssl'
Expand Down
2 changes: 1 addition & 1 deletion roles/aide/templates/etc/0.16-aide.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110501
# 2026111501
# For aide 0.16 (RHEL 8). Based on 0.19-aide.conf.j2, reduced to the options aide 0.16
# knows. The rules are the same for every aide version and platform.

Expand Down
2 changes: 1 addition & 1 deletion roles/aide/templates/etc/0.17-aide.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110501
# 2026111501
# For aide 0.17 (Ubuntu 22.04). Based on 0.19-aide.conf.j2, reduced to the options aide 0.17
# knows: num_workers, report_format and config_check_warn_unrestricted_rules arrived in 0.18
# (src/conf_lex.l). Debian and Ubuntu ship no single aide.conf to stay close to, aide-common
Expand Down
2 changes: 1 addition & 1 deletion roles/aide/templates/etc/0.18-aide.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110501
# 2026111501
# For aide 0.18 (Debian 12, Ubuntu 24.04). Based on 0.19-aide.conf.j2, with the options aide
# 0.18 knows. Debian and Ubuntu ship no single aide.conf to stay close to, aide-common
# assembles it from /etc/aide/aide.conf.d. The rules are the same for every aide version and
Expand Down
2 changes: 1 addition & 1 deletion roles/aide/templates/etc/0.19-aide.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026110501
# 2026111501
# For aide 0.19 (Debian 13, RHEL 9 and 10, Ubuntu 26.04). Based on the /etc/aide.conf shipped
# with aide 0.19.2 on Rocky 9 and 10. The rules are the same for every aide version and
# platform.
Expand Down
2 changes: 1 addition & 1 deletion roles/lynis/templates/etc/lynis/custom.prf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# {{ ansible_managed }}
# 2026092701
# 2026111601
#
# Local additions to /etc/lynis/default.prf, read by every audit on this host, including the one
# the lynis monitoring plugin runs.
Expand Down
4 changes: 4 additions & 0 deletions roles/lynis/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ __lynis__skip_tests__common:
comment: 'The redis role binds to localhost with protected-mode; a password needs a secret from the inventory (redis__conf_requirepass).'
- name: 'DBS-1886'
comment: 'Renaming CONFIG breaks clients that use it; the redis role binds to localhost with protected-mode.'
# `aide --config-check` of aide 0.16 (RHEL 8) opens the report_url file for writing and empties
# it, verified with Lynis 3.1.7 and aide 0.16 on Rocky 8 (0.19.1 and 0.19.2 keep it).
- name: 'FINT-4315'
comment: 'Lynis runs aide --config-check, which empties the AIDE report with aide 0.16, so the aide-logfile monitoring plugin warns until the next check; the aide role validates aide.conf on every deployment.'
- name: 'HRDN-7222'
comment: 'Compilers restricted to root break builds by other users, such as pip installing source packages into a venv, and package updates restore the mode.'
- name: 'HRDN-7230'
Expand Down
Loading