Skip to content

Depend on polkit so the packaged watchdog can heal Tor - #191

Merged
onyks-os merged 2 commits into
mainfrom
fix/polkit-dependency
Nov 30, 2026
Merged

onyks-os merged 2 commits into
mainfrom
fix/polkit-dependency

Conversation

@onyks-os

Copy link
Copy Markdown
Owner

Problem

Every native package (.deb, .rpm, PKGBUILD) creates the ttp-watchdog account, so the watchdog runs as that account. When Tor stops or crashes, it restarts ttp-tor.service through polkit, using 50-ttp-watchdog.rules. That rule is read by polkitd alone, and no package depended on polkit.

Measured on Debian 13, with systemd as PID 1, the packaged account and rule, and a stand-in ttp-tor.service:

polkitd systemctl restart ttp-tor.service as ttp-watchdog
absent Access denied
126, rule loaded succeeds. Another unit and another account are still refused

In the watchdog, a refused restart is a failed heal (ttp/watchdog/integrity.py:286), and a failed heal goes to heal_fail and then the emergency killswitch. Nothing leaks, but a Tor restart leaves the host with no network until the user steps in. This affects hosts without polkit, such as servers and minimal installs.

Fix

  • The .deb now depends on polkitd, and the .rpm and PKGBUILD on polkit.
  • tests/test_packaging_dependencies.py requires this of all three. It failed before the change.
  • packaging/smoke_test.sh also requires the account, polkitd and a readable rule:
    • on the released 0.5.1 .deb it fails;
    • the new .deb passes on Debian 13 and Ubuntu 24.04 (run locally).
  • Docs: the dependency lists, the watchdog explanation, and the security-assessment row for the polkit rule. That row described the rule incorrectly, and now records the measured scope.

New VM scenario

The other VM jobs install TTP with pip. With no account, the watchdog runs as root, and the chaos sweep counts a killswitch as contained, so none of them could see this. scripts/vm/lifecycle/heal.sh (new job Watchdog heals Tor as packaged) runs three steps:

  1. Install the .deb with apt in a Debian 13 guest, and require polkitd and a watchdog unit running with User=ttp-watchdog.
  2. Run systemctl stop ttp-tor, then require the watchdog to log the restart, ttp-tor to be active again, and no killswitch.
  3. Control: mask polkit and stop Tor again. The killswitch must engage, and the watchdog must log the failed heal. Without this, step 2 proves nothing.

This PR's run of that job is its first end-to-end run.

🤖 Generated with Claude Code

onyks-os and others added 2 commits November 30, 2026 11:24
Every native package creates the ttp-watchdog account, so the watchdog
runs as that account and restarts a stopped or crashed ttp-tor.service
through polkit (50-ttp-watchdog.rules). Only polkitd reads that rule, and
no package depended on it. Measured on Debian 13 (systemd as PID 1, the
packaged account and rule, a stand-in ttp-tor.service): without polkitd
`systemctl restart ttp-tor.service` as ttp-watchdog is "Access denied";
with polkitd 126 it succeeds, while another unit and another account are
still refused. In the watchdog a refused restart is a failed heal, which
engages the emergency killswitch: no leak, but a Tor restart left the
host without network.

The .deb now depends on polkitd, the .rpm and the PKGBUILD on polkit.
test_packaging_dependencies.py requires it of all three (it failed
before). The package smoke test also requires the account, polkitd and a
readable rule; run on the released 0.5.1 .deb it fails, and the new .deb
passes on Debian 13 and Ubuntu 24.04.

The VM jobs install TTP with pip, where the watchdog runs as root, and
the chaos sweep counts a killswitch as contained, so none of them could
see this. scripts/vm/lifecycle/heal.sh installs the .deb in a Debian
guest, stops ttp-tor and requires a heal without a killswitch, then masks
polkit and requires the same fault to end in the killswitch, so the check
can fail. It runs as a new job in lifecycle.yml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
The first run of heal.sh waited for "Restarted Tor service successfully"
and timed out. That line is logged at INFO, and the watchdog running as
ttp-watchdog cannot open root's log file, so only WARNING and above
reach its journal: the run shows "Initiating auto-healing for failed
component 'tor'" and no error after it.

The heal is now judged by: the watchdog's healing line, a new "Started
ttp-tor.service" from systemd, ttp-tor active, and, past the next
15 s check, no killswitch and neither "Failed to restart Tor service"
nor "Local integrity failure in tor". The control looks for the refused
restart that integrity.py logs on the supervisor's path, not the FSM's
message, which that path never emits. The journals of ttp-tor and
polkit are kept with the logs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
@onyks-os
onyks-os merged commit 25a4ff6 into main Nov 30, 2026
37 of 38 checks passed
@onyks-os
onyks-os deleted the fix/polkit-dependency branch November 30, 2026 13:01
onyks-os added a commit that referenced this pull request Nov 30, 2026
* Log the watchdog's INFO lines to the journal

The native packages run the watchdog as ttp-watchdog, which cannot open
root's /run/ttp/ttp.log (0600). setup_logging() returned early in that
case, before any console handler, so the ttp logger had no handler at
all: Python's last-resort handler printed WARNING and above, and INFO
lines appeared nowhere, a healed Tor among them. Found by the first run
of scripts/vm/lifecycle/heal.sh (#191), which waited for the heal's INFO
line in the journal and never saw it.

A file that cannot be opened now skips only the file handler. When
systemd has connected stderr to the journal (JOURNAL_STREAM names
stderr's device and inode, as the variable is inherited by children),
and no console handler is configured, INFO and above go to stderr, each
line prefixed with its syslog priority (<6>, <4>, ...), so journalctl
records the level and -p filters on it. A root watchdog keeps its file
and gains the journal; --quiet keeps the journal quiet; a CLI run from a
terminal is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>

* Require the heal's INFO line in the packaged watchdog's journal

With the journal handler, the watchdog running as ttp-watchdog logs
"Watchdog: Restarted Tor service successfully." at INFO. heal.sh now
requires that line, read with `journalctl -p info..info` so the priority
journald recorded is checked too. Before this branch the confined
watchdog logged nothing below WARNING, and this check would have failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>

---------

Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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