Ansible Role linuxfabrik.lfops.aide¶
This role installs and configures AIDE (Advanced Intrusion Detection Environment), creates the AIDE database, and schedules a regular file integrity check with aidecheck.timer, following the filesystem integrity recommendations of the CIS benchmarks.
This role is compatible with the following aide versions:
- 0.16 (RHEL 8)
- 0.17 (Ubuntu 22.04)
- 0.18 (Debian 12, Ubuntu 24.04)
- 0.19 (Debian 13, RHEL 9, RHEL 10, Ubuntu 26.04)
Available in the next LFOps release.
How the Role Behaves¶
- Every aide run of the role, of the check unit, of
system_updateand of the dpkg hook has the lowest CPU and I/O priority (Nice=19, idle I/O class, CPU and I/O weight of 1), so that it yields to everything else on the host. A run still shows up in/proc/pressure/io, since on an idle host the one task with work to do is the one waiting for the disk. - Before it deploys
/etc/aide.conf, the role has aide check the new file (aide --config-check) and aborts the run if aide does not accept it, for example because of a typo in a rule or inaide__conf_raw. The file on the host stays as it was. /etc/aide.confis fully templated, with the same path, database (/var/lib/aide/aide.db.gz) and rules on every platform. The options and the attribute groups (NORMAL,CONTENT,PERMS, ...) follow the installed aide version. All groups use sha512 as their only checksum. The rules come fromaide__rules__*_var, whose default is the rule list RHEL 9 and 10 ship, extended by the Debian and Ubuntu counterparts of its paths and by the audit tool rules the CIS benchmarks ask for. A path a host does not have is skipped.- Rules from the inventory with a path of their own are placed above the default rules, so that a rule such as
/root/\.bashrc$takes effect instead of the default/root/\..*rule. A default rule changed from the inventory keeps its place. - On Debian and Ubuntu the role installs aide without its recommended packages and purges
aide-commonif it is installed.aide-commonruns a daily check of its own next toaidecheck.timer, which mails its report instead of failing, writes the same/var/log/aide/aide.log, and pulls in cron and a mail transport agent (exim4 on Debian, postfix on Ubuntu). The role purges it, including its configuration in/etc/aide. - The aide binaries of Debian and Ubuntu are built without a default config file. All aide runs of LFOps take the lock
/run/aide.lockand run one after the other, since a second aide run exits with 21 while another one runs. Run aide by hand the same way, on every platform:flock /run/aide.lock aide --config=/etc/aide.conf --check. - On the first run the role creates the database (
/var/lib/aide/aide.db.gz), after it has deployed the config and the systemd units and after the pending handlers of the play have run. Depending on the size of the file system,aide --initcan take several minutes. In a playbook that combines several roles, run aide last, assetup_basicdoes, so that the database contains what the other roles deployed. aidecheck.servicerunsaide --checkat a low CPU and IO priority, byaidecheck.timerand after every boot, once the services have started. Any finding (added, removed or changed files) makes the check exit non-zero, which leavesaidecheck.servicein the failed state. The aide-logfile monitoring plugin evaluates the report, and monitoring failed systemd units alerts as well. The full report is written to/var/log/aide/aide.log, overwritten by every check. From aide 0.17 on, a summary (whether and how many files changed) additionally goes to syslog (journalctl --unit aidecheck.service), from where rsyslog forwards it. aide 0.16 (RHEL 8) cannot limit the syslog report, so there the report only goes to the file. The role sends no mail./etc/logrotate.d/aiderotates the report weekly withcopyinstead of thecopytruncatethe RHEL package ships, which would leave/var/log/aide/aide.logempty until the next check, as if the check had aborted.- A check that is due while the system_update role or
unattended-upgradesinstalls packages waits until the update has finished. Conversely,system_updateand the dpkg hook wait for a running check before they update the database. The role waits for it for 5 minutes at most and then aborts the run (see "Troubleshooting"). A database update runs no check against the new database:aide --updatecompares the whole file system like a check and writes its report to/var/log/aide/aide.log, which the aide-logfile monitoring plugin reports as accepted. The next regular check confirms the new database. - When the role changes
/etc/aide.conf, its own units or whetheraidecheck.serviceoraidecheck.timeris enabled, it updates the database afterwards, so that the next check does not report every path the new rules add or drop. It only does so if the last check had not reported changes: re-baselining a failing check would silently accept whatever changed on the host, an intrusion included. The same applies to a database the role finds on a host where it has not deployedaidecheck.serviceyet, for example one left by a previous AIDE setup: no check of this role has vouched for it. In both cases the database is left alone and the run tells you so. Review/var/log/aide/aide.logor the output ofaide --check, and accept the current state with--tags aide:update_db_force. - The re-baseline after a change of the role accepts everything that changed since the last check, not only the change the role made. The shorter the check interval, the smaller that window.
- Changes to monitored files made by anyone else, other LFOps roles and packages installed by hand included, are reported by the next check. The system_update role knows about
aidecheck.service: it runs a check before it updates packages and updates the database afterwards if that check was clean. The librenms role does the same around the nightly self-update of LibreNMS. - On Debian and Ubuntu the same applies to the updates of
unattended-upgrades: a dpkg hook (/usr/local/sbin/aide-dpkg-hook, wired in by/etc/apt/apt.conf.d/z00-linuxfabrik-aide) runs a check beforeunattended-upgradesinstalls its first package, and if that check was clean,aide-dpkg-update.serviceupdates the database once the upgrade has finished.unattended-upgradesinstalls in several steps, one dpkg run each, but the check and the update run only once per upgrade. The upgrade takes longer by that one check, while apt holds its lock. The hook only acts on dpkg runs ofunattended-upgrades, so a package installed with apt by hand is reported, as on the Red Hat family. Changes made on the host while the upgrade runs are accepted along with it. - On Debian and Ubuntu the role creates an empty
/etc/apt/sources.listif there is none, as on hosts with only/etc/apt/sources.list.d/*.sources.unattended-upgradescreates that file on every run otherwise, and the check before the first upgrade would report it. - The duplicity role backs up
/var/lib/aideby default. An attacker with root privileges can replace the local database. The database only changes when it is updated (by this role,--tags aide:update_dboraide:update_db_force, the system_update role,aide-dpkg-update.serviceorlibrenms-daily.serviceof the librenms role), so a local database that differs from the backup of a day without such an update points to tampering. - Before it creates the database, the role waits for running package jobs:
apt-daily.serviceandapt-daily-upgrade.serviceon Debian and Ubuntu,dnf-automatic.serviceanddnf-automatic-install.serviceon the Red Hat family, andsecurity-update.serviceandupdate-and-reboot.serviceof the system_update role everywhere. A package installation duringaide --initwould leave entries without checksums in the database.
Known Limitations¶
- Non-recursive negative rules (
-/path) are not available, since aide 0.16 to 0.18 do not know them. - Python byte code that a package does not compile when it is installed is written on its first use and reported by the next check as added, for example below
/usr/lib/python3/dist-packages/netplan/__pycache__on Ubuntu 22.04 after a netplan update. Review and accept it with--tags aide:update_db_force. - The CIS benchmarks for Debian 12 and Ubuntu 22.04 expect
aide-commonto be installed, and the one for Debian 12 accepts no other check than itsdailyaidecheck.timer. The role removesaide-commoninstead, since its check never fails on a finding, so these recommendations are reported as not met there. - On RHEL 8 the audit script of the CIS benchmark for the audit tool rules fails whatever
/etc/aide.confcontains: it locates the file withwhereis aide.conf, which util-linux 2.32 answers with/usr/sbin/aide. The rules are in place all the same.
Tags¶
aide
- Installs aide.
- Deploys
/etc/aide.confand/etc/logrotate.d/aide, and on Debian and Ubuntu the dpkg hook andaide-dpkg-update.service. - Deploys
aidecheck.serviceandaidecheck.timer, enables both and sets the state of the timer. - Creates the AIDE database if it does not exist yet.
- Triggers: AIDE database update.
aide:configure
- Deploys
/etc/aide.confand/etc/logrotate.d/aide, and on Debian and Ubuntu the dpkg hook andaide-dpkg-update.service. - Triggers: AIDE database update.
aide:state
- Enables or disables
aidecheck.serviceandaidecheck.timer, and sets the state of the timer. - Triggers: AIDE database update.
aide:update_db
- Not run by default, only when the tag is given explicitly.
- Updates the AIDE database to the current state of the host, but only if the last check had not reported changes, the same condition under which the role updates the database after a change of its own. Otherwise the database is left alone and the run tells you so. Use it routinely after a deploy, to accept what the run changed without accepting findings that were pending before it:
ansible-playbook --inventory inventory linuxfabrik.lfops.setup_basic --limit myhost --tags all,aide:update_db. Like that update, it accepts everything that changed since the last check, not only the changes of the run. - Triggers: none.
aide:update_db_force
- Not run by default, only when the tag is given explicitly.
- Updates the AIDE database to the current state of the host, whatever the last check reported, and clears the failed state of
aidecheck.service. Use it after reviewing a finding, to accept the reported changes. - Triggers: none.
Optional Role Variables¶
aide__check_on_calendar
- When
aidecheck.timerruns the check. The default runs it twice a day, after the update and reboot window of the system_update and schedule_reboot roles (04:00 by default), so that a finding shows up during office hours. If you move that window, move the check along with it: a check that runs while an update installs packages reports them, and the database is then no longer updated after updates. See systemd.time(7) for the format. - Type: String.
- Default:
'*-*-* 07,12:{{ 59 | random(seed=inventory_hostname) }}:00'
aide__conf_raw
- Raw content inserted into
/etc/aide.confbetween the attribute groups and the rules. Groups and macros defined here can be used byaide__rules__*_var, and a rule here takes precedence over the rules fromaide__rules__*_varthat belong to the same directory (seeaide__rules__host_var). A negative rule excludes its paths wherever it is. Declare the value as!unsafeif it contains{{or{%. - Type: Multiline string.
- Default:
''
aide__conf_report_level
-
How much the report in
/var/log/aide/aide.logtells about each finding, from least to most:minimal: whether there are findings.summary: plus their number.database_attributes: plus the checksums of the database.list_entries: plus the names of added, removed and changed files.changed_attributes: plus old and new value of each changed attribute.added_removed_attributes: plus the attributes a rule starts or stops checking.added_removed_entries: plus all attributes of added and removed files.
-
On aide 0.16 (RHEL 8) the role translates the value into
verbose, whereminimalandsummary, anddatabase_attributesandlist_entries, give the same report. - Type: String. One of
added_removed_attributes,added_removed_entries,changed_attributes,database_attributes,list_entries,minimal,summary. - Default:
'added_removed_entries' - Deviates from the upstream default
changed_attributes: an added file is otherwise reported by its name only, while its owner, permissions and checksums are what tells a harmless file from an intruder's, also after it has been deleted again.
aide__rules__host_var / aide__rules__group_var
- The rules in
/etc/aide.conf. See aide.conf(5) for the rule syntax. Items are identified by theirpath: an item with thepathof a default rule changes that rule in place,state: 'absent'removes it, and items with a newpathare placed above the default rules, in the order they are listed. The order matters within a directory: aide assigns each rule to the directory its fixed path prefix lies in (/root/\.bashrc$and/root/\..*to/root,/etc/aptto/etc,/etcto/), checks a path against the rules of the deepest such directory first, and applies the first rule that matches within a directory. Useaide --config=/etc/aide.conf --path-check=f:/path/to/file(aide 0.17 and newer) to see which rule applies to a file. Anegativerule always wins, wherever it is. - Type: List of dictionaries.
- Default: the rule list RHEL 9 and 10 ship, extended by the Debian and Ubuntu counterparts of its paths, see
aide__rules__role_varin defaults/main.yml. -
Deviates from the upstream default, so that all hosts are checked against the same rules without reporting what changes during normal operation:
- The RHEL 9 / 10 list is used on every platform, extended by the Debian and Ubuntu counterparts of its paths. On Debian and Ubuntu the rules of
aide-commonare not used. !/root/\.ansible/tmpis added, since Ansible creates and deletes a directory there for every task it runs as root.!/root/\.cacheis added. It holds disposable caches only and gains pip cache entries on every run of the python_venv role.!/root/\.gnupg/S\.,!/root/\.gnupg/.*\.lock$and!/root/\.gnupg/(.*/)?\.#lkare added. gpg-agent and keyboxd keep their sockets and locks there while they run, after a run of the duplicity role or a backup until the next reboot.!/opt/cool/cacheis added. Collabora caches the settings it fetches from the WOPI host there, per host and per user, and deletes them after some time of disuse.!/opt/cool/child-rootsis added. Collabora creates a jail per process there, under a new name on every start.!/opt/gitlab/sv/[^/]+/(log/)?superviseand!/opt/gitlab/varare added. GitLab writes the pid and the state of its services there whenever it starts them.!/opt/librenms/\.git,!/opt/librenms/bootstrap/cache,!/opt/librenms/logs,!/opt/librenms/rrdand!/opt/librenms/storageare added. LibreNMS writes its time series, logs and caches there with every poll, and its nightlydaily.shfetches the git metadata. The code and.envstay covered, so an update to a new release is reported.!/opt/[^/]+/\.local/share/containersis added. Rootless podman of service users with their home below/optrewrites its container storage on every container start and image update.!/root/\.mongodb/mongoshis added. mongosh writes a log file per session there and removes the old ones itself.!/root/\.wp-cli/cacheis added. WP-CLI keeps every WordPress release that the wordpress role downloads as root there.!/usr/share/httpd/\.ansible/tmp,!/usr/share/httpd/\.cacheand!/usr/share/httpd/\.config/libreofficeare added. In the home of the web server user, Ansible creates a directory for every task the nextcloud and wordpress roles run as apache, libsmbclient rewrites its name cache, and LibreOffice rewrites its profile with every document it converts./opt/*/.bash_historyis checked for permissions only (PERMS), like the dot files of root./var/log/dnf.log,dnf.librepo.log,dnf.rpm.loganddnf5.logare checked without their SELinux context, since dnf rotates them by renaming, and each file keeps the SELinux user of whoever ran dnf when it was started.!/usr/lib/sysimage/rpmis added. The RPM database lives there on RHEL 10, and every rpm or dnf query rewrites it.- The audit tool rules of the CIS benchmarks are added.
/etc/ld.so.cacheand/etc/udev/hwdb.binare checked without their inode (DATAONLY), since systemd rebuilds both on the first boot after an update./boot/efiis checked without the inode (DATAONLY), since the kernel assigns new inode numbers on the vfat EFI system partition at runtime./etc/aliases.dbis checked for permissions only (PERMS), since postfix on the Red Hat family rebuilds it on its start./etc/resolv.confis checked for permissions only (PERMS), since DHCP clients and NetworkManager rewrite it at runtime.- The certificates
*.crtin/etc/pki/tls/certsand/etc/ssl/certsare checked for permissions only (PERMS), since acme.sh and other tools renew them in place. The trust bundlesca-bundle.crt,ca-bundle.trust.crtandca-certificates.crtand the private keys stay fully checked, so a replaced key or a new trusted CA is still reported. /etc/fwupd/fwupd.confis checked without its mode, since fwupd sets the file to 0640 whenever its daemon starts./var/logitself is checked without its link count, which follows its subdirectories./etc/lvm/archiveallows added and removed files, since LVM archives the metadata of a VG before every change and removes old archives itself./var/log/auditallows added and removed files, since auditd rotates its logs itself.
- The RHEL 9 / 10 list is used on every platform, extended by the Debian and Ubuntu counterparts of its paths. On Debian and Ubuntu the rules of
-
Subkeys:
-
path:- Mandatory. The regular expression the rule matches, for example
/opt/appor/etc/app.conf$. It always matches from the start of the path. - Type: String.
- Mandatory. The regular expression the rule matches, for example
-
attributes:- Mandatory for rules of type
regularandequal. The attributes or group to check, for exampleNORMAL,CONTENT,PERMSorp+u+g+sha512. - Type: String.
- Mandatory for rules of type
-
state:- Optional.
presentorabsent. - Type: String.
- Default:
'present'
- Optional.
-
type:- Optional.
regularmonitors the path and everything below it.equalmonitors only the path itself (=).negativeexcludes the path and everything below it from monitoring (!), also when another rule covers it. - Type: String. One of
equal,negative,regular. - Default:
'regular'
- Optional.
-
aide__service_enabled
- Whether
aidecheck.serviceis enabled, which runs the check after every boot, once the services have started. - Type: Bool.
- Default:
true
aide__timer_enabled
- Whether
aidecheck.timeris enabled, which runs the check byaide__check_on_calendar. - Type: Bool.
- Default:
true
aide__timer_state
- State of
aidecheck.timer. - Type: String. One of
restarted,started,stopped. - Default:
'started'
Example:
# optional
aide__check_on_calendar: '*-*-* 03:30:00'
aide__conf_raw: |-
APP = p+u+g+sha512
!/var/lib/app/cache
aide__conf_report_level: 'changed_attributes'
aide__rules__host_var:
- path: '/root/\.bashrc$'
attributes: 'APP' # references APP defined in `aide__conf_raw`
- path: '/usr'
attributes: 'CONTENT'
- path: '/etc/cups'
state: 'absent'
- path: '/srv/app'
attributes: 'NORMAL'
- path: '/srv/app/cache'
type: 'negative'
- path: '/srv$'
type: 'equal'
attributes: 'DIR'
aide__service_enabled: true
aide__timer_enabled: true
aide__timer_state: 'started'
Troubleshooting¶
The run aborts with aide X.Y is not supported by this role
- The enabled repositories offer an aide version the role has no config for. The role supports aide 0.16, 0.17, 0.18 and 0.19. Pin the host to a supported version, or add a
roles/aide/templates/etc/<version>-aide.conf.j2and list the version inroles/aide/vars/main.yml.
The run aborts at Deploy /etc/aide.conf with failed to validate
- aide rejected the new config, and
/etc/aide.confwas left as it was. The message quotes the line aide stumbled over, typically a rule fromaide__rules__*_varor a line inaide__conf_rawwith an undefined group, an attribute the installed aide version does not know, or an invalid regular expression. Fix the inventory and run the role again.
The run aborts at a task that waits up to 5 minutes
- An AIDE check (
aidecheck.service) or a package job was still running after 5 minutes. A check takes longer on a large file system or a busy disk. Wait untilsystemctl is-active aidecheck.serviceand the package jobs the task names no longer reportactiveoractivating, then run the role again.
aidecheck.service is failed
- The last check found added, removed or changed files. Read the report in
/var/log/aide/aide.log. If the changes are expected, accept them withansible-playbook --inventory inventory linuxfabrik.lfops.aide --limit myhost --tags aide:update_db_force.