Skip to content

Commit

Permalink
Add test and validation for EFI SecureBoot
Browse files Browse the repository at this point in the history
Signed-off-by: Jed Lejosne <[email protected]>
  • Loading branch information
jean-edouard committed May 13, 2020
1 parent 9b5616c commit d77e932
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,20 @@ func validateFirmware(field *k8sfield.Path, firmware *v1.Firmware) []metav1.Stat

func validateDomainSpec(field *k8sfield.Path, spec *v1.DomainSpec) []metav1.StatusCause {
var causes []metav1.StatusCause

causes = append(causes, validateDevices(field.Child("devices"), &spec.Devices)...)
causes = append(causes, validateFirmware(field.Child("firmware"), spec.Firmware)...)

if spec.Firmware != nil && spec.Firmware.Bootloader != nil && spec.Firmware.Bootloader.EFI != nil &&
spec.Firmware.Bootloader.EFI.SecureBoot != nil && *spec.Firmware.Bootloader.EFI.SecureBoot &&
(spec.Features == nil || spec.Features.SMM == nil || !*spec.Features.SMM.Enabled) {
causes = append(causes, metav1.StatusCause{
Type: metav1.CauseTypeFieldValueInvalid,
Message: fmt.Sprintf("%s has EFI SecureBoot enabled. SecureBoot requires SMM, which is currently disabled.", field.String()),
Field: field.String(),
})
}

return causes
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/virt-launcher/virtwrap/api/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2176,10 +2176,28 @@ var _ = Describe("Converter", func() {
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)
Expect(domainSpec.OS.BootLoader.ReadOnly).To(Equal("yes"))
Expect(domainSpec.OS.BootLoader.Type).To(Equal("pflash"))
Expect(domainSpec.OS.BootLoader.Secure).To(Equal("no"))
Expect(domainSpec.OS.BootLoader.Path).To(Equal(EFIPath))
Expect(domainSpec.OS.NVRam.Template).To(Equal(EFIVarsPath))
Expect(domainSpec.OS.NVRam.NVRam).To(Equal("/tmp/mynamespace_testvmi"))
})

It("should configure the EFI bootloader if EFI secure option", func() {
vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{
SecureBoot: True(),
},
},
}
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)
Expect(domainSpec.OS.BootLoader.ReadOnly).To(Equal("yes"))
Expect(domainSpec.OS.BootLoader.Type).To(Equal("pflash"))
Expect(domainSpec.OS.BootLoader.Secure).To(Equal("yes"))
Expect(domainSpec.OS.BootLoader.Path).To(Equal(EFIPathSecureBoot))
Expect(domainSpec.OS.NVRam.Template).To(Equal(EFIVarsPathSecureBoot))
Expect(domainSpec.OS.NVRam.NVRam).To(Equal("/tmp/mynamespace_testvmi"))
})
})
})

Expand Down

0 comments on commit d77e932

Please sign in to comment.