Skip to content

Commit

Permalink
Add support for EFI SecureBoot.
Browse files Browse the repository at this point in the history
When SecureBoot is enabled:
- Pass the option to libvirt
- Use the SecureBoot-enabled OVMF roms (/usr/share/OVMF/OVMF_*.secboot.fd)

Signed-off-by: Jed Lejosne <[email protected]>
  • Loading branch information
jean-edouard committed May 13, 2020
1 parent 1b1045f commit 9b5616c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
8 changes: 7 additions & 1 deletion api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4818,7 +4818,13 @@
},
"v1.EFI": {
"description": "If set, EFI will be used instead of BIOS.",
"type": "object"
"type": "object",
"properties": {
"secureBoot": {
"description": "If set, SecureBoot will be enabled and the OVMF roms will be swapped for SecureBoot-enabled ones. Requires SMM to be enabled. Defaults to false",
"type": "boolean"
}
}
},
"v1.EmptyDiskSource": {
"description": "EmptyDisk represents a temporary disk which shares the vmis lifecycle.",
Expand Down
33 changes: 24 additions & 9 deletions pkg/virt-launcher/virtwrap/api/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const (
defaultIOThread = uint(1)
EFIPath = "/usr/share/OVMF/OVMF_CODE.fd"
EFIVarsPath = "/usr/share/OVMF/OVMF_VARS.fd"
EFIPathSecureBoot = "/usr/share/OVMF/OVMF_CODE.secboot.fd"
EFIVarsPathSecureBoot = "/usr/share/OVMF/OVMF_VARS.secboot.fd"
)

// +k8s:deepcopy-gen=false
Expand Down Expand Up @@ -702,17 +704,30 @@ func Convert_v1_VirtualMachine_To_api_Domain(vmi *v1.VirtualMachineInstance, dom
}

if vmi.Spec.Domain.Firmware.Bootloader != nil && vmi.Spec.Domain.Firmware.Bootloader.EFI != nil {
if vmi.Spec.Domain.Firmware.Bootloader.EFI.SecureBoot != nil && *vmi.Spec.Domain.Firmware.Bootloader.EFI.SecureBoot {
domain.Spec.OS.BootLoader = &Loader{
Path: EFIPathSecureBoot,
ReadOnly: "yes",
Secure: "yes",
Type: "pflash",
}

domain.Spec.OS.BootLoader = &Loader{
Path: EFIPath,
ReadOnly: "yes",
Secure: "no",
Type: "pflash",
}
domain.Spec.OS.NVRam = &NVRam{
NVRam: filepath.Join("/tmp", domain.Spec.Name),
Template: EFIVarsPathSecureBoot,
}
} else {
domain.Spec.OS.BootLoader = &Loader{
Path: EFIPath,
ReadOnly: "yes",
Secure: "no",
Type: "pflash",
}

domain.Spec.OS.NVRam = &NVRam{
NVRam: filepath.Join("/tmp", domain.Spec.Name),
Template: EFIVarsPath,
domain.Spec.OS.NVRam = &NVRam{
NVRam: filepath.Join("/tmp", domain.Spec.Name),
Template: EFIVarsPath,
}
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions staging/src/kubevirt.io/client-go/api/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ type BIOS struct {
//
// +k8s:openapi-gen=true
type EFI struct {
// If set, SecureBoot will be enabled and the OVMF roms will be swapped for
// SecureBoot-enabled ones.
// Requires SMM to be enabled.
// Defaults to false
// +optional
SecureBoot *bool `json:"secureBoot,omitempty"`
}

//
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b5616c

Please sign in to comment.