-
Notifications
You must be signed in to change notification settings - Fork 287
always set SecurityPolicyEnabled when policy is present #2748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anmaxvl
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
anmaxvl:fix-lcow-policy-plumbing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+170
−22
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,11 @@ func BuildSandboxConfig( | |
| return nil, nil, fmt.Errorf("failed to parse sandbox options: %w", err) | ||
| } | ||
|
|
||
| // isConfidentialSNP is true when we have a security policy AND real SNP hardware. | ||
| // This gates SNP-specific HCS document construction (schema V25, confidential boot, etc.). | ||
| // When no-security-hardware is set, we still plumb the policy but use the standard HCS doc. | ||
| isConfidentialSNP := sandboxOptions.ConfidentialConfig != nil && !sandboxOptions.NoSecurityHardware | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move |
||
|
|
||
| // ================== Parse Topology (CPU, Memory, NUMA) options ================= | ||
| // =============================================================================== | ||
|
|
||
|
|
@@ -89,7 +94,7 @@ func BuildSandboxConfig( | |
| // Parse NUMA settings only for non-confidential VMs. | ||
| var numa *hcsschema.Numa | ||
| var numaProcessors *hcsschema.NumaProcessors | ||
| if sandboxOptions.ConfidentialConfig == nil { | ||
| if !isConfidentialSNP { | ||
| numa, numaProcessors, err = parseNUMAOptions( | ||
| ctx, | ||
| spec.Annotations, | ||
|
|
@@ -121,11 +126,11 @@ func BuildSandboxConfig( | |
| // ================== Parse Boot options ========================================= | ||
| // =============================================================================== | ||
|
|
||
| // For confidential VMs, we don't use the standard boot options - the UEFI secure boot | ||
| // For SNP confidential VMs, we don't use the standard boot options - the UEFI secure boot | ||
| // settings will be set by parseConfidentialOptions. | ||
| bootOptions := &hcsschema.Chipset{} | ||
| var rootFsFullPath string | ||
| if sandboxOptions.ConfidentialConfig == nil { | ||
| if !isConfidentialSNP { | ||
| bootOptions, rootFsFullPath, err = parseBootOptions(ctx, opts, spec.Annotations) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to parse boot options: %w", err) | ||
|
|
@@ -141,9 +146,9 @@ func BuildSandboxConfig( | |
| spec.Annotations, | ||
| spec.Devices, | ||
| rootFsFullPath, | ||
| numa != nil && numaProcessors != nil, // isNumaEnabled | ||
| sandboxOptions.FullyPhysicallyBacked, // isFullyPhysicallyBacked | ||
| sandboxOptions.ConfidentialConfig != nil, // isConfidential | ||
| numa != nil && numaProcessors != nil, // isNumaEnabled | ||
| sandboxOptions.FullyPhysicallyBacked, // isFullyPhysicallyBacked | ||
| isConfidentialSNP, // isConfidential | ||
| ) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to parse device options: %w", err) | ||
|
|
@@ -156,7 +161,7 @@ func BuildSandboxConfig( | |
| hvSocketConfig, comPorts, err := setAdditionalOptions( | ||
| ctx, | ||
| spec.Annotations, | ||
| sandboxOptions.ConfidentialConfig != nil, // isConfidential | ||
| isConfidentialSNP, // isConfidential | ||
| ) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to parse additional parameters: %w", err) | ||
|
|
@@ -169,7 +174,7 @@ func BuildSandboxConfig( | |
| var securitySettings *hcsschema.SecuritySettings | ||
| var guestState *hcsschema.GuestState | ||
| var filesToCleanOnError []string | ||
| if sandboxOptions.ConfidentialConfig != nil { | ||
| if isConfidentialSNP { | ||
| bootOptions, | ||
| securitySettings, | ||
| guestState, | ||
|
|
@@ -204,9 +209,9 @@ func BuildSandboxConfig( | |
| // =============================================================================== | ||
|
|
||
| // Build the kernel command line after all options are parsed. | ||
| // For confidential VMs (SNP mode), kernel args are embedded in VMGS file, so skip this. | ||
| // For SNP confidential VMs, kernel args are embedded in VMGS file, so skip this. | ||
| var kernelArgs string | ||
| if sandboxOptions.ConfidentialConfig == nil { | ||
| if !isConfidentialSNP { | ||
| kernelArgs, err = buildKernelArgs( | ||
| ctx, | ||
| opts, | ||
|
|
@@ -238,7 +243,7 @@ func BuildSandboxConfig( | |
| // Use Schema V21 for non-confidential cases. | ||
| // Use Schema V25 for confidential cases. | ||
| schema := schemaversion.SchemaV21() | ||
| if sandboxOptions.ConfidentialConfig != nil { | ||
| if isConfidentialSNP { | ||
| schema = schemaversion.SchemaV25() | ||
| } | ||
|
|
||
|
|
@@ -332,12 +337,13 @@ func parseSandboxOptions(ctx context.Context, platform string, annotations map[s | |
| // Determine if this is a confidential VM early, as it affects boot options parsing | ||
| securityPolicy := oci.ParseAnnotationsString(annotations, shimannotations.LCOWSecurityPolicy, "") | ||
| noSecurityHardware := oci.ParseAnnotationsBool(ctx, annotations, shimannotations.NoSecurityHardware, false) | ||
| if securityPolicy != "" && !noSecurityHardware { | ||
| if len(securityPolicy) > 0 { | ||
| sandboxOptions.ConfidentialConfig = &ConfidentialConfig{ | ||
| SecurityPolicy: securityPolicy, | ||
| SecurityPolicyEnforcer: oci.ParseAnnotationsString(annotations, shimannotations.LCOWSecurityPolicyEnforcer, ""), | ||
| SecurityPolicyEnforcer: oci.ParseAnnotationsString(annotations, shimannotations.LCOWSecurityPolicyEnforcer, "rego"), | ||
| UvmReferenceInfoFile: oci.ParseAnnotationsString(annotations, shimannotations.LCOWReferenceInfoFile, vmutils.DefaultUVMReferenceInfoFile), | ||
| } | ||
| sandboxOptions.NoSecurityHardware = noSecurityHardware | ||
|
|
||
| log.G(ctx).WithFields(logrus.Fields{ | ||
| "securityPolicy": securityPolicy, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
NoSecurityHardwareis used locally withinlcow builder, can we avoid adding it toSandboxOptions?SandboxOptionsare used outside the package and usually contain the fields which are used later in the workflow.