Skip to content

Commit 84d8696

Browse files
authored
Merge pull request #1426 from bgartzi/gcp-tdx
Support Intel TDX confidential computing machine configuration
2 parents 59977b4 + 36236cc commit 84d8696

File tree

8 files changed

+145
-1
lines changed

8 files changed

+145
-1
lines changed

api/v1beta1/gcpmachine_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,16 @@ const (
138138
ConfidentialComputePolicySEV ConfidentialComputePolicy = "AMDEncrytedVirtualization"
139139
// ConfidentialComputePolicySEVSNP sets AMD SEV-SNP as the VM instance's confidential computing technology of choice.
140140
ConfidentialComputePolicySEVSNP ConfidentialComputePolicy = "AMDEncrytedVirtualizationNestedPaging"
141+
// ConfidentialComputePolicyTDX sets Intel TDX as the VM instance's confidential computing technology of choice.
142+
ConfidentialComputePolicyTDX ConfidentialComputePolicy = "IntelTrustedDomainExtensions"
141143
)
142144

143145
// Confidential VM Technology support depends on the configured machine types.
144146
// reference: https://cloud.google.com/compute/confidential-vm/docs/os-and-machine-type#machine-type
145147
var (
146148
confidentialMachineSeriesSupportingSev = []string{"n2d", "c2d", "c3d"}
147149
confidentialMachineSeriesSupportingSevsnp = []string{"n2d"}
150+
confidentialMachineSeriesSupportingTdx = []string{"c3"}
148151
)
149152

