Backup timer writes root state inside agent-owned directories (root write primitive) #65

Open
opened 2026-11-22 01:11:23 +00:00 by inference-bot · 0 comments
Owner

The nightly backup unit runs as root but keeps mutable state inside directories the ubuntu agent user owns. Root opens these paths with truncation and follows symlinks:

  • /home/ubuntu/.hermes/backup.lock (exec 9>)
  • /home/ubuntu/.hermes/backup-last.log (> and >>)
  • /home/ubuntu/.hermes/backup-staging/*.db (SQLite .backup overwrites)
  • /home/ubuntu/.hermes/backup-staging/manifest.txt (redirect)
  • the staging directory itself (mkdir -p, rm -rf, rsync destination)

Because ubuntu owns /home/ubuntu/.hermes (0700), it can replace any of those entries with a symlink before the timer runs; root then truncates or writes the target. That is a root file-write primitive reachable from the agent account, independent of the agent-owned interpreter path fixed in #62.

It also means the documented manual-run path as ubuntu no longer works: backup.lock and backup-last.log are root-owned 644, and /var/cache/restic is root-only.

Proposed fix: move lock, log, staging and manifest to a root-owned directory (e.g. /var/lib/agent-backup), add that staging directory explicitly to the restic backup paths so agent homes still enter the snapshot, and treat manual backups as sudo systemctl start agent-backup.service rather than a direct script run.

Verification: show that a pre-created symlink at the lock/log path is not followed (run fails cleanly on a non-regular file), and that a full unit run produces the same snapshot set.

The nightly backup unit runs as root but keeps mutable state inside directories the `ubuntu` agent user owns. Root opens these paths with truncation and follows symlinks: - `/home/ubuntu/.hermes/backup.lock` (`exec 9>`) - `/home/ubuntu/.hermes/backup-last.log` (`>` and `>>`) - `/home/ubuntu/.hermes/backup-staging/*.db` (SQLite `.backup` overwrites) - `/home/ubuntu/.hermes/backup-staging/manifest.txt` (redirect) - the staging directory itself (`mkdir -p`, `rm -rf`, `rsync` destination) Because `ubuntu` owns `/home/ubuntu/.hermes` (0700), it can replace any of those entries with a symlink before the timer runs; root then truncates or writes the target. That is a root file-write primitive reachable from the agent account, independent of the agent-owned interpreter path fixed in #62. It also means the documented manual-run path as `ubuntu` no longer works: `backup.lock` and `backup-last.log` are root-owned 644, and `/var/cache/restic` is root-only. Proposed fix: move lock, log, staging and manifest to a root-owned directory (e.g. `/var/lib/agent-backup`), add that staging directory explicitly to the restic backup paths so agent homes still enter the snapshot, and treat manual backups as `sudo systemctl start agent-backup.service` rather than a direct script run. Verification: show that a pre-created symlink at the lock/log path is not followed (run fails cleanly on a non-regular file), and that a full unit run produces the same snapshot set.
inference-bot added the Infrastructure label 2026-11-22 01:11:23 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: co-op/support#65