Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/client/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (g *GcpCli) CreateInstance(ctx context.Context, spec *spec.RunnerSpec) (*co
inst := &computepb.Instance{
Name: proto.String(name),
MachineType: proto.String(util.GetMachineType(g.cfg.Zone, spec.BootstrapParams.Flavor)),
Disks: generateBootDisk(spec.DiskSize, spec.BootstrapParams.Image, spec.SourceSnapshot, spec.DiskType, spec.CustomLabels),
Disks: generateBootDisk(spec.DiskSize, spec.BootstrapParams.Image, spec.SourceSnapshot, spec.DiskType, spec.CustomLabels, spec.BootDiskKmsKeyName),
DisplayDevice: &computepb.DisplayDevice{
EnableDisplay: proto.Bool(spec.DisplayDevice),
},
Expand Down Expand Up @@ -323,7 +323,7 @@ func selectStartupScript(osType params.OSType) string {
}
}

func generateBootDisk(diskSize int64, image, snapshot string, diskType string, customLabels map[string]string) []*computepb.AttachedDisk {
func generateBootDisk(diskSize int64, image, snapshot string, diskType string, customLabels map[string]string, kmsKeyName string) []*computepb.AttachedDisk {
disk := []*computepb.AttachedDisk{
{
Boot: proto.Bool(true),
Expand All @@ -345,5 +345,12 @@ func generateBootDisk(diskSize int64, image, snapshot string, diskType string, c
disk[0].InitializeParams.SourceImage = nil
}

// Set CMEK (Customer-Managed Encryption Key) for the boot disk
if kmsKeyName != "" {
disk[0].DiskEncryptionKey = &computepb.CustomerEncryptionKey{
KmsKeyName: proto.String(kmsKeyName),
}
}

return disk
}
7 changes: 7 additions & 0 deletions internal/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type extraSpecs struct {
EnableSecureBoot bool `json:"enable_secure_boot,omitempty" jsonschema:"description=Enable Secure Boot on the VM. Requires a Shielded VM compatible image."`
EnableVTPM bool `json:"enable_vtpm,omitempty" jsonschema:"description=Enable virtual Trusted Platform Module (vTPM) on the VM."`
EnableIntegrityMonitoring bool `json:"enable_integrity_monitoring,omitempty" jsonschema:"description=Enable integrity monitoring on the VM."`
// CMEK (Customer-Managed Encryption Key) for boot disk
BootDiskKmsKeyName string `json:"boot_disk_kms_key_name,omitempty" jsonschema:"description=The Cloud KMS key to use for boot disk encryption. Format: projects/{project}/locations/{location}/keyRings/{keyRing}/cryptoKeys/{key}"`
// The Cloudconfig struct from common package
cloudconfig.CloudConfigSpec
}
Expand Down Expand Up @@ -205,6 +207,8 @@ type RunnerSpec struct {
EnableSecureBoot bool
EnableVTPM bool
EnableIntegrityMonitoring bool
// CMEK (Customer-Managed Encryption Key) for boot disk
BootDiskKmsKeyName string
}

func (r *RunnerSpec) MergeExtraSpecs(extraSpecs *extraSpecs) {
Expand Down Expand Up @@ -258,6 +262,9 @@ func (r *RunnerSpec) MergeExtraSpecs(extraSpecs *extraSpecs) {
if extraSpecs.EnableIntegrityMonitoring {
r.EnableIntegrityMonitoring = extraSpecs.EnableIntegrityMonitoring
}
if extraSpecs.BootDiskKmsKeyName != "" {
r.BootDiskKmsKeyName = extraSpecs.BootDiskKmsKeyName
}
}

func (r *RunnerSpec) Validate() error {
Expand Down