Skip to content

Commit 88c9212

Browse files
shubazalamtuxtof
authored andcommitted
add secure boot (nutanix-cloud-native#181)
1 parent b842074 commit 88c9212

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.web-docs/components/builder/nutanix/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ These parameters allow to define information about platform and temporary VM use
2121
- `memory_mb` (number) - Size of vRAM for temporary VM (in megabytes).
2222
- `cd_files` (array of strings) - A list of files to place onto a CD that is attached when the VM is booted. This can include either files or directories; any directories will be copied onto the CD recursively, preserving directory structure hierarchy.
2323
- `cd_label` (string) - Label of this CD Drive.
24-
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy" or "uefi", default is "legacy").
24+
- `boot_type` (string) - Type of boot used on the temporary VM ("legacy", "uefi" or "secure_boot", default is "legacy").
2525
- `boot_priority` (string) - Priority of boot device ("cdrom" or "disk", default is "cdrom").
2626
- `ip_wait_timeout` (duration string | ex: "0h42m0s") - Amount of time to wait for VM's IP, similar to 'ssh_timeout'. Defaults to 15m (15 minutes). See the Golang [ParseDuration](https://golang.org/pkg/time/#ParseDuration) documentation for full details.
2727
- `vm_categories` ([]Category) - Assign Categories to the vm.

builder/nutanix/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const (
2525
// NutanixIdentifierBootTypeUEFI is a resource identifier identifying the UEFI boot type for virtual machines.
2626
NutanixIdentifierBootTypeUEFI string = "uefi"
2727

28+
// NutanixIdentifierBootTypeSecure is a resource identifier identifying the secure boot type for virtual machines.
29+
NutanixIdentifierBootTypeSecure string = "secure_boot"
30+
2831
// NutanixIdentifierBootPriorityDisk is a resource identifier identifying the boot priority as disk for virtual machines.
2932
NutanixIdentifierBootPriorityDisk string = "disk"
3033

@@ -92,6 +95,7 @@ type VmNIC struct {
9295
type VmConfig struct {
9396
VMName string `mapstructure:"vm_name" json:"vm_name" required:"false"`
9497
OSType string `mapstructure:"os_type" json:"os_type" required:"true"`
98+
MachineType string `mapstructure:"machine_type" json:"machine_type" required:"false"`
9599
BootType string `mapstructure:"boot_type" json:"boot_type" required:"false"`
96100
BootPriority string `mapstructure:"boot_priority" json:"boot_priority" required:"false"`
97101
VmDisks []VmDisk `mapstructure:"vm_disks"`
@@ -146,7 +150,7 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
146150
c.ClusterConfig.Port = 9440
147151
}
148152

149-
if c.BootType != NutanixIdentifierBootTypeLegacy && c.BootType != NutanixIdentifierBootTypeUEFI {
153+
if c.BootType != NutanixIdentifierBootTypeLegacy && c.BootType != NutanixIdentifierBootTypeUEFI && c.BootType != NutanixIdentifierBootTypeSecure {
150154
log.Println("No correct VM Boot Type configured, defaulting to 'legacy'")
151155
c.BootType = string(NutanixIdentifierBootTypeLegacy)
152156
}
@@ -156,6 +160,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
156160
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("UEFI does not support boot priority"))
157161
}
158162

163+
if c.BootType == NutanixIdentifierBootTypeSecure && c.BootPriority != "" {
164+
log.Println("Boot Priority is not supported for secure boot type")
165+
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("Secure boot does not support boot priority"))
166+
}
167+
159168
if c.BootPriority != NutanixIdentifierBootPriorityDisk && c.BootPriority != NutanixIdentifierBootPriorityCDROM {
160169
log.Println("No correct VM Boot Priority configured, defaulting to 'cdrom'")
161170
c.BootPriority = string(NutanixIdentifierBootPriorityCDROM)

builder/nutanix/driver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,14 @@ func (d *NutanixDriver) CreateRequest(ctx context.Context, vm VmConfig, state mu
554554
req.Spec.Resources.BootConfig = &v3.VMBootConfig{
555555
BootType: &bootType,
556556
}
557+
} else if vm.BootType == NutanixIdentifierBootTypeSecure {
558+
bootType := strings.ToUpper(NutanixIdentifierBootTypeSecure)
559+
560+
req.Spec.Resources.BootConfig = &v3.VMBootConfig{
561+
BootType: &bootType,
562+
}
563+
// Force machine type to "Q35", which is required for Secure Boot
564+
req.Spec.Resources.MachineType = StringPtr("Q35")
557565
} else {
558566
bootType := strings.ToUpper(NutanixIdentifierBootTypeLegacy)
559567

0 commit comments

Comments
 (0)