Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/lifecycle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ on:
- "ttp/tor_config.py"
- "ttp/virtual_addresses.py"
- "ttp/watchdog/**"
- "ttp/resources/polkit/**"
- "packaging/build_deb.sh"
- "ttp/vpn.py"
- "ttp/vpn_guard.py"
- "tests/chaos_monkey.py"
Expand Down Expand Up @@ -146,6 +148,49 @@ jobs:
# - independent, no bypass: no canary either, because its bypass rule is
# something the watchdog checks - with it configured, a flushed table was
# caught for a reason a normal session does not have (#80).
heal:
# The other jobs install TTP with pip, where the watchdog runs as root.
# This one installs the .deb, so the watchdog runs as ttp-watchdog and
# restarts Tor through polkit, as it does for anyone who installs a package.
name: Watchdog heals Tor as packaged (VM, debian)
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false

- name: Enable KVM for the runner user
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Install QEMU
run: |
sudo apt-get update -q
sudo apt-get install -y -q --no-install-recommends qemu-system-x86 qemu-utils genisoimage

- name: Build the .deb
run: packaging/build_deb.sh

- name: Heal Tor in the guest
env:
VM_WORK: ${{ runner.temp }}/vm
run: scripts/vm/lifecycle/heal.sh packaging/transparent-tor-proxy_*_all.deb

- name: Upload the scenario's logs
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: heal-vm-debian
path: |
${{ runner.temp }}/vm/results.txt
${{ runner.temp }}/vm/heal-*.log
${{ runner.temp }}/vm/cloud-init.txt
if-no-files-found: warn

chaos:
name: Watchdog chaos sweep (VM, ${{ matrix.variant }})
runs-on: ubuntu-latest
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- The `.deb`, `.rpm` and PKGBUILD did not depend on polkit. Each creates the
`ttp-watchdog` account, so the watchdog runs as that account and restarts a
stopped or crashed Tor through polkit (`50-ttp-watchdog.rules`), and only
polkit's daemon reads that rule. Without it, systemd answered "Access denied"
(measured on Debian 13), the heal failed, and the watchdog engaged the
emergency killswitch. Nothing leaked, but a Tor restart left the host with no
network until the user intervened. This happens on hosts without polkit, such
as servers and minimal installs; desktops usually have it. The packages now
depend on `polkitd` (Debian/Ubuntu) or `polkit` (Fedora, Arch).

- `ttp start` interrupted with Ctrl-C or SIGTERM before it recorded its session
undid nothing and exited `0`. It printed "Signal received, restoring
network...", but the nftables table, the DNS overlay and the managed Tor
Expand All @@ -35,6 +45,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Tests

- `scripts/vm/lifecycle/heal.sh` installs the `.deb` in a Debian 13 VM, where
the watchdog runs as `ttp-watchdog` as it does for anyone who installs a
package. It stops `ttp-tor` and requires the watchdog to restart it without a
killswitch. As a control, the same fault with polkit masked must end in the
killswitch. The other VM jobs install with pip, where the watchdog runs as
root, and the chaos sweep counts a killswitch as contained, so neither could
see the missing dependency below. The package smoke tests now also require
the account, polkitd and a readable rule.

- The lifecycle VM judges its phases with NSE 2.6.0, and the `nse` extra
requires `network-sandbox-engine>=2.6.0`. In the guest, NSE's stimulus streams
run as the non-bypassed user between two beacons that carry the guest's clocks.
Expand Down
2 changes: 1 addition & 1 deletion docs/security-assessment.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ TTP is designed to achieve the following security properties, in order of priori
| Threat | STRIDE Category | Description | Mitigation | Residual Risk |
| :--- | :--- | :--- | :--- | :--- |
| Watchdog process compromise | Elevation of Privilege | An attacker exploits the watchdog to execute arbitrary code with full root privileges | The watchdog drops all root privileges, running under the unprivileged user `ttp-watchdog` with `NoNewPrivileges=yes` and the minimal set of capabilities (`CAP_NET_ADMIN`). | **Low.** The watchdog holds `CAP_NET_ADMIN`, so it can program nftables directly; it has no write access to system directories and cannot run administrative shell commands. |
| Insecure Polkit rules authorization | Tampering | An attacker bypasses authentication checks to start/stop the watchdog service | Polkit rules explicitly restrict starting/stopping `ttp-watchdog.service` to root users and the TTP controller. | **Low.** Standard Polkit controls prevent unauthorized service state tampering. |
| Insecure Polkit rules authorization | Tampering | An attacker bypasses authentication checks to start/stop the watchdog service | `50-ttp-watchdog.rules` grants `manage-units` to the `ttp-watchdog` account alone, and only for `ttp-tor.service` and `ttp-watchdog.service`. Measured on Debian 13 with polkitd 126: `ttp-watchdog` can restart `ttp-tor`, but not another unit, and another account cannot restart `ttp-tor`. The native packages depend on polkit, which reads the rule. | **Low.** Standard Polkit controls prevent unauthorized service state tampering. |

