From 38232d1d522b2c555b7ccf5fd3d84499829fb64e Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 17 Nov 2026 00:33:39 -0800 Subject: [PATCH] Report VM command identity, elevation and CPU acceleration Report the actual Windows token elevation and desktop session, or Unix UID/GID and account name, without changing execution privileges. Distinguish hardware accelerated libvirt domains from emulated domains in status, including when stopped. Verified Linux identity against id, Windows elevated and least-privilege tokens against actual command integrity labels, and an isolated stopped emulated domain. 43 protocol tests, 28 VM boundary tests, 61 Rust tests and the OAuth client integration pass. Assisted-by: gpt-6.1-sol --- dashboard/src/computer-tools.json | 4 ++-- guest/computer-windows.cs | 9 ++++++++- tools/mac-computer.py | 2 ++ tools/vm-computer.py | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dashboard/src/computer-tools.json b/dashboard/src/computer-tools.json index 8fd3f6584265d027bfad8c2a6102db629fe4426b..b40ae925ce85b28ff94c44c01b084fc81efa55aa 100644 --- a/dashboard/src/computer-tools.json +++ b/dashboard/src/computer-tools.json @@ -14,7 +14,7 @@ }, { "name": "computer_status", - "description": "Report VM power, command readiness, runtimes and desktop capabilities. Status and screenshots remain available during commands on Linux-hosted VMs. Use active_operation.id with computer_process to inspect or cancel an active operation. Available runtimes do not prove a particular command succeeded.", + "description": "Report VM power, command readiness, CPU acceleration, runtimes, execution context and desktop capabilities. Status and screenshots remain available during commands on Linux-hosted VMs. Use active_operation.id with computer_process to inspect or cancel an active operation. Available runtimes do not prove a particular command succeeded.", "inputSchema": { "type": "object", "properties": { @@ -339,7 +339,7 @@ }, { "name": "computer_exec", - "description": "Run a script in the VM’s logged-in desktop session. Runtimes come from computer_status: zsh/bash on Unix, PowerShell/cmd/AutoHotkey v2 on Windows. Default uses the platform shell. AHK sets Mouse/Pixel CoordMode to Screen; SendText types literal text and FileAppend(text,\"*\") writes stdout. Returns bounded stdout/stderr, exit status, timeout state and optional screenshot. Timeout stops the command group; effects already performed remain. Use computer_spawn for persistent apps.", + "description": "Run a script in the VM’s logged-in desktop session. Runtimes come from computer_status: zsh/bash on Unix, PowerShell/cmd/AutoHotkey v2 on Windows. Default uses the platform shell. Windows uses the desktop account's highest available privileges; check execution_context in computer_status. AHK sets Mouse/Pixel CoordMode to Screen; SendText types literal text and FileAppend(text,\"*\") writes stdout. Returns bounded stdout/stderr, exit status, timeout state and optional screenshot. Timeout stops the command group; effects already performed remain. Use computer_spawn for persistent apps.", "inputSchema": { "type": "object", "properties": { diff --git a/guest/computer-windows.cs b/guest/computer-windows.cs index 88349cd3c1fd7e1bff75c877c2dc76ce73b81785..0aa0dc5c79c8446193ec2887f6851e2f8515904d 100644 --- a/guest/computer-windows.cs +++ b/guest/computer-windows.cs @@ -121,6 +121,7 @@ public static class ComputerWorker { static string Text(System.Collections.Generic.Dictionary value, string key, string fallback = "") { return Convert.ToString(Get(value,key,fallback)); } static int Number(System.Collections.Generic.Dictionary value, string key, int fallback = 0) { return Convert.ToInt32(Get(value,key,fallback)); } [DllImport("user32.dll")] static extern bool SetProcessDPIAware(); + [DllImport("advapi32.dll",SetLastError=true)] static extern bool GetTokenInformation(IntPtr token,int informationClass,out int elevation,int length,out int returned); [STAThread] public static int Main(string[] args) { if(args.Length==2 && (args[0]=="--prepare" || args[0]=="--cleanup" || args[0]=="--release")) { try { @@ -269,7 +270,13 @@ public static class ComputerWorker { string action=Text(request,"action");string root=System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if(action=="status") { var runtimes=new System.Collections.Generic.List(new[]{"powershell","cmd"});if(System.IO.File.Exists(System.IO.Path.Combine(root,"AutoHotkey.exe")))runtimes.Add("ahk"); - return new {platform="windows",hostname=Environment.MachineName,runtimes=runtimes,capabilities=new[]{"shot","input","ui","ui_action","exec","spawn","process","file"},coordinate_units="screenshot_pixels",max_timeout_ms=180000}; + using(var identity=System.Security.Principal.WindowsIdentity.GetCurrent()) + using(var process=Process.GetCurrentProcess()) { + int elevation,returned; + if(!GetTokenInformation(identity.Token,20,out elevation,4,out returned))throw new System.ComponentModel.Win32Exception(); + return new {platform="windows",hostname=Environment.MachineName,runtimes=runtimes,capabilities=new[]{"shot","input","ui","ui_action","exec","spawn","process","file"},coordinate_units="screenshot_pixels",max_timeout_ms=180000, + execution_context=new {user=identity.Name,elevated=elevation!=0,session=process.SessionId}}; + } } if(action=="input") { var actions=(object[])Get(request,"actions");foreach(var value in actions) {var item=Map(value);if(Text(item,"type")!="text")throw new Exception("Use the VM console for pointer and key actions.");ComputerProcess.Type(Text(item,"text"));}return new {completed=actions.Length}; diff --git a/tools/mac-computer.py b/tools/mac-computer.py index 52906310985aa8bd13129036e9c341305aeda8db..1e1dcba75058c9c147facbf56004826ae0c08f5c 100644 --- a/tools/mac-computer.py +++ b/tools/mac-computer.py @@ -8,6 +8,7 @@ import shutil import stat import uuid import os +import pwd from pathlib import Path import selectors import signal @@ -277,6 +278,7 @@ def execute(request): except (ImportError, ValueError): permissions["accessibility"] = False return {"permissions": permissions, "hostname": os.uname().nodename, + "execution_context": {"user": pwd.getpwuid(os.geteuid()).pw_name, "uid": os.geteuid(), "gid": os.getegid(), "elevated": os.geteuid() == 0}, "platform": "macos" if MAC else "linux", "runtimes": [r for r in ("zsh","bash") if shutil.which(r)], "capabilities": ["shot","input","exec","spawn","process","file"] + (["ui","ui_action"] if permissions.get("accessibility") else []), "max_timeout_ms": 180000, "coordinate_units":"screenshot_pixels"} diff --git a/tools/vm-computer.py b/tools/vm-computer.py index 669a90170780d70169f2fc5a5ec444d4c76583f0..efce7c1f290c99e005c203fa820603bb4c3e9bc1 100644 --- a/tools/vm-computer.py +++ b/tools/vm-computer.py @@ -573,6 +573,7 @@ def handle(name, request, *, active_snapshot=None): power = vms.virsh('domstate',name,timeout=remaining(15)).strip() platform = root.findtext(f'metadata/{vms.NS}vm/{vms.NS}platform','linux') status = {'platform': platform, 'power_state': power, 'readiness': 'starting', + 'cpu_acceleration': {'kvm': 'hardware', 'qemu': 'emulated'}.get(root.get('type')), 'capabilities': ['shot', 'input'] if power == 'running' else [], 'runtimes': [], 'coordinate_units': 'screenshot_pixels'} if power != 'running': -- 2.54.1