fix: keep manual UEFI firmware selection

go
codex 1 month ago
parent 6461eb3d29
commit e155ccfc3b

@ -95,10 +95,9 @@ func BuildDomainXML(definition DomainDefinition) (string, error) {
NVRam: &libvirtxml.DomainNVRam{
NVRam: definition.Firmware.NVRAMPath, Template: definition.Firmware.NVRAMTemplate,
},
FirmwareInfo: &libvirtxml.DomainOSFirmwareInfo{Features: []libvirtxml.DomainOSFirmwareFeature{
{Name: "secure-boot", Enabled: "no"},
{Name: "enrolled-keys", Enabled: "no"},
}},
// FirmwareInfo is intentionally omitted. Its feature list is only
// valid with libvirt firmware autoselection, while this agent pins a
// host-validated loader and NVRAM template explicitly.
BootDevices: []libvirtxml.DomainBootDevice{{Dev: "hd"}},
},
Features: &libvirtxml.DomainFeatureList{

@ -49,7 +49,8 @@ func testPlatformPolicy() PlatformNetworkPolicySnapshot {
}
func TestBuildDomainXMLUsesQ35UEFIWithSecureBootDisabled(t *testing.T) {
document, err := BuildDomainXML(validDomainDefinition())
definition := validDomainDefinition()
document, err := BuildDomainXML(definition)
if err != nil {
t.Fatal(err)
}
@ -60,10 +61,10 @@ func TestBuildDomainXMLUsesQ35UEFIWithSecureBootDisabled(t *testing.T) {
if domain.OS == nil || domain.OS.Type == nil || domain.OS.Type.Machine != "q35" {
t.Fatalf("machine is not q35: %#v", domain.OS)
}
if domain.OS.Loader == nil || domain.OS.Loader.Type != "pflash" || domain.OS.Loader.Secure != "no" {
t.Fatalf("loader does not explicitly disable secure boot: %#v", domain.OS.Loader)
if domain.OS.Loader == nil || domain.OS.Loader.Path != definition.Firmware.Loader || domain.OS.Loader.Type != "pflash" || domain.OS.Loader.Readonly != "yes" || domain.OS.Loader.Secure != "no" {
t.Fatalf("loader does not pin the configured non-Secure-Boot pflash firmware: %#v", domain.OS.Loader)
}
if domain.OS.NVRam == nil || domain.OS.NVRam.Template == "" || domain.OS.NVRam.NVRam == "" {
if domain.OS.NVRam == nil || domain.OS.NVRam.Template != definition.Firmware.NVRAMTemplate || domain.OS.NVRam.NVRam != definition.Firmware.NVRAMPath {
t.Fatalf("NVRAM is incomplete: %#v", domain.OS.NVRam)
}
if domain.Features == nil || domain.Features.SMM == nil || domain.Features.SMM.State != "off" {
@ -92,12 +93,8 @@ func TestBuildDomainXMLUsesQ35UEFIWithSecureBootDisabled(t *testing.T) {
if domain.Devices.MemBalloon == nil || domain.Devices.MemBalloon.Model != "virtio" || domain.Devices.MemBalloon.FreePageReporting != "on" || domain.Devices.MemBalloon.Stats == nil || domain.Devices.MemBalloon.Stats.Period != 10 {
t.Fatalf("virtio balloon telemetry is incomplete: %#v", domain.Devices.MemBalloon)
}
features := map[string]string{}
for _, feature := range domain.OS.FirmwareInfo.Features {
features[feature.Name] = feature.Enabled
}
if features["secure-boot"] != "no" || features["enrolled-keys"] != "no" {
t.Fatalf("firmware features = %#v", features)
if domain.OS.Firmware != "" || domain.OS.FirmwareInfo != nil || strings.Contains(document, "<firmware>") {
t.Fatalf("manual firmware must not request autoselection features: %#v", domain.OS)
}
if strings.Contains(document, "escaped <description>") || !strings.Contains(document, "&lt;description&gt; &amp; safe") {
t.Fatalf("description was not XML escaped: %s", document)

@ -180,17 +180,14 @@ Gateway 在已认证控制通道发送 `console_open`,其中包含一次性 Ag
## UEFI 与 Secure Boot
`POST /v1/vms` 不接受 firmware mode、loader、NVRAM 路径或 Secure Boot 开关;所有新域固定为 UEFI 且 Secure Boot 关闭。运维在部署时依据本机 domain capabilities 选定 loader、NVRAM template 与目录,并把它们作为 Agent 本地固定配置。域为 `x86_64/q35`,XML 必须明确:
`POST /v1/vms` 不接受 firmware mode、loader、NVRAM 路径或 Secure Boot 开关;所有新域固定为 UEFI 且 Secure Boot 关闭。运维在部署时依据本机 domain capabilities 选定不启用 Secure Boot 的 loader、NVRAM template 与目录,并把它们作为 Agent 本地固定配置。域为 `x86_64/q35`,XML 使用手工固件路径:
```xml
<loader readonly="yes" secure="no" type="pflash">...</loader>
<firmware>
<feature enabled="no" name="secure-boot"/>
<feature enabled="no" name="enrolled-keys"/>
</firmware>
<nvram template="...">...</nvram>
```
SMM 不得为了 Secure Boot 被隐式开启。宿主机不支持所选组合时明确拒绝,不能回退 BIOS 或硬编码另一个发行版的 OVMF 路径。
手工指定 loader/NVRAM 时不得再生成仅适用于 `os firmware='efi'` 自动选择模式的 `<firmware><feature/></firmware>` 列表;两种模式混用会被 libvirt 拒绝。`loader secure="no"` 表示所选固件不具备 Secure Boot 能力,实际路径还必须由宿主机配置固定为非 Secure Boot 固件。SMM 不得为了 Secure Boot 被隐式开启。宿主机不支持所选组合时明确拒绝,不能回退 BIOS 或硬编码另一个发行版的 OVMF 路径。
## 云镜像首次启动脚本

@ -74,7 +74,7 @@ Unix 时间戳
## 虚拟机、镜像与启动脚本
- 域 XML 使用结构化类型生成并验证输入,所有变更按 UUID 定位。部署每台宿主机时先查询 domain capabilities,把该机支持的 Q35/EFI loader 与 NVRAM template 写入本机 Agent 配置;创建请求不能传入任意固件路径。域 XML 明确关闭 `secure-boot` 和 enrolled keys,不在 PHP 中硬编码单一发行版 OVMF 路径。
- 域 XML 使用结构化类型生成并验证输入,所有变更按 UUID 定位。部署每台宿主机时先查询 domain capabilities,把该机支持且不启用 Secure Boot 的 Q35/EFI loader 与 NVRAM template 写入本机 Agent 配置;创建请求不能传入任意固件路径。Agent 使用手工 loader/NVRAM XML 并保持 `secure="no"`、`SMM=off`,不混入只适用于固件自动选择的 feature 列表,也不在 PHP 中硬编码单一发行版 OVMF 路径。
- Agent 配置使用 `revision`/`tested_revision` 就绪门闩。保存密钥、启用状态或宿主机 `default_network` 会推进 revision 并将 `tested_revision` 清零;只有同一 revision 经已认证出站会话完成 `/v1/health` 与 `/v1/capabilities`,且 `default_network` 精确存在于 Agent 上报的可用 `network_selectors`,才记录为就绪。调度、Agent 客户端以及控制台路径均要求 `enabled=1`、`last_test_status=healthy` 且 `tested_revision=revision`。
- 云镜像由 PHP 保存目录元数据和启动脚本。创建任务快照镜像 generation、revision 和脚本正文后签名发送给目标 Agent;删除后重新导入的同名镜像不能继承旧脚本。
- 启动脚本仅用于新云镜像实例的首次安装,不用于普通重启、网络设置、重装、救援或用户 ISO。脚本限制 32 KiB UTF-8,拒绝 NUL,CRLF 规范化为 LF,空值表示禁用。

@ -277,3 +277,19 @@ PHP tests: CloudAdminOperationsService、CloudAgentProtocol、CloudFinancialWork
artifact inspection: 两个文件均为 ELF 64-bit x86-64,未嵌入本机路径或部署端点;Agent 最低检测到 GLIBC_2.14,运行时需要 libvirt.so.0
known skips or risks: 二进制需部署到面板与宿主机后,再以一次受控创建取得新的 cause_code 并完成真实 libvirt 生命周期验收
```
### 2026-10-16 手工 UEFI 固件模式修复验收
```text
commit: 本记录所在 go 分支源码提交(基线 6461eb3)
Go version / libvirt version: Go 1.27.1 / 本机 libvirt 12.8.0
go vet: Agent 默认构建通过
go test: Agent 默认及 libvirt+libvirt_dlopen 全量通过;hypervisor 定向回归通过
go test -race: Agent libvirt+libvirt_dlopen 全量通过
go mod verify / tidy -diff: 均通过且无变更
Linux AMD64 build: Zig 交叉编译预检通过;linux/amd64、CGO_ENABLED=1、tags=libvirt,libvirt_dlopen,最低 GLIBC 符号版本 2.14
read-only host diagnosis: 103 宿主机 libvirt 日志对失败创建明确报告 `cannot use feature-based firmware autoselection when firmware autoselection is disabled`
XML contract: 手工 loader/NVRAM 模式不再生成仅适用于 `os firmware='efi'` 自动选择的 firmware feature;测试精确锁定配置 loader、readonly=yes、pflash、secure=no、NVRAM template/path、SMM=off
authorized host mutation test: 未重放旧 operation_id,未重新提交付费创建,未注册测试域
known skips or risks: schema 校验不能捕获本次 libvirt 语义互斥;发布后二进制仍须先在 103 执行只读 domxml-to-native,再由用户即时确认一次受控付费创建
```

Loading…
Cancel
Save