Ubuntu · Logging & auditing

Rotate log files with logrotate

When it fails: Text log files are never rotated. Without logrotate, files such as /var/log/dpkg.log grow forever and old entries are never archived or removed.

CB-UBU-AUDIT-007lowactiveautomatedautomated fixprofile core

As released in v0.1.2 (beta). Current state.

Description

logrotate renames, compresses and removes the text log files under /var/log/ following /etc/logrotate.conf and the files that packages drop in /etc/logrotate.d/. Ubuntu installs it by default and starts it every day with logrotate.timer.

This control requires the logrotate package and its timer to be enabled.

The systemd journal rotates itself (CB-UBU-AUDIT-001) and auditd rotates its own logs (CB-UBU-AUDIT-013); logrotate handles the remaining text files.

Rationale

Logs that are never rotated end up filling the file system, which stops the services that need to write, or are deleted by hand in a hurry. Rotation keeps a predictable history.

Impact

Old rotated files are deleted after the number of rotations set in each logrotate file (4 weeks by default in /etc/logrotate.conf). Keep a remote copy when a longer history is required.

Setting

Locationlogrotate package, logrotate.timer
DefaultNot installed on cloud images
RecommendedInstalled, timer enabled

Audit

  1. Run dpkg-query -W -f='${Status}\n' logrotate. It must end with installed.
  2. Run systemctl is-enabled logrotate.timer. It must print enabled.
  3. Review /etc/logrotate.conf and /etc/logrotate.d/ against the site retention policy.

Automated: every check must pass. Scanners report each check by its id.

package

logrotate is installed.

name: logrotate
state: installed

timer

logrotate.timer is enabled.

unit: logrotate.timer
state: enabled

Remediation

Run apt-get install logrotate, then systemctl enable --now logrotate.timer.

Restartnone
Disruptionnone

Rollback

Run apt-get purge logrotate.

package

Generated from check package: the engine writes the fix for every output, it sets the expected value and the check runs again after.

timer

Generated from check timer: the engine writes the fix for every output, it sets the expected value and the check runs again after.

Each release turns these fixes into remediate.sh and an Ansible role per profile: dry run by default, a fix runs only when its check fails.

References

Mappings

How this control relates to the other framework's: equivalent, stricter, looser, partial or related.

Threats mitigated

  • related CB-UBU-AUDIT-001 Keep the systemd journal running, persistent, compressed and bounded in size

People and lifecycle

Authors
Verified2026-10-19 by Sn0wAlice on 20.04, Proxmox VM, Ubuntu 20.04 cloud image, kernel 5.4.0-216-generic. Passes on stock image (logrotate installed, logrotate.timer enabled).
Verified2026-10-19 by Sn0wAlice on 22.04, Proxmox VM, Ubuntu 22.04 cloud image, kernel 5.15.0-198-generic. Passes on stock image (logrotate installed, logrotate.timer enabled).
Verified2026-10-19 by Sn0wAlice on 24.04, Proxmox VM, Ubuntu 24.04 cloud image, kernel 6.8.0-147-generic. Passes on stock image (logrotate installed, logrotate.timer enabled).
Verified2026-10-19 by Sn0wAlice on 26.04, Proxmox VM, Ubuntu 26.04 cloud image, kernel 7.0.0-38-generic. Passes on stock image (logrotate installed, logrotate.timer enabled).
Introduced inv0.1.0
Created, updated2026-10-19, 2026-10-19
Translationsfr