### 3.8 systemd-resolved — DNS Resolution Edge Cases

Expand Down
6 changes: 5 additions & 1 deletion docs/web/explanation/watchdog-fsm.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ running `ttp watchdog run`:

- as the `ttp-watchdog` account when it exists, with only `CAP_NET_ADMIN` and
`NoNewPrivileges=yes`. It can read the session lock but not write it, and it
writes only to its own directory, `/run/ttp/watchdog`;
writes only to its own directory, `/run/ttp/watchdog`. The native packages
create this account. They also depend on polkit, because the watchdog restarts
`ttp-tor.service` through `50-ttp-watchdog.rules`, and without polkitd that
restart is refused. Without the account, as after a pip install, the
watchdog runs as root;
- as `Type=notify`: it reports **ready** only after its event subscriptions are
in place and its first complete evaluation has finished (`readiness_timeout`,
30 s). `ttp start` waits for that first healthy observation. A watchdog that
Expand Down
20 changes: 19 additions & 1 deletion docs/web/how-to/vm-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,25 @@ purpose. It collects the log and exit code through QEMU Guest Agent over
virtio-serial, independently of SSH and the guest's firewall. Failure to retrieve
the result remains an error; it never counts as containment.

Both scripts run in CI from `.github/workflows/lifecycle.yml`. See
Both install TTP with pip, so no `ttp-watchdog` account exists and the watchdog
runs as root. `scripts/vm/lifecycle/heal.sh <package.deb>` installs the `.deb`
instead, as a user would. In that setup the watchdog runs as `ttp-watchdog` and
restarts Tor through polkit. The script runs three checks:

1. polkitd came with the package;
2. after `systemctl stop ttp-tor`, the watchdog restarted Tor and no killswitch
engaged;
3. as a control, with polkit masked the same fault ends in the killswitch.

The chaos sweep counts a killswitch as contained, so it cannot tell a healed
Tor from a refused restart; this scenario can:

```bash
packaging/build_deb.sh
VM_WORK=~/.cache/ttp-heal-vm scripts/vm/lifecycle/heal.sh packaging/transparent-tor-proxy_*_all.deb
```

These scripts run in CI from `.github/workflows/lifecycle.yml`. See
`docs/security-assessment.md` section 4.3 for what it asserts and what it found.

### Required VPN with real Tor
Expand Down
14 changes: 11 additions & 3 deletions docs/web/reference/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ fails if a runtime dependency in `pyproject.toml` is missing from any of them, a
CI installs every package in a clean container before a release is signed
(`packaging/smoke_test.sh`).

Every package creates the `ttp-watchdog` account, so its watchdog runs as that
account and restarts `ttp-tor.service` through polkit
(`/usr/share/polkit-1/rules.d/50-ttp-watchdog.rules`). The packages therefore
depend on polkit's daemon, which reads that rule. Without it, systemd refuses the
restart, and a stopped Tor makes the watchdog engage the emergency killswitch
instead of healing the session. A pip install has no such account: there the
watchdog runs as root and does not need polkit.

=== "Debian / Ubuntu (.deb)"

```text
Depends: python3 (>= 3.12), python3-typer, python3-rich (>= 13.7.1), python3-stem,
python3-transitions (>= 0.9.0), nftables, tor, apparmor
python3-transitions (>= 0.9.0), nftables, tor, apparmor, polkitd
Suggests: network-manager, wireguard-tools
```

Expand All @@ -96,7 +104,7 @@ CI installs every package in a clean container before a release is signed

```text
Requires: python3 >= 3.12, python3-typer, python3-rich, python3-stem, python3-six,
nftables, tor, policycoreutils
nftables, tor, policycoreutils, polkit
Suggests: NetworkManager, wireguard-tools
Provides: bundled(python3dist(transitions)) = 0.9.3
```
Expand All @@ -110,7 +118,7 @@ CI installs every package in a clean container before a release is signed
=== "Arch Linux (PKGBUILD)"

```text
depends=('python>=3.12' 'python-typer' 'python-rich' 'python-stem' 'python-six' 'nftables' 'tor')
depends=('python>=3.12' 'python-typer' 'python-rich' 'python-stem' 'python-six' 'nftables' 'tor' 'polkit')
```

