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
log67a75449a270804854c5cdae4b2b6a83c1fcd234
tree3cc559f709b1bba508b887ad854afb1a72a17a82
parent298b2bc858305fc0316d44c33e0961d0fb242ce8
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Preserve EFI state in prepared VM clones

Keep signed EFI variables with the prepared disk when saving and cloning secure UEFI presets. A fresh variable store can trigger the upstream OpenSSL runtime address-map bug during Windows signed-variable updates: https://github.com/tianocore/edk2/issues/9769 The save/create regression also checks that clone credentials remain independent. Assisted-by: gpt-6.1-sol

2 files changed, 48 insertions(+), 3 deletions(-)

tools/dashboard-vms-test.py+43
...@@ -22,6 +22,49 @@ spec.loader.exec_module(host)...@@ -22,6 +22,49 @@ spec.loader.exec_module(host)
2222
2323
24class VMTests(unittest.TestCase):24class VMTests(unittest.TestCase):
25 def test_secure_preset_retains_efi_state_but_generates_new_login(self):
26 with tempfile.TemporaryDirectory() as temporary:
27 root = Path(temporary).resolve()
28 disks = root / 'vms'
29 source = disks / 'template'
30 source.mkdir(parents=True)
31 (source / 'disk.qcow2').write_bytes(b'prepared disk')
32 (source / 'nvram.fd').write_bytes(b'prepared signed EFI variables')
33 code = root / 'code.fd'
34 code.write_bytes(b'firmware')
35 defaults = root / 'vars.fd'
36 defaults.write_bytes(b'fresh EFI variables')
37 xml = f'''<domain><metadata><vm xmlns="{vms.NS[1:-1]}">
38 <platform>windows</platform><hardwareProfile>windows-aarch64-nvme</hardwareProfile>
39 </vm></metadata><memory>8388608</memory><vcpu>4</vcpu>
40 <os><type arch="aarch64">hvm</type><loader>{code}</loader><nvram>{source / 'nvram.fd'}</nvram></os>
41 <devices><disk device="disk"><source file="{source / 'disk.qcow2'}"/></disk></devices></domain>'''
42 def command(*args, **kwargs):
43 if args[0] == 'cp':
44 with os.fdopen(os.dup(int(args[-2].split('/')[-1])), 'rb') as incoming:
45 Path(args[-1]).write_bytes(incoming.read())
46 elif args[:2] == ('qemu-img', 'convert'):
47 Path(args[-1]).write_bytes(Path(args[-2]).read_bytes())
48 return json.dumps({'format': 'qcow2', 'virtual-size': 1024, 'format-specific': {'data': {}}})
49 def virsh(*args, **kwargs):
50 return {'domstate': 'shut off', 'dumpxml': xml, 'pool-list': 'vms', 'pool-info': 'State: active'}.get(args[0], '')
51 with patch.object(vms, 'DISKS', disks), patch.object(vms, 'PRESETS', root / 'presets'), \
52 patch.object(vms, 'command', side_effect=command), patch.object(vms, 'virsh', side_effect=virsh), \
53 patch.object(vms, 'secure_firmware', return_value=(code, defaults)), \
54 patch.dict(os.environ, {'SNOWGLOBE_VM_WINDOWS_ARM_EMULATOR': '/qemu-system-aarch64'}):
55 vms.save_preset({'name': 'template', 'id': 'prepared', 'os': 'Windows 11 Pro ARM64',
56 'description': '', 'setup': 'windows-v4'})
57 for name in ['first', 'second']:
58 vms.create({'name': name, 'description': '', 'image': 'prepared', 'mode': 'preset',
59 'owner': 'fixture', 'username': name, 'vcpus': 4, 'memory': 8 * 2**30,
60 'disk': 1024, 'start': False, 'autostart': False})
61 self.assertEqual((disks / name / 'nvram.fd').read_bytes(), (source / 'nvram.fd').read_bytes())
62 first = json.loads((disks / 'first' / 'access.json').read_text())
63 second = json.loads((disks / 'second' / 'access.json').read_text())
64 self.assertNotEqual(first['password'], second['password'])
65 self.assertEqual(first['username'], 'first')
66 self.assertEqual(second['username'], 'second')
67
25 def test_windows_setup_closes_milestone_files(self):68 def test_windows_setup_closes_milestone_files(self):
26 for stage in ['ready', 'failed', 'restarting', 'personalizing']:69 for stage in ['ready', 'failed', 'restarting', 'personalizing']:
27 def reply(action, name, payload, *args):70 def reply(action, name, payload, *args):
tools/vms.py+5-3
...@@ -585,10 +585,10 @@ def save_preset(spec):...@@ -585,10 +585,10 @@ def save_preset(spec):
585 hardware_profile = inferred_profile(root)585 hardware_profile = inferred_profile(root)
586 type_element = os_element.find("type")586 type_element = os_element.find("type")
587 arch = type_element.get("arch", "x86_64")587 arch = type_element.get("arch", "x86_64")
588 details_profile = checked_profile(hardware_profile, platform, firmware, arch)588 checked_profile(hardware_profile, platform, firmware, arch)
589 # Persistent firmware variables are needed for installers that only register an EFI boot entry.589 # Boot entries and signed EFI variables belong to the prepared image.
590 nvram = root.findtext("./os/nvram")590 nvram = root.findtext("./os/nvram")
591 if nvram and not details_profile.get("secure"):591 if nvram:
592 with os.fdopen(open_regular(Path(nvram)), "rb") as incoming, (temporary / "nvram.fd").open("xb") as outgoing:592 with os.fdopen(open_regular(Path(nvram)), "rb") as incoming, (temporary / "nvram.fd").open("xb") as outgoing:
593 shutil.copyfileobj(incoming, outgoing)593 shutil.copyfileobj(incoming, outgoing)
594 preset = {"id": spec["id"], "os": spec["os"], "description": spec["description"],594 preset = {"id": spec["id"], "os": spec["os"], "description": spec["description"],
...@@ -836,6 +836,8 @@ def create(spec, *, ai=False):...@@ -836,6 +836,8 @@ def create(spec, *, ai=False):
836 if firmware == "uefi":836 if firmware == "uefi":
837 if details_profile.get("secure"):837 if details_profile.get("secure"):
838 code, variables = secure_firmware(details_profile["arch"])838 code, variables = secure_firmware(details_profile["arch"])
839 if preset and (PRESETS / selected / "nvram.fd").exists():
840 variables = PRESETS / selected / "nvram.fd"
839 nvram = directory / "nvram.fd"841 nvram = directory / "nvram.fd"
840 copy_regular(variables, nvram)842 copy_regular(variables, nvram)
841 loader = ET.SubElement(os_element, "loader", readonly="yes", type="pflash")843 loader = ET.SubElement(os_element, "loader", readonly="yes", type="pflash")