engine: run tor as the tor user on Arch with reliable start/stop#198
Open
UncleJ4ck wants to merge 1 commit into
Open
engine: run tor as the tor user on Arch with reliable start/stop#198UncleJ4ck wants to merge 1 commit into
UncleJ4ck wants to merge 1 commit into
Conversation
ab5a1d9 to
6eadd0b
Compare
6eadd0b to
5689168
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was a problem?
On Arch,
.configs/arch-torrcnever setUser, sotor -fran as root. The OUTPUT rules pass tor's own traffic with-m owner --uid-owner tor -j RETURN, which never matches a root-owned tor, so tor's connections to its guards were redirected back into its own TransPort and it never bootstrapped. Nothing was torified. Every other distro config (debian, fedora, opensuse, void) already pinsUser; arch was the only one missing it.Three more issues surfaced in the same path:
Startlaunched tor withtor -fand then also ransystemctl start tor, a second instance with no TransPort, whileStoponly ransystemctl stop tor. Thetor -fdaemon was left running, kept 9051/9061, and broke the nextstart.Stopflushed the OUTPUT chain and left it empty, dropping any firewall the user already had.How this PR fixes the problem?
User torand matches the other configs (DataDirectory, ClientOnly, PidFile, control socket).tor -f, stopped via its pid file. No systemctl double-launch, no orphan.Startsnapshots the firewall andStoprestores it, paired with an explicit OUTPUT flush, because aniptables-savetaken before any rule exists is empty on nft and restore alone would leave nipe's rules in place.FindBin; tor runtime and log dirs are created with the right owner and a private (0700) control-socket dir (on Arch neither/run/tornor/var/log/torexists outside the systemd unit, whichtor -fbypasses); non-loopback IPv6 is rejected.build_rulesis split into a pure function so the firewall policy is unit testable.Check lists (check
xin[ ]of list items)Additional Comments (if any)
t/20-rules.tasserts the rule set and, specifically, that the owner RETURN precedes the catch-all REDIRECT, the ordering this fix depends on.Runtime verification (privileged containers):
nipe statusreportsIsTor: truewith a real exit IP,nipe newnymrotates it,nipe stopremoves the rules..perlcriticrc(via theghcr.io/natanlao/criticimage).Not runtime tested by me: Void, Fedora, openSUSE, CentOS (same
tor -fcode path, covered by the per-distro CI smoke workflows), the IPv6 reject path, and bare hardware.Two behaviour changes worth noting: rules are applied before tor comes up, so
startis fail-closed (nothing leaves until tor is up; if tor cannot start, runstopto restore connectivity).startalso flushes conntrack, which drops connections opened before nipe started so they re-establish through tor.