Skip to content

Commit b292ed4

Browse files
committed
machine_webhook: Support AMD SEV and AMD SEV-SNP confidentialCompute
Additional logic to support AMD SEV and AMD SEV-SNP values in the confidentialCompute parameter.
1 parent 68c834e commit b292ed4

File tree

2 files changed

+89
-18
lines changed

2 files changed

+89
-18
lines changed

pkg/webhooks/machine_webhook.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ const (
225225

226226
// GCP Confidential VM supports Compute Engine machine types in the following series:
227227
// reference: https://cloud.google.com/compute/confidential-vm/docs/os-and-machine-type#machine-type
228-
var gcpConfidentialComputeSupportedMachineSeries = []string{"n2d", "c2d", "c3d"}
228+
var gcpConfidentialTypeMachineSeriesSupportingSEV = []string{"n2d", "c2d", "c3d"}
229+
var gcpConfidentialTypeMachineSeriesSupportingSEVSNP = []string{"n2d"}
229230

230231
// defaultInstanceTypeForCloudProvider returns the default instance type for the given cloud provider and architecture.
231232
// If the cloud provider is not supported, an empty string is returned.
@@ -1314,30 +1315,37 @@ func validateShieldedInstanceConfig(providerSpec *machinev1beta1.GCPMachineProvi
13141315

13151316
func validateGCPConfidentialComputing(providerSpec *machinev1beta1.GCPMachineProviderSpec) field.ErrorList {
13161317
var errs field.ErrorList
1317-
1318-
switch providerSpec.ConfidentialCompute {
1319-
case machinev1beta1.ConfidentialComputePolicyEnabled:
1318+
if providerSpec.ConfidentialCompute != "" && providerSpec.ConfidentialCompute != machinev1beta1.ConfidentialComputePolicyDisabled {
13201319
// Check on host maintenance
13211320
if providerSpec.OnHostMaintenance != machinev1beta1.TerminateHostMaintenanceType {
13221321
errs = append(errs, field.Invalid(field.NewPath("providerSpec", "onHostMaintenance"),
13231322
providerSpec.OnHostMaintenance,
1324-
fmt.Sprintf("ConfidentialCompute require OnHostMaintenance to be set to %s, the current value is: %s", machinev1beta1.TerminateHostMaintenanceType, providerSpec.OnHostMaintenance)))
1323+
fmt.Sprintf("ConfidentialCompute %s requires OnHostMaintenance to be set to %s, the current value is: %s", providerSpec.ConfidentialCompute, machinev1beta1.TerminateHostMaintenanceType, providerSpec.OnHostMaintenance)))
13251324
}
13261325
// Check machine series supports confidential computing
13271326
machineSeries := strings.Split(providerSpec.MachineType, "-")[0]
1328-
if !slices.Contains(gcpConfidentialComputeSupportedMachineSeries, machineSeries) {
1329-
errs = append(errs, field.Invalid(field.NewPath("providerSpec", "machineType"),
1330-
providerSpec.MachineType,
1331-
fmt.Sprintf("ConfidentialCompute require machine type in the following series: %s", strings.Join(gcpConfidentialComputeSupportedMachineSeries, `,`))),
1327+
switch providerSpec.ConfidentialCompute {
1328+
case machinev1beta1.ConfidentialComputePolicyEnabled, machinev1beta1.ConfidentialComputePolicySEV:
1329+
if !slices.Contains(gcpConfidentialTypeMachineSeriesSupportingSEV, machineSeries) {
1330+
errs = append(errs, field.Invalid(field.NewPath("providerSpec", "machineType"),
1331+
providerSpec.MachineType,
1332+
fmt.Sprintf("ConfidentialCompute %s requires a machine type in the following series: %s", providerSpec.ConfidentialCompute, strings.Join(gcpConfidentialTypeMachineSeriesSupportingSEV, `,`))),
1333+
)
1334+
}
1335+
case machinev1beta1.ConfidentialComputePolicySEVSNP:
1336+
if !slices.Contains(gcpConfidentialTypeMachineSeriesSupportingSEVSNP, machineSeries) {
1337+
errs = append(errs, field.Invalid(field.NewPath("providerSpec", "machineType"),
1338+
providerSpec.MachineType,
1339+
fmt.Sprintf("ConfidentialCompute %s requires a machine type in the following series: %s", providerSpec.ConfidentialCompute, strings.Join(gcpConfidentialTypeMachineSeriesSupportingSEVSNP, `,`))),
1340+
)
1341+
}
1342+
default:
1343+
errs = append(errs, field.Invalid(field.NewPath("providerSpec", "confidentialCompute"),
1344+
providerSpec.ConfidentialCompute,
1345+
fmt.Sprintf("ConfidentialCompute must be %s, %s, %s, or %s", machinev1beta1.ConfidentialComputePolicyEnabled, machinev1beta1.ConfidentialComputePolicyDisabled, machinev1beta1.ConfidentialComputePolicySEV, machinev1beta1.ConfidentialComputePolicySEVSNP)),
13321346
)
13331347
}
1334-
case machinev1beta1.ConfidentialComputePolicyDisabled, "":
1335-
default:
1336-
errs = append(errs, field.Invalid(field.NewPath("providerSpec", "confidentialCompute"),
1337-
providerSpec.ConfidentialCompute,
1338-
fmt.Sprintf("ConfidentialCompute must be either %s or %s.", machinev1beta1.ConfidentialComputePolicyEnabled, machinev1beta1.ConfidentialComputePolicyDisabled)))
13391348
}
1340-
13411349
return errs
13421350
}
13431351

pkg/webhooks/machine_webhook_test.go

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,9 +3802,10 @@ func TestValidateGCPProviderSpec(t *testing.T) {
38023802
testCase: "with ConfidentialCompute invalid value",
38033803
modifySpec: func(p *machinev1beta1.GCPMachineProviderSpec) {
38043804
p.ConfidentialCompute = "invalid-value"
3805+
p.OnHostMaintenance = machinev1beta1.TerminateHostMaintenanceType
38053806
},
38063807
expectedOk: false,
3807-
expectedError: "providerSpec.confidentialCompute: Invalid value: \"invalid-value\": ConfidentialCompute must be either Enabled or Disabled.",
3808+
expectedError: "providerSpec.confidentialCompute: Invalid value: \"invalid-value\": ConfidentialCompute must be Enabled, Disabled, AMDEncryptedVirtualization, or AMDEncryptedVirtualizationNestedPaging",
38083809
},
38093810
{
38103811
testCase: "with ConfidentialCompute enabled while onHostMaintenance is set to Migrate",
@@ -3815,7 +3816,7 @@ func TestValidateGCPProviderSpec(t *testing.T) {
38153816
p.GPUs = []machinev1beta1.GCPGPUConfig{}
38163817
},
38173818
expectedOk: false,
3818-
expectedError: "providerSpec.onHostMaintenance: Invalid value: \"Migrate\": ConfidentialCompute require OnHostMaintenance to be set to Terminate, the current value is: Migrate",
3819+
expectedError: "providerSpec.onHostMaintenance: Invalid value: \"Migrate\": ConfidentialCompute Enabled requires OnHostMaintenance to be set to Terminate, the current value is: Migrate",
38193820
},
38203821
{
38213822
testCase: "with ConfidentialCompute enabled and unsupported machineType",
@@ -3825,7 +3826,69 @@ func TestValidateGCPProviderSpec(t *testing.T) {
38253826
p.MachineType = "e2-standard-4"
38263827
},
38273828
expectedOk: false,
3828-
expectedError: "providerSpec.machineType: Invalid value: \"e2-standard-4\": ConfidentialCompute require machine type in the following series: n2d,c2d,c3d",
3829+
expectedError: "providerSpec.machineType: Invalid value: \"e2-standard-4\": ConfidentialCompute Enabled requires a machine type in the following series: n2d,c2d,c3d",
3830+
},
3831+
{
3832+
testCase: "with ConfidentialCompute AMDEncryptedVirtualization and an unsupported machine",
3833+
modifySpec: func(p *machinev1beta1.GCPMachineProviderSpec) {
3834+
p.ConfidentialCompute = machinev1beta1.ConfidentialComputePolicySEV
3835+
p.OnHostMaintenance = machinev1beta1.TerminateHostMaintenanceType
3836+
p.MachineType = "c3-standard-4"
3837+
},
3838+
expectedOk: false,
3839+
expectedError: "providerSpec.machineType: Invalid value: \"c3-standard-4\": ConfidentialCompute AMDEncryptedVirtualization requires a machine type in the following series: n2d,c2d,c3d",
3840+
},
3841+
{
3842+
testCase: "with ConfidentialCompute AMDEncryptedVirtualization and a supported machine",
3843+
modifySpec: func(p *machinev1beta1.GCPMachineProviderSpec) {
3844+
p.ConfidentialCompute = machinev1beta1.ConfidentialComputePolicySEV
3845+
p.OnHostMaintenance = machinev1beta1.TerminateHostMaintenanceType
3846+
p.MachineType = "c2d-standard-4"
3847+
},
3848+
expectedOk: true,
3849+
expectedError: "",
3850+
},
3851+
{
3852+
testCase: "with ConfidentialCompute AMDEncryptedVirtualization and onHostMaintenance set to Migrate",
3853+
modifySpec: func(p *machinev1beta1.GCPMachineProviderSpec) {
3854+
p.ConfidentialCompute = machinev1beta1.ConfidentialComputePolicySEV
3855+
p.OnHostMaintenance = machinev1beta1.MigrateHostMaintenanceType
3856+
p.MachineType = "c3d-standard-4"
3857+
p.GPUs = []machinev1beta1.GCPGPUConfig{}
3858+
},
3859+
expectedOk: false,
3860+
expectedError: "providerSpec.onHostMaintenance: Invalid value: \"Migrate\": ConfidentialCompute AMDEncryptedVirtualization requires OnHostMaintenance to be set to Terminate, the current value is: Migrate",
3861+
},
3862+
{
3863+
testCase: "with ConfidentialCompute AMDEncryptedVirtualizationNestedPaging and an unsupported machine",
3864+
modifySpec: func(p *machinev1beta1.GCPMachineProviderSpec) {
3865+
p.ConfidentialCompute = machinev1beta1.ConfidentialComputePolicySEVSNP
3866+
p.OnHostMaintenance = machinev1beta1.TerminateHostMaintenanceType
3867+
p.MachineType = "c3-standard-4"
3868+
},
3869+
expectedOk: false,
3870+
expectedError: "providerSpec.machineType: Invalid value: \"c3-standard-4\": ConfidentialCompute AMDEncryptedVirtualizationNestedPaging requires a machine type in the following series: n2d",
3871+
},
3872+
{
3873+
testCase: "with ConfidentialCompute AMDEncryptedVirtualizationNestedPaging and a supported machine",
3874+
modifySpec: func(p *machinev1beta1.GCPMachineProviderSpec) {
3875+
p.ConfidentialCompute = machinev1beta1.ConfidentialComputePolicySEVSNP
3876+
p.OnHostMaintenance = machinev1beta1.TerminateHostMaintenanceType
3877+
p.MachineType = "n2d-standard-4"
3878+
},
3879+
expectedOk: true,
3880+
expectedError: "",
3881+
},
3882+
{
3883+
testCase: "with ConfidentialCompute AMDEncryptedVirtualizationNestedPaging and onHostMaintenance set to Migrate",
3884+
modifySpec: func(p *machinev1beta1.GCPMachineProviderSpec) {
3885+
p.ConfidentialCompute = machinev1beta1.ConfidentialComputePolicySEVSNP
3886+
p.OnHostMaintenance = machinev1beta1.MigrateHostMaintenanceType
3887+
p.MachineType = "n2d-standard-4"
3888+
p.GPUs = []machinev1beta1.GCPGPUConfig{}
3889+
},
3890+
expectedOk: false,
3891+
expectedError: "providerSpec.onHostMaintenance: Invalid value: \"Migrate\": ConfidentialCompute AMDEncryptedVirtualizationNestedPaging requires OnHostMaintenance to be set to Terminate, the current value is: Migrate",
38293892
},
38303893
{
38313894
testCase: "with GPUs and Migrate onHostMaintenance",

0 commit comments

Comments
 (0)