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
35 changes: 28 additions & 7 deletions internal/oci/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
18 changes: 2 additions & 16 deletions internal/oci/uvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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{}},
Expand Down
7 changes: 2 additions & 5 deletions internal/uvm/create_wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ func prepareCommonConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWC
RegistryChanges: &registryChanges,
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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading