[ norboten ]
linux · lab linux-06

The Log That Never Rotates

· about 30 minutes · runs on ubuntu-26.04-container · unrated

An unrated lab. It runs on your machine with no account and no network, and everything about it — the faults, the checks, the hints and the reference solution — is in the repository. An attempt on it is recorded on your profile and never moves a rating: only rated labs do. Rated and unrated labs.

The briefing

The shop's order service writes to /var/log/shop/app.log as the system user shop. The file is 300 MB and growing. There is a logrotate policy for it in /etc/logrotate.d/shop, and logrotate runs every night — yet the log has never been rotated, and the only time someone forced it by hand the service stopped logging until a restart.

This lab runs in a container: no boot, no cron daemon, nothing to reboot. Run logrotate yourself to see what the nightly job would do (-d shows it without touching anything). You are learner with sudo. /usr/local/bin/shop-log writes one line as shop, the way the service does.

What is expected, and graded — rotation is tried against a copy of your policy, in a scratch directory set up like /var/log/shop, so the grader never rotates your real logs:

  1. logrotate reads /etc/logrotate.d/shop instead of ignoring it.
  2. logrotate agrees to rotate logs in a directory like /var/log/shop.
  3. After a rotation, shop can still write to app.log.
  4. The policy keeps seven rotated logs, compressed, and no more.
  5. The oversized app.log has actually been rotated: it is small now, and its history is beside it.

Do not solve it by making /var/log/shop root's: the service writes there.

What is graded

This lab runs in a container — Docker or Podman, no VM — so there is no boot to survive: the checks run once, against the state you left.

CheckObjective
01_the_config_is_not_ignoredFind out why logrotate ignores or skips a configuration
02_rotation_is_allowed_thereFind out why logrotate ignores or skips a configuration
03_the_app_writes_after_rotationRotate a log without locking out the program that writes it
04_a_week_of_compressed_historyKeep a bounded, compressed history
05_the_big_log_is_rotatedRotate the oversized log now

Start it

  1. 2Labs
  2. linux-06select this one
  3. udownload it
  4. sstart the machine

Reading

Where the lab's hints send you, level by level, as you ask for them (h, then l opens a journal section in the TUI).

Theory for this lab

4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:

Question 1

logrotate reports "skipping /var/log/shop/app.log because parent directory has insecure permissions". The directory is drwxrwxr-x shop:shop and the service writes there. The right fix?

Question 2

A program keeps its log open and never reopens it. The policy uses create, with no postrotate. After a rotation, where do its new lines go?

Question 3

What does this print?

truncate -s 300M app.log
echo "$(stat -c %s app.log) $(du -k app.log | cut -f1)"