From 92dda739cbc51cce5bb840529388707c70648e64 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Thu, 22 Oct 2026 13:14:53 -0700 Subject: [PATCH] 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 --- guest/windows-provision.ps1 | 4 +++- tools/computer-test.py | 2 +- tools/vm-computer.py | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/guest/windows-provision.ps1 b/guest/windows-provision.ps1 index 853b3f4ff3110360225882487865fc0bf475214f..14d34b3a47d8346683f566b758c04d645c36ebe8 100644 --- a/guest/windows-provision.ps1 +++ b/guest/windows-provision.ps1 @@ -98,6 +98,8 @@ try { Start-Sleep -Milliseconds 250 $desktop = Find-Desktop } + # Windows 7 cannot resolve the old task principal after the account is renamed. + $definition = $folder.GetTask("SnowglobeGuest-$sid").Definition Set-GuestPassword $user.Name $password if ($user.Name -ine $username -and $user.Rename($username).ReturnValue -ne 0) { throw 'The template account could not be renamed.' } Set-ItemProperty $winlogon AutoAdminLogon '1' @@ -105,7 +107,7 @@ try { Set-ItemProperty $winlogon DefaultDomainName $env:COMPUTERNAME Set-ItemProperty $winlogon DefaultPassword $password Remove-ItemProperty $winlogon AutoLogonCount -ErrorAction SilentlyContinue - $definition = $folder.GetTask("SnowglobeGuest-$sid").Definition + $definition.Principal.UserId = $sid $definition.Triggers.Item(1).UserId = $sid $definition.Settings.Enabled = $true $task = $folder.RegisterTaskDefinition("SnowglobeGuest-$sid", $definition, 6, $sid, $null, 3, $null) diff --git a/tools/computer-test.py b/tools/computer-test.py index b5b84adbd6d88e757c7dc1fb46d7f3adff190f2c..2f96176092806460b2ddd6e1175e13c6201de77d 100644 --- a/tools/computer-test.py +++ b/tools/computer-test.py @@ -97,7 +97,7 @@ class GuestCancellation(unittest.TestCase): def test_guest_pid_absence_is_distinct_from_transport_failure(self): 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']: - response = Mock(stdout='', stderr='error: ' + message + '\n') + response = Mock(stdout='', stderr='error: ' + message + '\nerror: Failed to create virsh cache: Read-only file system\n') with self.subTest(message=message), patch.object(computer.subprocess, 'run', return_value=response): with self.assertRaises(ValueError if message == 'Guest agent is not responding' else ProcessLookupError): computer.qga('fixture', 'guest-exec-status', pid=2596) diff --git a/tools/vm-computer.py b/tools/vm-computer.py index c80cd29019bf46b6b21ab09ae543b256f74015f7..37df08f13a8998d782ff8c37544babd1303784ae 100644 --- a/tools/vm-computer.py +++ b/tools/vm-computer.py @@ -41,8 +41,9 @@ def qga(name, operation, **arguments): value = json.loads(line) if 'return' in value: return value['return'] - if operation == 'guest-exec-status' and result.stderr.rstrip().endswith(( - f"PID {arguments['pid']} does not exist", 'PID ld does not exist', 'PID lld does not exist', "Invalid parameter 'pid'")): + if operation == 'guest-exec-status' and any(line.endswith(( + f"PID {arguments['pid']} does not exist", 'PID ld does not exist', 'PID lld does not exist', "Invalid parameter 'pid'")) + for line in result.stderr.splitlines()): raise ProcessLookupError('The guest process result is unavailable. Check the VM before retrying.') raise ValueError('The guest agent did not answer. Wait for the VM to finish starting, then retry.') -- 2.54.1