refactor: users single-point

This commit is contained in:
fufsob committed 2026-09-29 05:39:33 +00:00
1 parent c8b9b3de46
commit a4752049ef
35 files changed
+1009 -381

No files matched your search

+7 -2
View File
@@ -364,7 +364,8 @@ def _warp_unit():
def _tor_control(*commands):
"""Replies to commands on Tor's control socket, one list of lines per command.
The socket authenticates by who can open it: root and the userControl group.
The socket authenticates by who can open it: root, and Tor's own user. Not the
userControl group, which could publish any loopback port as an onion service with it.
"""
path = env("TOR_CONTROL_SOCKET", f"{runtime_dir()}/proxy-suite-tor/control/socket")
replies = []
@@ -413,7 +414,11 @@ def cmd_tor(verb="status", *args):
if verb == "newnym":
if not svc_exists(unit):
die("tor is not enabled in this configuration.")
_tor_control("SIGNAL NEWNYM")
if env("PRIVILEGED") == "1" and os.geteuid() != 0:
# The group's way in, polkit's "services" scope: a root unit that asks Tor.
must("start", "proxy-suite-tor-newnym.service")
else:
_tor_control("SIGNAL NEWNYM")
print("New connections take new circuits (Tor allows this once every 10 seconds).")
return
if verb not in ("status", "on", "off", "toggle", "restart"):
+10
View File
@@ -1301,6 +1301,16 @@ class TorTest(EnvTest):
self.thread.join(5)
self.assertEqual(self.received, ["AUTHENTICATE", "SIGNAL NEWNYM"])
def test_newnym_as_the_group_goes_through_the_unit(self):
"""On a system install only root opens the socket: the group starts a root unit."""
os.environ["PRIVILEGED"] = "1"
started = []
self.patch("systemctl", lambda *a, **kw: started.append(a) or (0, None))
with mock.patch.object(ctl.os, "geteuid", return_value=1000):
ok(ctl.cmd_tor, "newnym")
self.assertIn(("start", "proxy-suite-tor-newnym.service"), started)
self.assertEqual(self.received, [])
def test_not_running(self):
os.environ["TOR_CONTROL_SOCKET"] = "missing"
status, _, err = run(ctl.cmd_tor, "newnym")
+14 -5
View File
@@ -26,14 +26,23 @@ pkgs.buildGo126Module (finalAttrs: {
"headless/dion-joiner"
"headless/bitrix-joiner"
];
# The local proxy's password from the environment, not argv: a creator runs for good,
# and every local user reads its command line.
# The call link (WB_LINK) and the local proxy's password (WB_UPSTREAM_PASS) from the
# environment, not argv: these run for good, and every local user reads a command line.
postPatch = ''
envDefault() {
substituteInPlace "headless/$1/main.go" --replace-fail \
"flag.String(\"$2\", \"\"," "flag.String(\"$2\", os.Getenv(\"$3\"),"
}
for p in vk telemost wbstream dion bitrix; do
substituteInPlace headless/$p/main.go --replace-fail \
'flag.String("upstream-pass", "",' \
'flag.String("upstream-pass", os.Getenv("WB_UPSTREAM_PASS"),'
envDefault $p upstream-pass WB_UPSTREAM_PASS
done
for p in bitrix dion dion-joiner wbstream wbstream-joiner; do
envDefault $p room WB_LINK
done
envDefault bitrix-joiner link WB_LINK
envDefault telemost tm-link WB_LINK
envDefault telemost-joiner tm-link WB_LINK
envDefault vk vk-link WB_LINK
'';
ldflags = [
"-s"