Privilege split 7/11: launch the LLM servers as plain child processes

- kurgan/ai/launcher.py: the app is unelevated now, so the servers are
  started with CreateProcessW, still suspended into their own kill-on-close
  job object and with an explicit handle list (only the log and NUL are
  inherited). Gone: the copy of Explorer's token (CreateProcessWithTokenW),
  the Safer "normal user" token and CreateProcessAsUserW, and with them the
  AI service's wait for the desktop at logon.
- launch() refuses (PermissionError) if The Kurgan itself is elevated, rather
  than pass admin rights on to a model server; this also covers opening the
  browser.
- Tests: the handle list is checked for real (an inheritable, unlisted handle
  doesn't reach the child; a control run without the list leaks it), and an
  elevated app starts nothing. The launch tests skip when the suite itself
  runs elevated.
- The UI's server token label and the README's launcher paragraph follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
paulandClaude Opus 5.5 committed 2026-12-05 19:44:47 +13:00
1 parent eb771656fb
commit e583e25346
5 files changed
+76 -168

No files matched your search

+32
View File
@@ -1,4 +1,6 @@
import msvcrt
import os
import sys
import tempfile
import threading
import unittest
@@ -382,7 +384,11 @@ class StrataLogRotationTest(unittest.TestCase):
self.assertEqual(log.read(), "previous run")
ELEVATED = launcher.token_info()["elevated"]
class LauncherTest(unittest.TestCase):
@unittest.skipIf(ELEVATED, "the launcher refuses to run elevated")
def test_child_runs_as_a_normal_user_with_its_output_logged(self):
with tempfile.TemporaryDirectory() as directory:
log_path = os.path.join(directory, "logs", "child.log")
@@ -395,6 +401,32 @@ class LauncherTest(unittest.TestCase):
with open(log_path, encoding="utf-8", errors="replace") as f:
self.assertIn("hello from the child", f.read())
@unittest.skipIf(ELEVATED, "the launcher refuses to run elevated")
def test_only_the_log_and_nul_are_inherited(self):
# The child names the file behind a handle number of ours that is inheritable but not listed.
script = ("import ctypes, sys; b = ctypes.create_unicode_buffer(1024); "
"n = ctypes.windll.kernel32.GetFinalPathNameByHandleW(ctypes.c_void_p(int(sys.argv[1])), b, 1024, 0); "
"print(b.value if n else 'no such handle')")
with tempfile.TemporaryDirectory() as directory:
log_path = os.path.join(directory, "child.log")
with open(os.path.join(directory, "secret.txt"), "w") as f:
handle = msvcrt.get_osfhandle(f.fileno())
os.set_handle_inheritable(handle, True)
child = launcher.launch([sys._base_executable, "-I", "-c", script, str(handle)], directory, log_path)
try:
self.assertEqual(child.wait(30), 0)
finally:
child.close()
with open(log_path, encoding="utf-8") as f:
self.assertNotIn("secret.txt", f.read())
def test_an_elevated_kurgan_starts_nothing(self):
with patch.object(launcher, "elevated", return_value=True), tempfile.TemporaryDirectory() as directory:
with self.assertRaises(PermissionError) as raised:
launcher.launch(["cmd.exe", "/d", "/c", "exit 0"], directory, None)
self.assertIn("admin rights", str(raised.exception))
@unittest.skipIf(ELEVATED, "the launcher refuses to run elevated")
def test_kill_ends_the_whole_job(self):
with tempfile.TemporaryDirectory() as directory:
child = launcher.launch(["cmd.exe", "/d", "/c", "ping -n 30 127.0.0.1"], directory, None)