diff --git a/internal/oci/uvm.go b/internal/oci/uvm.go index ece82e3d9b..889e31f09e 100644 --- a/internal/oci/uvm.go +++ b/internal/oci/uvm.go @@ -196,7 +196,7 @@ func handleLCOWSecurityPolicy(ctx context.Context, a map[string]string, lopts *u lopts.SecurityPolicy = ParseAnnotationsString(a, annotations.LCOWSecurityPolicy, lopts.SecurityPolicy) // allow actual isolated boot etc to be ignored if we have no hardware. Required for dev // this is not a security issue as the attestation will fail without a genuine report - noSecurityHardware := ParseAnnotationsBool(ctx, a, annotations.LCOWNoSecurityHardware, false) + noSecurityHardware := ParseAnnotationsBool(ctx, a, annotations.NoSecurityHardware, false) // if there is a security policy (and SNP) we currently boot in a way that doesn't support any boot options // this might change if the building of the vmgs file were to be done on demand but that is likely @@ -245,15 +245,36 @@ func handleWCOWSecurityPolicy(ctx context.Context, a map[string]string, wopts *u return fmt.Errorf("minimum 2048MB of memory is required for confidential pods, got: %d", wopts.MemorySizeInMB) } - wopts.AllowOvercommit = ParseAnnotationsBool(ctx, a, annotations.AllowOvercommit, false) - if wopts.AllowOvercommit { - return fmt.Errorf("allow overcommit MUST be false for confidential pods") - } - wopts.SecurityPolicyEnforcer = ParseAnnotationsString(a, annotations.WCOWSecurityPolicyEnforcer, wopts.SecurityPolicyEnforcer) wopts.DisableSecureBoot = ParseAnnotationsBool(ctx, a, annotations.WCOWDisableSecureBoot, false) wopts.GuestStateFilePath = ParseAnnotationsString(a, annotations.WCOWGuestStateFile, uvm.GetDefaultConfidentialVMGSPath()) - wopts.IsolationType = ParseAnnotationsString(a, annotations.WCOWIsolationType, "") + wopts.IsolationType = "SecureNestedPaging" + if noSecurityHardware := ParseAnnotationsBool(ctx, a, annotations.NoSecurityHardware, false); noSecurityHardware { + wopts.IsolationType = "GuestStateOnly" + } + if err := handleWCOWIsolationType(ctx, a, wopts); err != nil { + return err + } + + return nil +} + +func handleWCOWIsolationType(ctx context.Context, a map[string]string, wopts *uvm.OptionsWCOW) error { + isolationType := ParseAnnotationsString(a, annotations.WCOWIsolationType, wopts.IsolationType) + switch isolationType { + case "SecureNestedPaging", "SNP": // Allow VBS & SNP shorthands + wopts.IsolationType = "SecureNestedPaging" + wopts.AllowOvercommit = false + case "VirtualizationBasedSecurity", "VBS": + wopts.IsolationType = "VirtualizationBasedSecurity" + wopts.AllowOvercommit = false + case "GuestStateOnly": + wopts.IsolationType = "GuestStateOnly" + wopts.AllowOvercommit = false + default: + return fmt.Errorf("invalid WCOW isolation type %q", isolationType) + } + return nil } diff --git a/internal/oci/uvm_test.go b/internal/oci/uvm_test.go index 4a4ceed5c2..f8405c64c6 100644 --- a/internal/oci/uvm_test.go +++ b/internal/oci/uvm_test.go @@ -158,8 +158,8 @@ func Test_SpecToUVMCreateOptions_WCOW_Confidential_Defaults(t *testing.T) { if wopts.GuestStateFilePath != uvm.GetDefaultConfidentialVMGSPath() { t.Fatalf("expected GuestStateFilePath to default to %q, got %q", uvm.GetDefaultConfidentialVMGSPath(), wopts.GuestStateFilePath) } - if wopts.IsolationType != "" { - t.Fatalf("expected empty IsolationType by default, got %q", wopts.IsolationType) + if wopts.IsolationType != "SecureNestedPaging" { + t.Fatalf("expected SecureNestedPaging IsolationType by default, got %q", wopts.IsolationType) } } @@ -218,20 +218,6 @@ func Test_SpecToUVMCreateOptions_WCOW_Confidential_ErrorOnLowMemory(t *testing.T } } -func Test_SpecToUVMCreateOptions_WCOW_Confidential_ErrorOnAllowOvercommit(t *testing.T) { - s := &specs.Spec{ - Windows: &specs.Windows{HyperV: &specs.WindowsHyperV{}}, - Annotations: map[string]string{ - annotations.WCOWSecurityPolicy: "test-policy", - annotations.AllowOvercommit: "true", - }, - } - - if _, err := SpecToUVMCreateOpts(context.Background(), s, t.Name(), ""); err == nil { - t.Fatal("expected error for confidential pods when AllowOvercommit=true, got nil") - } -} - func Test_SpecToUVMCreateOptions_WCOW_Confidential_Overrides(t *testing.T) { s := &specs.Spec{ Windows: &specs.Windows{HyperV: &specs.WindowsHyperV{}}, diff --git a/internal/uvm/create_wcow.go b/internal/uvm/create_wcow.go index aedd960776..aa4465fabf 100644 --- a/internal/uvm/create_wcow.go +++ b/internal/uvm/create_wcow.go @@ -220,9 +220,8 @@ func prepareCommonConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWC RegistryChanges: ®istryChanges, ComputeTopology: &hcsschema.Topology{ Memory: &hcsschema.VirtualMachineMemory{ - SizeInMB: memorySizeInMB, - AllowOvercommit: opts.AllowOvercommit, - // EnableHotHint is not compatible with physical. + SizeInMB: memorySizeInMB, + AllowOvercommit: opts.AllowOvercommit, EnableHotHint: opts.AllowOvercommit, EnableDeferredCommit: opts.EnableDeferredCommit, LowMMIOGapInMB: opts.LowMMIOGapInMB, @@ -382,8 +381,6 @@ func prepareSecurityConfigDoc(ctx context.Context, uvm *UtilityVM, opts *Options } } - memoryBacking := hcsschema.MemoryBackingType_PHYSICAL - doc.VirtualMachine.ComputeTopology.Memory.Backing = &memoryBacking doc.SchemaVersion = schemaversion.SchemaV25() doc.VirtualMachine.Version = &hcsschema.Version{ Major: 11, diff --git a/pkg/annotations/annotations.go b/pkg/annotations/annotations.go index b00522344b..9e857340d2 100644 --- a/pkg/annotations/annotations.go +++ b/pkg/annotations/annotations.go @@ -145,10 +145,9 @@ const ( // Deprecated: use [LCOWHostAMDCertificate] instead. HostAMDCertificate = LCOWHostAMDCertificate - // LCOWNoSecurityHardware allows us, when it is set to true, to do testing and development without requiring SNP hardware. - LCOWNoSecurityHardware = "io.microsoft.virtualmachine.lcow.no_security_hardware" - // Deprecated: use [LCOWNoSecurityHardware] instead. - NoSecurityHardware = LCOWNoSecurityHardware + // NoSecurityHardware allows us, when it is set to true, to do testing and development without requiring SNP hardware. + // + NoSecurityHardware = "io.microsoft.virtualmachine.no_security_hardware" // LCOWSecurityPolicy is used to specify a security policy for opengcs to enforce. LCOWSecurityPolicy = "io.microsoft.virtualmachine.lcow.securitypolicy"