Skip to content

Commit 6c85edc

Browse files
authored
Move common confidential options for LCOW and WCOW (#2582)
Signed-off-by: Mahati Chamarthy <[email protected]>
1 parent cbc0126 commit 6c85edc

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

internal/oci/uvm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func handleLCOWSecurityPolicy(ctx context.Context, a map[string]string, lopts *u
206206
// VPMem not supported by the enlightened kernel for SNP so set count to zero.
207207
lopts.VPMemDeviceCount = 0
208208
// set the default GuestState filename.
209-
lopts.GuestStateFile = uvm.GuestStateFile
209+
lopts.GuestStateFilePath = uvm.GuestStateFile
210210
lopts.KernelBootOptions = ""
211211
lopts.AllowOvercommit = false
212212
lopts.SecurityPolicyEnabled = true
@@ -388,7 +388,7 @@ func SpecToUVMCreateOpts(ctx context.Context, s *specs.Spec, id, owner string) (
388388
handleLCOWSecurityPolicy(ctx, s.Annotations, lopts)
389389

390390
// override the default GuestState and DmVerityRootFs filenames if specified
391-
lopts.GuestStateFile = ParseAnnotationsString(s.Annotations, annotations.LCOWGuestStateFile, lopts.GuestStateFile)
391+
lopts.GuestStateFilePath = ParseAnnotationsString(s.Annotations, annotations.LCOWGuestStateFile, lopts.GuestStateFilePath)
392392
lopts.DmVerityRootFsVhd = ParseAnnotationsString(s.Annotations, annotations.DmVerityRootFsVhd, lopts.DmVerityRootFsVhd)
393393
lopts.DmVerityMode = ParseAnnotationsBool(ctx, s.Annotations, annotations.DmVerityMode, lopts.DmVerityMode)
394394
lopts.DmVerityCreateArgs = ParseAnnotationsString(s.Annotations, annotations.DmVerityCreateArgs, lopts.DmVerityCreateArgs)

internal/tools/uvmboot/lcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func createLCOWOptions(ctx context.Context, c *cli.Context, id string) (*uvm.Opt
274274
options.SecurityPolicyEnforcer = c.String(securityPolicyEnforcerArgName)
275275
}
276276
if c.IsSet(securityHardwareFlag) {
277-
options.GuestStateFile = uvm.GuestStateFile
277+
options.GuestStateFilePath = uvm.GuestStateFile
278278
options.SecurityPolicyEnabled = true
279279
options.AllowOvercommit = false
280280
}

internal/uvm/create.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ type Options struct {
131131
ConsolePipe string // The named pipe path to use for the serial console (COM1). eg \\.\pipe\vmpipe
132132
}
133133

134+
type ConfidentialCommonOptions struct {
135+
GuestStateFilePath string // The vmgs file path to load
136+
SecurityPolicy string // Optional security policy
137+
SecurityPolicyEnabled bool // Set when there is a security policy to apply on actual SNP hardware, use this rathen than checking the string length
138+
SecurityPolicyEnforcer string // Set which security policy enforcer to use (open door or rego). This allows for better fallback mechanic.
139+
UVMReferenceInfoFile string // Path to the file that contains the signed UVM measurements
140+
}
141+
134142
func verifyWCOWBootFiles(bootFiles *WCOWBootFiles) error {
135143
if bootFiles == nil {
136144
return fmt.Errorf("boot files is nil")
@@ -323,8 +331,8 @@ func (uvm *UtilityVM) CloseCtx(ctx context.Context) (err error) {
323331
_ = uvm.WaitCtx(ctx)
324332
}
325333

326-
if lopts, ok := uvm.createOpts.(*OptionsLCOW); ok && uvm.HasConfidentialPolicy() && lopts.GuestStateFile != "" {
327-
vmgsFullPath := filepath.Join(lopts.BundleDirectory, lopts.GuestStateFile)
334+
if lopts, ok := uvm.createOpts.(*OptionsLCOW); ok && uvm.HasConfidentialPolicy() && lopts.GuestStateFilePath != "" {
335+
vmgsFullPath := filepath.Join(lopts.BundleDirectory, lopts.GuestStateFilePath)
328336
e := log.G(ctx).WithField("VMGS file", vmgsFullPath)
329337
e.Debug("removing VMGS file")
330338
if err := os.Remove(vmgsFullPath); err != nil {

internal/uvm/create_lcow.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,12 @@ const (
9090
)
9191

9292
type ConfidentialLCOWOptions struct {
93-
GuestStateFile string // The vmgs file to load
94-
UseGuestStateFile bool // Use a vmgs file that contains a kernel and initrd, required for SNP
95-
SecurityPolicy string // Optional security policy
96-
SecurityPolicyEnabled bool // Set when there is a security policy to apply on actual SNP hardware, use this rathen than checking the string length
97-
SecurityPolicyEnforcer string // Set which security policy enforcer to use (open door, standard or rego). This allows for better fallback mechanic.
98-
UVMReferenceInfoFile string // Filename under `BootFilesPath` for (potentially signed) UVM image reference information.
99-
BundleDirectory string // pod bundle directory
100-
DmVerityRootFsVhd string // The VHD file (bound to the vmgs file via embedded dmverity hash data file) to load.
101-
DmVerityMode bool // override to be able to turn off dmverity for debugging
102-
DmVerityCreateArgs string // set dm-verity args when booting with verity in non-SNP mode
93+
*ConfidentialCommonOptions
94+
UseGuestStateFile bool // Use a vmgs file that contains a kernel and initrd, required for SNP
95+
BundleDirectory string // pod bundle directory
96+
DmVerityRootFsVhd string // The VHD file (bound to the vmgs file via embedded dmverity hash data file) to load.
97+
DmVerityMode bool // override to be able to turn off dmverity for debugging
98+
DmVerityCreateArgs string // set dm-verity args when booting with verity in non-SNP mode
10399
}
104100

105101
// OptionsLCOW are the set of options passed to CreateLCOW() to create a utility vm.
@@ -177,8 +173,10 @@ func NewDefaultOptionsLCOW(id, owner string) *OptionsLCOW {
177173
EnableScratchEncryption: false,
178174
DisableTimeSyncService: false,
179175
ConfidentialLCOWOptions: &ConfidentialLCOWOptions{
180-
SecurityPolicyEnabled: false,
181-
UVMReferenceInfoFile: UVMReferenceInfoFile,
176+
ConfidentialCommonOptions: &ConfidentialCommonOptions{
177+
SecurityPolicyEnabled: false,
178+
UVMReferenceInfoFile: UVMReferenceInfoFile,
179+
},
182180
},
183181
}
184182

@@ -350,7 +348,7 @@ func makeLCOWVMGSDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_
350348
}
351349

352350
// The kernel and minimal initrd are combined into a single vmgs file.
353-
vmgsTemplatePath := filepath.Join(opts.BootFilesPath, opts.GuestStateFile)
351+
vmgsTemplatePath := filepath.Join(opts.BootFilesPath, opts.GuestStateFilePath)
354352
if _, err := os.Stat(vmgsTemplatePath); os.IsNotExist(err) {
355353
return nil, fmt.Errorf("the GuestState vmgs file '%s' was not found", vmgsTemplatePath)
356354
}
@@ -367,7 +365,7 @@ func makeLCOWVMGSDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_
367365
return nil, err
368366
}
369367

370-
vmgsFileFullPath := filepath.Join(opts.BundleDirectory, opts.GuestStateFile)
368+
vmgsFileFullPath := filepath.Join(opts.BundleDirectory, opts.GuestStateFilePath)
371369
if err := copyfile.CopyFile(ctx, vmgsTemplatePath, vmgsFileFullPath, true); err != nil {
372370
return nil, fmt.Errorf("failed to copy VMGS template file: %w", err)
373371
}

internal/uvm/create_wcow.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ var (
4545
)
4646

4747
type ConfidentialWCOWOptions struct {
48-
GuestStateFilePath string // The vmgs file path
49-
SecurityPolicyEnabled bool // Set when there is a security policy to apply on actual SNP hardware, use this rathen than checking the string length
50-
SecurityPolicy string // Optional security policy
51-
SecurityPolicyEnforcer string // Set which security policy enforcer to use (open door or rego). This allows for better fallback mechanic.
52-
UVMReferenceInfoFile string // Path to the file that contains the signed UVM measurements
53-
48+
*ConfidentialCommonOptions
5449
/* Below options are only included for testing/debugging purposes - shouldn't be used in regular scenarios */
5550
IsolationType string
5651
DisableSecureBoot bool
@@ -111,7 +106,9 @@ func NewDefaultOptionsWCOW(id, owner string) *OptionsWCOW {
111106
Options: newDefaultOptions(id, owner),
112107
AdditionalRegistryKeys: []hcsschema.RegistryValue{},
113108
ConfidentialWCOWOptions: &ConfidentialWCOWOptions{
114-
SecurityPolicyEnabled: false,
109+
ConfidentialCommonOptions: &ConfidentialCommonOptions{
110+
SecurityPolicyEnabled: false,
111+
},
115112
},
116113
OutputHandlerCreator: parseLogrus,
117114
ForwardLogs: true, // Default to true for WCOW, and set to false for CWCOW in internal/oci/uvm.go SpecToUVMCreateOpts

0 commit comments

Comments
 (0)