# ClusterControl MCP Server audit log — /etc/logrotate.d/cmon-mcp
#
# `create 0600 root root` is the load-bearing line here, not a hardening
# nicety. The server refuses to append to an audit log whose mode is
# wider than 0600 — it re-opens the file for EVERY record, and checks
# the mode of the descriptor it just opened — so a policy that rotated
# to any wider mode would leave the file perfectly present and every
# audited call refused with AUDIT_UNAVAILABLE from the first rotation
# onwards. Nothing about the package would look wrong: the file list
# would be identical, the service would still be `active`, and the
# fault would appear on whatever day the log first rotated.
#
# root:root because the packaged unit declares no User=, so the server
# runs as root and would otherwise be unable to append to the file this
# policy created.
#
# No `copytruncate`, deliberately. That directive exists for a process
# that holds one descriptor from startup, and this sink does not: it
# opens, appends, fsyncs and closes per record, so a rename is all that
# is needed and the next record lands in the new file. copytruncate
# would introduce the one window that does not exist today — records
# written between the copy and the truncate are lost — in exchange for
# nothing.
#
# `compress` with no `delaycompress` for the same reason: nothing is
# still writing to the rotated file once it has been renamed. gzip
# preserves the source mode, so the compressed copy stays 0600.
#
# `missingok` because the audit log only exists once a host is governed
# AND the server has written its first record, and neither is true of
# every host that has this file. An upgraded host is ungoverned unless
# its operator governed it themselves, and a fresh install has no records
# until the server is first asked to do something. A daily error from
# logrotate about a path that is correctly absent is noise that trains an
# operator to ignore this unit's mail.
#
# This policy names the PACKAGED path and follows no setting. An operator
# who moves the log with MCP_AUDIT_LOG rotates it themselves; nothing
# here reads that variable, and nothing can — logrotate has no view of
# the unit's environment.
#
# This file ships as a dpkg conffile and an RPM %config(noreplace),
# which is the convention for /etc/logrotate.d and the right one: how
# long an operator keeps audit records, and whether they compress them,
# is their decision and not the package's. The residual is the same trap
# the packaged systemd drop-in exists to close — a host that edits this
# file never receives a later change to the `create` mode — and it is
# accepted here because the file is new, so every host that has one got
# it from a first install of a version that already carried this line.
/var/log/cmon-mcp/audit.jsonl {
    daily
    rotate 30
    missingok
    notifempty
    compress
    create 0600 root root
}
