Skip to content

fix(image): rotate logs as their owner so rotation works without CAP_FOWNER - #16

Merged
ks98 merged 3 commits into
mainfrom
fix/logrotate-caps
Nov 20, 2026
Merged

ks98 merged 3 commits into
mainfrom
fix/logrotate-caps

Conversation

@ks98

@ks98 ks98 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Problem

Log rotation inside the container never succeeded. logrotate 3.21 copies the file's ACL onto the
rotated copy; as root without CAP_FOWNER (the container drops all capabilities except SETUID,
SETGID, DAC_OVERRIDE, CHOWN) that fails with setting ACL for /var/log/squid/access.log.1: Operation not permitted. The error was hidden by 2>/dev/null, so access.log grew without limit
(2.46 GB in three weeks on a production proxy) and empty 0600 leftovers piled up.

Fix

  • su proxy proxy in both logrotate stanzas, so logrotate acts as the file owner and needs no
    extra capability. No capability is added.
  • At start, remove only empty leftover files that match the logrotate output patterns.
  • One error line per failed run instead of silence.
  • docs/operations.md: how an existing backlog shrinks (≈ log_retention_days + 1–2 days), the
    copytruncate loss window, and a tested command to trim the backlog by hand.

Tests

  • 3 new integration tests test_log_rotation_* (cp-docker-it, heavy tier): rotation with the real
    hardened container settings, leftover cleanup, error reporting.
  • scripts/tests/logrotate_smoke.sh removed, superseded by those tests.
  • Fast tier and e2e green locally; cold verification by a fresh agent passed all criteria.

Kevin Stenzel added 3 commits November 19, 2026 16:28
… CAP_FOWNER

In the container the control plane starts (cap_drop ALL + SETUID, SETGID,
DAC_OVERRIDE, CHOWN, read-only rootfs, no-new-privileges) logrotate ran as
root and failed on every run: copytruncate creates the copy, chowns it to
proxy and then sets the log's ACL on it, which needs ownership or
CAP_FOWNER ("error: setting ACL for /var/log/squid/access.log.1: Operation
not permitted"). It left an empty 0600 copy, never truncated the log, and
later runs renamed the empty files to *.backup; the errors went to
/dev/null. access.log grew without limit and log_retention_days deleted
nothing.

- logrotate.conf: "su proxy proxy" for access.log and cache.log, so the
  rotation runs as the files' owner (seteuid via SETUID/SETGID, no new
  capability; also what logrotate(8) recommends for directories a
  non-privileged user controls).
- entrypoint: delete only empty files with logrotate's names
  (access.log.<digit>*, cache.log.<digit>*) left by the old images, and say
  how many; anything with content stays.
- a failed run logs one line to the container log: error count and the
  first error.
- Docker integration tests with containers from the real DockerService:
  rotation and retention, the upgrade from a 7.3.9 volume, a failed run
  logged once; all three fail against the 7.3.9 and 7.3.7 images.
- docs: rotation, how to check it, what happens to the backlog after the
  upgrade and how to trim it to the retention (T13).
… tests

It passed against the broken rotation (an empty access.log.1.gz counted as a rotation, the history query read the never truncated access.log) and no runner called it. test_log_rotation_* in controlplane/tests/test_docker_integration.py (cp-docker-it in run.sh e2e) cover the same and fail against the broken images.
…2.gz trim command

From the cold review: the backlog is deleted about log_retention_days + 1 to 2 days after the upgrade (one day until it becomes access.log.1, then log_retention_days rotations); the copytruncate window grows with the log, so the first rotation of a GB backlog can lose a few lines; the trim command for access.log.2.gz is written out in full.
@ks98
ks98 merged commit b18b773 into main Nov 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant