Skip to content

Commit 9c2bda0

Browse files
committed
machine_webhook: Add validation for CPUOptions in AWSMachineProviderConfig
This change introduces webhook validation for the CPUOptions field in AWSMachineProviderConfig. The validation ensures that if cpuOptions is provided, its confidentialCompute value is either empty or one of the supported policies: - Disabled - AMDEncryptedVirtualizationNestedPaging Signed-off-by: Fangge Jin <[email protected]>
1 parent d19bdda commit 9c2bda0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/webhooks/machine_webhook.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,20 @@ func validateAWS(m *machinev1beta1.Machine, config *admissionConfig) (bool, []st
868868
)
869869
}
870870

871+
switch providerSpec.CPUOptions.ConfidentialCompute {
872+
case "", machinev1beta1.AWSConfidentialComputePolicyDisabled, machinev1beta1.AWSConfidentialComputePolicySEVSNP:
873+
// Valid values
874+
default:
875+
errs = append(
876+
errs,
877+
field.Invalid(
878+
field.NewPath("providerSpec", "CPUOptions", "ConfidentialCompute"),
879+
providerSpec.CPUOptions.ConfidentialCompute,
880+
fmt.Sprintf("Allowed values are %s, %s and omitted", machinev1beta1.AWSConfidentialComputePolicyDisabled, machinev1beta1.AWSConfidentialComputePolicySEVSNP),
881+
),
882+
)
883+
}
884+
871885
if len(errs) > 0 {
872886
return false, warnings, errs
873887
}

pkg/webhooks/machine_webhook_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,21 @@ func TestValidateAWSProviderSpec(t *testing.T) {
26102610
expectedOk: false,
26112611
expectedError: "providerSpec.metadataServiceOptions.authentication: Invalid value: \"Boom\": Allowed values are either 'Optional' or 'Required'",
26122612
},
2613+
{
2614+
testCase: "with valid cpuOptions",
2615+
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
2616+
p.CPUOptions.ConfidentialCompute = "AMDEncryptedVirtualizationNestedPaging"
2617+
},
2618+
expectedOk: true,
2619+
},
2620+
{
2621+
testCase: "with invalid cpuOptions",
2622+
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {
2623+
p.CPUOptions.ConfidentialCompute = "invalid"
2624+
},
2625+
expectedOk: false,
2626+
expectedError: "providerSpec.CPUOptions.ConfidentialCompute: Invalid value: \"invalid\": Allowed values are Disabled, AMDEncryptedVirtualizationNestedPaging and omitted",
2627+
},
26132628
{
26142629
testCase: "with invalid GroupVersionKind",
26152630
modifySpec: func(p *machinev1beta1.AWSMachineProviderConfig) {

0 commit comments

Comments
 (0)