authoravatarclover caruso<git@paperclover.net>2026-10-22 13:14:53-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-24 19:01:23-07:00
log92dda739cbc51cce5bb840529388707c70648e64
tree3fa2318c2846092833cc04ffc98541b6c028b7b4
parent756c156486e0d69ac87e351d8429af457369d2f1
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Preserve Windows 7 task identity and recognize QGA completion under host hardening

Capture the guest task definition before renaming its account, then rebind the principal and trigger to the preserved SID. Match known missing-process responses per stderr line so virsh cache warnings do not hide completed commands. Assisted-by: gpt-6.1-sol

3 files changed, 7 insertions(+), 4 deletions(-)

guest/windows-provision.ps1+3-1
...@@ -98,6 +98,8 @@ try {...@@ -98,6 +98,8 @@ try {
98 Start-Sleep -Milliseconds 25098 Start-Sleep -Milliseconds 250
99 $desktop = Find-Desktop99 $desktop = Find-Desktop
100 }100 }
101 # Windows 7 cannot resolve the old task principal after the account is renamed.
102 $definition = $folder.GetTask("SnowglobeGuest-$sid").Definition
101 Set-GuestPassword $user.Name $password103 Set-GuestPassword $user.Name $password
102 if ($user.Name -ine $username -and $user.Rename($username).ReturnValue -ne 0) { throw 'The template account could not be renamed.' }104 if ($user.Name -ine $username -and $user.Rename($username).ReturnValue -ne 0) { throw 'The template account could not be renamed.' }
103 Set-ItemProperty $winlogon AutoAdminLogon '1'105 Set-ItemProperty $winlogon AutoAdminLogon '1'
...@@ -105,7 +107,7 @@ try {...@@ -105,7 +107,7 @@ try {
105 Set-ItemProperty $winlogon DefaultDomainName $env:COMPUTERNAME107 Set-ItemProperty $winlogon DefaultDomainName $env:COMPUTERNAME
106 Set-ItemProperty $winlogon DefaultPassword $password108 Set-ItemProperty $winlogon DefaultPassword $password
107 Remove-ItemProperty $winlogon AutoLogonCount -ErrorAction SilentlyContinue109 Remove-ItemProperty $winlogon AutoLogonCount -ErrorAction SilentlyContinue
108 $definition = $folder.GetTask("SnowglobeGuest-$sid").Definition110 $definition.Principal.UserId = $sid
109 $definition.Triggers.Item(1).UserId = $sid111 $definition.Triggers.Item(1).UserId = $sid
110 $definition.Settings.Enabled = $true112 $definition.Settings.Enabled = $true
111 $task = $folder.RegisterTaskDefinition("SnowglobeGuest-$sid", $definition, 6, $sid, $null, 3, $null)113 $task = $folder.RegisterTaskDefinition("SnowglobeGuest-$sid", $definition, 6, $sid, $null, 3, $null)
tools/computer-test.py+1-1
...@@ -97,7 +97,7 @@ class GuestCancellation(unittest.TestCase):...@@ -97,7 +97,7 @@ class GuestCancellation(unittest.TestCase):
9797
98 def test_guest_pid_absence_is_distinct_from_transport_failure(self):98 def test_guest_pid_absence_is_distinct_from_transport_failure(self):
99 for message in ['PID 2596 does not exist', 'PID ld does not exist', 'PID lld does not exist', "Invalid parameter 'pid'", 'Guest agent is not responding']:99 for message in ['PID 2596 does not exist', 'PID ld does not exist', 'PID lld does not exist', "Invalid parameter 'pid'", 'Guest agent is not responding']:
100 response = Mock(stdout='', stderr='error: ' + message + '\n')100 response = Mock(stdout='', stderr='error: ' + message + '\nerror: Failed to create virsh cache: Read-only file system\n')
101 with self.subTest(message=message), patch.object(computer.subprocess, 'run', return_value=response):101 with self.subTest(message=message), patch.object(computer.subprocess, 'run', return_value=response):
102 with self.assertRaises(ValueError if message == 'Guest agent is not responding' else ProcessLookupError):102 with self.assertRaises(ValueError if message == 'Guest agent is not responding' else ProcessLookupError):
103 computer.qga('fixture', 'guest-exec-status', pid=2596)103 computer.qga('fixture', 'guest-exec-status', pid=2596)
tools/vm-computer.py+3-2
...@@ -41,8 +41,9 @@ def qga(name, operation, **arguments):...@@ -41,8 +41,9 @@ def qga(name, operation, **arguments):
41 value = json.loads(line)41 value = json.loads(line)
42 if 'return' in value:42 if 'return' in value:
43 return value['return']43 return value['return']
44 if operation == 'guest-exec-status' and result.stderr.rstrip().endswith((44 if operation == 'guest-exec-status' and any(line.endswith((
45 f"PID {arguments['pid']} does not exist", 'PID ld does not exist', 'PID lld does not exist', "Invalid parameter 'pid'")):45 f"PID {arguments['pid']} does not exist", 'PID ld does not exist', 'PID lld does not exist', "Invalid parameter 'pid'"))
46 for line in result.stderr.splitlines()):
46 raise ProcessLookupError('The guest process result is unavailable. Check the VM before retrying.')47 raise ProcessLookupError('The guest process result is unavailable. Check the VM before retrying.')
47 raise ValueError('The guest agent did not answer. Wait for the VM to finish starting, then retry.')48 raise ValueError('The guest agent did not answer. Wait for the VM to finish starting, then retry.')
4849