Skip to content

Never let root run a file the bot can write - #88

Merged
Isma-L154 merged 2 commits into
mainfrom
fix/87-root-runs-bot-writable-script
Oct 15, 2026
Merged

Isma-L154 merged 2 commits into
mainfrom
fix/87-root-runs-bot-writable-script

Conversation

@Isma-L154

Copy link
Copy Markdown
Owner

Closes #87

What changes

  • install-units.sh installs update-ytdlp.sh as a root-owned 0755 copy in /usr/local/sbin/loopify-ytdlp-update, and the updater unit runs that copy with the checkout as its argument. Root no longer executes anything the bot can write.
  • The updater unit gets the same sandboxing as the bot, with only the venv writable. PIP_NO_CACHE_DIR=1 because pip's cache in the read-only home only produced a warning.
  • The bot's ReadWritePaths goes from the whole checkout to .cache and the optional cookies.txt, so a compromised bot cannot rewrite its own code.
  • Two tests in tests/test_service_sandbox.py keep both properties.

Verified on ilserver4

  • The new updater, run as a transient unit with exactly these sandbox properties: pip ran as ashesofil, and the run printed yt-dlp already current (2026.08.19), exit 0.
  • systemctl restart, issued from inside the same sandbox, restarts a unit (exit 0).
  • Since its last restart, the bot has only written .cache and __pycache__ in the checkout. Python skips the bytecode cache quietly when it cannot write it.

The yt-dlp updater ran as root straight from the checkout, which the bot's
unit could write. Install a root-owned copy in /usr/local/sbin, sandbox the
updater, and narrow the bot's writable paths to its caches and cookies.
@Isma-L154
Isma-L154 merged commit f0548c9 into main Oct 15, 2026
8 checks passed
@Isma-L154
Isma-L154 deleted the fix/87-root-runs-bot-writable-script branch October 15, 2026 01:14
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.

The bot can rewrite a script that root runs every day

1 participant