150153
// HostMaintenancePolicy represents the desired behavior ase of a host maintenance event.
@@ -347,9 +350,10 @@ type GCPMachineSpec struct {
347350
// If Enabled, confidential computing will be configured and AMD Secure Encrypted Virtualization will be configured by default. That is subject to change over time. If using AMD Secure Encrypted Virtualization is vital, use AMDEncryptedVirtualization explicitly instead.
348351
// If AMDEncryptedVirtualization, it will configure AMD Secure Encrypted Virtualization (AMD SEV) as the confidential computing technology.
349352
// If AMDEncryptedVirtualizationNestedPaging, it will configure AMD Secure Encrypted Virtualization Secure Nested Paging (AMD SEV-SNP) as the confidential computing technology.
353+
// If IntelTrustedDomainExtensions, it will configure Intel TDX as the confidential computing technology.
350354
// If enabled (any value other than Disabled) OnHostMaintenance is required to be set to "Terminate".
351355
// If omitted, the platform chooses a default, which is subject to change over time, currently that default is false.
352-
// +kubebuilder:validation:Enum=Enabled;Disabled;AMDEncrytedVirtualization;AMDEncrytedVirtualizationNestedPaging
356+
// +kubebuilder:validation:Enum=Enabled;Disabled;AMDEncrytedVirtualization;AMDEncrytedVirtualizationNestedPaging;IntelTrustedDomainExtensions
353357
// +optional
354358
ConfidentialCompute *ConfidentialComputePolicy `json:"confidentialCompute,omitempty"`
355359

api/v1beta1/gcpmachine_webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func validateConfidentialCompute(spec GCPMachineSpec) error {
124124
if !slices.Contains(confidentialMachineSeriesSupportingSevsnp, machineSeries) {
125125
return fmt.Errorf("ConfidentialCompute %s requires any of the following machine series: %s. %s was found instead", *spec.ConfidentialCompute, strings.Join(confidentialMachineSeriesSupportingSevsnp, ", "), spec.InstanceType)
126126
}
127+
case ConfidentialComputePolicyTDX:
128+
if !slices.Contains(confidentialMachineSeriesSupportingTdx, machineSeries) {
129+
return fmt.Errorf("ConfidentialCompute %s requires any of the following machine series: %s. %s was found instead", *spec.ConfidentialCompute, strings.Join(confidentialMachineSeriesSupportingTdx, ", "), spec.InstanceType)
130+
}
127131
default:
128132
return fmt.Errorf("invalid ConfidentialCompute %s", *spec.ConfidentialCompute)
129133
}

api/v1beta1/gcpmachine_webhook_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestGCPMachine_ValidateCreate(t *testing.T) {
2727
confidentialComputeEnabled := ConfidentialComputePolicyEnabled
2828
confidentialComputeSEV := ConfidentialComputePolicySEV
2929
confidentialComputeSEVSNP := ConfidentialComputePolicySEVSNP
30+
confidentialComputeTDX := ConfidentialComputePolicyTDX
3031
confidentialComputeFooBar := ConfidentialComputePolicy("foobar")
3132
onHostMaintenanceTerminate := HostMaintenancePolicyTerminate
3233
onHostMaintenanceMigrate := HostMaintenancePolicyMigrate
@@ -165,6 +166,28 @@ func TestGCPMachine_ValidateCreate(t *testing.T) {
165166
},
166167
wantErr: true,
167168
},
169+
{
170+
name: "GCPMachine with explicit TDX ConfidentialInstanceType and supported machine type - valid",
171+
GCPMachine: &GCPMachine{
172+
Spec: GCPMachineSpec{
173+
InstanceType: "c3-standard-4",
174+
ConfidentialCompute: &confidentialComputeTDX,
175+
OnHostMaintenance: &onHostMaintenanceTerminate,
176+
},
177+
},
178+
wantErr: false,
179+
},
180+
{
181+
name: "GCPMachine with explicit TDX ConfidentialInstanceType and unsupported machine type - invalid",
182+
GCPMachine: &GCPMachine{
183+
Spec: GCPMachineSpec{
184+
InstanceType: "c3d-standard-4",
185+
ConfidentialCompute: &confidentialComputeTDX,
186+
OnHostMaintenance: &onHostMaintenanceTerminate,
187+
},
188+
},
189+
wantErr: true,
190+
},
168191
{
169192
name: "GCPMachine with RootDiskEncryptionKey KeyType Managed and Managed field set",
170193
GCPMachine: &GCPMachine{

api/v1beta1/gcpmachinetemplate_webhook_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) {
2727
confidentialComputeEnabled := ConfidentialComputePolicyEnabled
2828
confidentialComputeSEV := ConfidentialComputePolicySEV
2929
confidentialComputeSEVSNP := ConfidentialComputePolicySEVSNP
30+
confidentialComputeTDX := ConfidentialComputePolicyTDX
3031
onHostMaintenanceTerminate := HostMaintenancePolicyTerminate
3132
onHostMaintenanceMigrate := HostMaintenancePolicyMigrate
3233
tests := []struct {
@@ -197,6 +198,36 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) {
197198
},
198199
wantErr: true,
199200
},
201+
{
202+
name: "GCPMachine with explicit TDX ConfidentialInstanceType and supported machine type - valid",
203+
template: &GCPMachineTemplate{
204+
Spec: GCPMachineTemplateSpec{
205+
Template: GCPMachineTemplateResource{
206+
Spec: GCPMachineSpec{
207+
InstanceType: "c3-standard-4",
208+
ConfidentialCompute: &confidentialComputeTDX,
209+
OnHostMaintenance: &onHostMaintenanceTerminate,
210+
},
211+
},
212+
},
213+
},
214+
wantErr: false,
215+
},
216+
{
217+
name: "GCPMachine with explicit TDX ConfidentialInstanceType and unsupported machine type - invalid",
218+
template: &GCPMachineTemplate{
219+
Spec: GCPMachineTemplateSpec{
220+
Template: GCPMachineTemplateResource{
221+
Spec: GCPMachineSpec{
222+
InstanceType: "c3d-standard-4",
223+
ConfidentialCompute: &confidentialComputeTDX,
224+
OnHostMaintenance: &onHostMaintenanceTerminate,
225+
},
226+
},
227+
},
228+
},
229+
wantErr: true,
230+
},
200231
}
201232
for _, test := range tests {
202233
t.Run(test.name, func(t *testing.T) {

cloud/scope/machine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
454454
instance.ConfidentialInstanceConfig.ConfidentialInstanceType = "SEV"
455455
case infrav1.ConfidentialComputePolicySEVSNP:
456456
instance.ConfidentialInstanceConfig.ConfidentialInstanceType = "SEV_SNP"
457+
case infrav1.ConfidentialComputePolicyTDX:
458+
instance.ConfidentialInstanceConfig.ConfidentialInstanceType = "TDX"
457459
default:
458460
}
459461
}

cloud/services/compute/instances/reconcile_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,82 @@ func TestService_createOrGetInstance(t *testing.T) {
647647
Zone: "us-central1-c",
648648
},
649649
},
650+
{
651+
name: "instance does not exist (should create instance) with confidential compute enabled and TDX confidential instance type specified",
652+
scope: func() Scope {
653+
machineScope.GCPMachine = getFakeGCPMachine()
654+
hostMaintenancePolicyTerminate := infrav1.HostMaintenancePolicyTerminate
655+
machineScope.GCPMachine.Spec.OnHostMaintenance = &hostMaintenancePolicyTerminate
656+
confidentialInstTypeTDX := infrav1.ConfidentialComputePolicyTDX
657+
machineScope.GCPMachine.Spec.ConfidentialCompute = &confidentialInstTypeTDX
658+
return machineScope
659+
},
660+
mockInstance: &cloud.MockInstances{
661+
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
662+
Objects: map[meta.Key]*cloud.MockInstancesObj{},
663+
},
664+
want: &compute.Instance{
665+
Name: "my-machine",
666+
CanIpForward: true,
667+
Disks: []*compute.AttachedDisk{
668+
{
669+
AutoDelete: true,
670+
Boot: true,
671+
InitializeParams: &compute.AttachedDiskInitializeParams{
672+
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
673+
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
674+
ResourceManagerTags: map[string]string{},
675+
Labels: map[string]string{
676+
"foo": "bar",
677+
},
678+
},
679+
},
680+
},
681+
Labels: map[string]string{
682+
"capg-role": "node",
683+
"capg-cluster-my-cluster": "owned",
684+
"foo": "bar",
685+
},
686+
MachineType: "zones/us-central1-c/machineTypes",
687+
Metadata: &compute.Metadata{
688+
Items: []*compute.MetadataItems{
689+
{
690+
Key: "user-data",
691+
Value: ptr.To[string]("Zm9vCg=="),
692+
},
693+
},
694+
},
695+
NetworkInterfaces: []*compute.NetworkInterface{
696+
{
697+
Network: "projects/my-proj/global/networks/default",
698+
},
699+
},
700+
Params: &compute.InstanceParams{
701+
ResourceManagerTags: map[string]string{},
702+
},
703+
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/zones/us-central1-c/instances/my-machine",
704+
ConfidentialInstanceConfig: &compute.ConfidentialInstanceConfig{
705+
EnableConfidentialCompute: true,
706+
ConfidentialInstanceType: "TDX",
707+
},
708+
Scheduling: &compute.Scheduling{
709+
OnHostMaintenance: strings.ToUpper(string(infrav1.HostMaintenancePolicyTerminate)),
710+
},
711+
ServiceAccounts: []*compute.ServiceAccount{
712+
{
713+
Email: "default",
714+
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
715+
},
716+
},
717+
Tags: &compute.Tags{
718+
Items: []string{
719+
"my-cluster-node",
720+
"my-cluster",
721+
},
722+
},
723+
Zone: "us-central1-c",
724+
},
725+
},
650726
{
651727
name: "instance does not exist (should create instance) with MIGRATE OnHostMaintenance",
652728
scope: func() Scope {

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,15 @@ spec:
198198
If Enabled, confidential computing will be configured and AMD Secure Encrypted Virtualization will be configured by default. That is subject to change over time. If using AMD Secure Encrypted Virtualization is vital, use AMDEncryptedVirtualization explicitly instead.
199199
If AMDEncryptedVirtualization, it will configure AMD Secure Encrypted Virtualization (AMD SEV) as the confidential computing technology.
200200
If AMDEncryptedVirtualizationNestedPaging, it will configure AMD Secure Encrypted Virtualization Secure Nested Paging (AMD SEV-SNP) as the confidential computing technology.
201+
If IntelTrustedDomainExtensions, it will configure Intel TDX as the confidential computing technology.
201202
If enabled (any value other than Disabled) OnHostMaintenance is required to be set to "Terminate".
202203
If omitted, the platform chooses a default, which is subject to change over time, currently that default is false.
203204
enum:
204205
- Enabled
205206
- Disabled
206207
- AMDEncrytedVirtualization
207208
- AMDEncrytedVirtualizationNestedPaging
209+
- IntelTrustedDomainExtensions
208210
type: string
209211
image:
210212
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ spec:
213213
If Enabled, confidential computing will be configured and AMD Secure Encrypted Virtualization will be configured by default. That is subject to change over time. If using AMD Secure Encrypted Virtualization is vital, use AMDEncryptedVirtualization explicitly instead.
214214
If AMDEncryptedVirtualization, it will configure AMD Secure Encrypted Virtualization (AMD SEV) as the confidential computing technology.
215215
If AMDEncryptedVirtualizationNestedPaging, it will configure AMD Secure Encrypted Virtualization Secure Nested Paging (AMD SEV-SNP) as the confidential computing technology.
216+
If IntelTrustedDomainExtensions, it will configure Intel TDX as the confidential computing technology.
216217
If enabled (any value other than Disabled) OnHostMaintenance is required to be set to "Terminate".
217218
If omitted, the platform chooses a default, which is subject to change over time, currently that default is false.
218219
enum:
219220
- Enabled
220221
- Disabled
221222
- AMDEncrytedVirtualization
222223
- AMDEncrytedVirtualizationNestedPaging
224+
- IntelTrustedDomainExtensions
223225
type: string
224226
image:
225227
description: |-

0 commit comments

Comments
 (0)