Exit nodes on macOS: pf anchor for offering, routes plus route-to for using
The exit-node host rules existed only for Linux (iptables + policy routing); macOS reported "only supported on Linux yet". Offering: a pf anchor com.apple/tsunagi-exit-<if> (evaluated by the stock pf.conf) holds a nat rule per offered range and a pass-in rule. pf is enabled if needed and the pfctl -E reference is released when the rules are removed. net.inet.ip.forwarding is only read, never written, as on Linux. Using: macOS has no uidrange policy routing and the agent is root, so the overlay gets 0.0.0.0/1 and 128.0.0.0/1 routes and a pf route-to rule (matched by the agent's uid) sends the agent's own QUIC/relay traffic back out the physical interface, translated to its address. The rules are loaded before the routes, so a failed load never sends traffic into a tunnel it cannot exempt the agent from. IPv6 is blocked with rejecting ::/1 and 8000::/1 routes. ExitHostPlan gains `overlay` (every network range) for the route-to exemption; Linux ignores it. Known limits: the egress is the default route's interface at apply time; other root processes also bypass the tunnel. Forwarding hints in the CLI and tray name the macOS sysctl. The rule text and command order are unit-tested with a scripted host; nothing was run against a live pf/route (needs root), so the route-to + nat second-pass behaviour is unverified. Checks: cargo fmt --check, cargo clippy --locked --workspace --all-targets -D warnings and cargo test --locked --workspace --all-targets, run on macOS only. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0cfc1cbafc
commit
47c5d38d0c
9 files changed
+1028
-13
No files matched your search
@@ -59,6 +59,27 @@ be an exit node in one network and not in another.
|
||||
specific IPv6 routes keep working, and so does the agent's own IPv6. A host
|
||||
with no IPv6 has nothing to block and is left alone.
|
||||
|
||||
## macOS
|
||||
|
||||
macOS has no `iptables` and no per-user policy routing, so the same behaviour
|
||||
is built from `pf` and `route`. The agent runs as root there.
|
||||
|
||||
- **Offering:** a `pf` anchor `com.apple/tsunagi-exit-<interface>` (the stock
|
||||
`/etc/pf.conf` already evaluates `com.apple/*`) holds
|
||||
`nat on <egress> from <range> to any -> (<egress>)` and a `pass in` rule.
|
||||
`pf` is enabled if it was off, and that reference is released when the rules
|
||||
go. Forwarding is only read: `sudo sysctl -w net.inet.ip.forwarding=1`, which
|
||||
macOS forgets at reboot. The egress is the default route's interface **at the
|
||||
time the rules are applied**; after it changes (Wi-Fi to Ethernet) switch the
|
||||
offer off and on.
|
||||
- **Using:** `0.0.0.0/1` and `128.0.0.0/1` routes through the overlay interface,
|
||||
and a `pf` `route-to` rule that sends the agent's own traffic (matched by its
|
||||
user id, root) back out the physical interface, with translation to that
|
||||
interface's address. Anything else you run as root also bypasses the tunnel.
|
||||
IPv6 is blocked with rejecting `::/1` and `8000::/1` routes.
|
||||
- Not verified on a live host when this was written: run `tsng exit-node` and
|
||||
check `sudo pfctl -a com.apple/tsunagi-exit-utunN -s rules -s nat`.
|
||||
|
||||
## What it does not do
|
||||
|
||||
- **The agent must run as a system service** (its own user). The uid exemption
|
||||
|
||||
Reference in new issue
Block a user