Skip to content

Commit

Permalink
Merge pull request kubevirt#3529 from jean-edouard/defaulttosb
Browse files Browse the repository at this point in the history
Enable Secure Boot by default when EFI is enabled
  • Loading branch information
kubevirt-bot authored Jun 21, 2020
2 parents d036d9d + aa144fe commit b8543ba
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6219,7 +6219,7 @@
"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",
"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 true",
"type": "boolean"
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/vmi-alpine-efi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ spec:
name: containerdisk
firmware:
bootloader:
efi: {}
efi:
secureBoot: false
machine:
type: ""
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ func validateDomainSpec(field *k8sfield.Path, spec *v1.DomainSpec) []metav1.Stat
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.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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2286,10 +2286,16 @@ var _ = Describe("Validating VMICreate Admitter", func() {
Expect(len(causes)).To(Equal(0))
})

It("should accept EFI", func() {
It("should accept EFI with SMM", func() {
vmi := v1.NewMinimalVMI("testvmi")
vmi.Spec.Subdomain = "testsubdomain"

_true := true
vmi.Spec.Domain.Features = &v1.Features{
SMM: &v1.FeatureState{
Enabled: &_true,
},
}
vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{},
Expand All @@ -2300,10 +2306,47 @@ var _ = Describe("Validating VMICreate Admitter", func() {
Expect(len(causes)).To(Equal(0))
})

It("should not accept EFI without SMM", func() {
vmi := v1.NewMinimalVMI("testvmi")
vmi.Spec.Subdomain = "testsubdomain"

vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{},
},
}

causes := ValidateVirtualMachineInstanceSpec(k8sfield.NewPath("fake"), &vmi.Spec, config)
Expect(len(causes)).To(Equal(1))
})

It("should accept EFI without secureBoot and without SMM", func() {
vmi := v1.NewMinimalVMI("testvmi")
vmi.Spec.Subdomain = "testsubdomain"

_false := false
vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{
SecureBoot: &_false,
},
},
}

causes := ValidateVirtualMachineInstanceSpec(k8sfield.NewPath("fake"), &vmi.Spec, config)
Expect(len(causes)).To(Equal(0))
})

It("should not accept BIOS and EFI together", func() {
vmi := v1.NewMinimalVMI("testvmi")
vmi.Spec.Subdomain = "testsubdomain"

_true := true
vmi.Spec.Domain.Features = &v1.Features{
SMM: &v1.FeatureState{
Enabled: &_true,
},
}
vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{},
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/api/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ 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 {
if vmi.Spec.Domain.Firmware.Bootloader.EFI.SecureBoot == nil || *vmi.Spec.Domain.Firmware.Bootloader.EFI.SecureBoot {
domain.Spec.OS.BootLoader = &Loader{
Path: filepath.Join(c.OVMFPath, EFICodeSecureBoot),
ReadOnly: "yes",
Expand Down
8 changes: 4 additions & 4 deletions pkg/virt-launcher/virtwrap/api/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,9 @@ var _ = Describe("Converter", func() {

vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{},
EFI: &v1.EFI{
SecureBoot: False(),
},
},
}
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)
Expand All @@ -2186,9 +2188,7 @@ var _ = Describe("Converter", func() {
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(),
},
EFI: &v1.EFI{},
},
}
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)
Expand Down

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

2 changes: 1 addition & 1 deletion staging/src/kubevirt.io/client-go/api/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ 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
// Defaults to true
// +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.

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

8 changes: 4 additions & 4 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,9 @@ func NewRandomVMIWithEFIBootloader() *v1.VirtualMachineInstance {
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1Gi")
vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{},
EFI: &v1.EFI{
SecureBoot: NewBool(false),
},
},
}

Expand All @@ -1985,9 +1987,7 @@ func NewRandomVMIWithSecureBoot() *v1.VirtualMachineInstance {
}
vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{
SecureBoot: NewBool(true),
},
EFI: &v1.EFI{}, // SecureBoot should default to true
},
}

Expand Down
5 changes: 4 additions & 1 deletion tools/vms-generator/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,13 @@ func GetVMISecureBoot() *v1.VirtualMachineInstance {
func GetVMIAlpineEFI() *v1.VirtualMachineInstance {
vmi := getBaseVMI(VmiAlpineEFI)

_false := false
addContainerDisk(&vmi.Spec, fmt.Sprintf("%s/%s:%s", DockerPrefix, imageAlpine, DockerTag), busVirtio)
vmi.Spec.Domain.Firmware = &v1.Firmware{
Bootloader: &v1.Bootloader{
EFI: &v1.EFI{},
EFI: &v1.EFI{
SecureBoot: &_false,
},
},
}

Expand Down

0 comments on commit b8543ba

Please sign in to comment.