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:
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
The nightly backup unit runs as root but keeps mutable state inside directories the
ubuntuagent 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.backupoverwrites)/home/ubuntu/.hermes/backup-staging/manifest.txt(redirect)mkdir -p,rm -rf,rsyncdestination)Because
ubuntuowns/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
ubuntuno longer works:backup.lockandbackup-last.logare root-owned 644, and/var/cache/resticis 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 assudo systemctl start agent-backup.servicerather 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.