`transitions` is only in the AUR, so the PKGBUILD bundles it the same way as the
Expand Down
19 changes: 19 additions & 0 deletions docs/web/release-notes/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- The `.deb`, `.rpm` and PKGBUILD did not depend on polkit. Each creates the
`ttp-watchdog` account, so the watchdog runs as that account and restarts a
stopped or crashed Tor through polkit (`50-ttp-watchdog.rules`), and only
polkit's daemon reads that rule. Without it, systemd answered "Access denied"
(measured on Debian 13), the heal failed, and the watchdog engaged the
emergency killswitch. Nothing leaked, but a Tor restart left the host with no
network until the user intervened. This happens on hosts without polkit, such
as servers and minimal installs; desktops usually have it. The packages now
depend on `polkitd` (Debian/Ubuntu) or `polkit` (Fedora, Arch).

- `ttp start` interrupted with Ctrl-C or SIGTERM before it recorded its session
undid nothing and exited `0`. It printed "Signal received, restoring
network...", but the nftables table, the DNS overlay and the managed Tor
Expand All @@ -30,6 +40,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Tests

- `scripts/vm/lifecycle/heal.sh` installs the `.deb` in a Debian 13 VM, where
the watchdog runs as `ttp-watchdog` as it does for anyone who installs a
package. It stops `ttp-tor` and requires the watchdog to restart it without a
killswitch. As a control, the same fault with polkit masked must end in the
killswitch. The other VM jobs install with pip, where the watchdog runs as
root, and the chaos sweep counts a killswitch as contained, so neither could
see the missing dependency below. The package smoke tests now also require
the account, polkitd and a readable rule.

- The lifecycle VM judges its phases with NSE 2.6.0, and the `nse` extra
requires `network-sandbox-engine>=2.6.0`. In the guest, NSE's stimulus streams
run as the non-bypassed user between two beacons that carry the guest's clocks.
Expand Down
4 changes: 3 additions & 1 deletion packaging/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ license=('MIT')
optdepends=('networkmanager: required VPN mode' 'wireguard-tools: required VPN mode'
'apparmor: required for managed Tor when the kernel selects AppArmor')

depends=('python>=3.12' 'python-typer' 'python-rich' 'python-stem' 'python-six' 'nftables' 'tor')
# polkit: its daemon reads 50-ttp-watchdog.rules, which lets ttp-watchdog
# restart ttp-tor; without it the watchdog's Tor heal is refused.
depends=('python>=3.12' 'python-typer' 'python-rich' 'python-stem' 'python-six' 'nftables' 'tor' 'polkit')

# Build dependencies. These are only needed temporarily while creating the package.
# python-hatchling is the build backend; with --no-isolation it must be installed.
Expand Down
2 changes: 1 addition & 1 deletion packaging/build_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Section: net
Priority: optional
Homepage: https://github.com/onyks-os/TransparentTorProxy
License: MIT
Depends: python3 (>= 3.12), python3-typer, python3-rich (>= 13.7.1), python3-stem, python3-transitions (>= 0.9.0), nftables, tor, apparmor
Depends: python3 (>= 3.12), python3-typer, python3-rich (>= 13.7.1), python3-stem, python3-transitions (>= 0.9.0), nftables, tor, apparmor, polkitd
Suggests: network-manager, wireguard-tools
Description: Transparent Tor Proxy
A Linux CLI tool that transparently routes all system traffic through the Tor network.
Expand Down
4 changes: 4 additions & 0 deletions packaging/smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ python3 -c "import sys; from ttp.watchdog.fsm import load_machine; m = load_mach
# And everything ttp stop imports must import even so.
python3 -c "import ttp.commands.lifecycle, ttp.commands.stop_restart, ttp.watchdog"
echo "ok: teardown modules import"
getent passwd ttp-watchdog > /dev/null || { echo "FAIL: no ttp-watchdog account"; exit 1; }
test -x /usr/lib/polkit-1/polkitd || { echo "FAIL: polkitd is not installed, so the watchdog cannot restart ttp-tor"; exit 1; }
test -r /usr/share/polkit-1/rules.d/50-ttp-watchdog.rules || { echo "FAIL: no readable 50-ttp-watchdog.rules"; exit 1; }
echo "ok: ttp-watchdog account, polkitd and its rule"
'

stage="$(mktemp -d)"
Expand Down
3 changes: 3 additions & 0 deletions packaging/ttp.spec
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Requires: tor
Suggests: NetworkManager
Suggests: wireguard-tools
Requires: policycoreutils
# polkitd reads 50-ttp-watchdog.rules, which lets ttp-watchdog restart ttp-tor;
# without it the watchdog's Tor heal is refused and it trips the killswitch.
Requires: polkit
Requires: python3-six
Provides: bundled(python3dist(transitions)) = @@TRANSITIONS_VERSION@@

Expand Down
Loading