Skip to content

Commit 8d6f821

Browse files
committed
Pass CWCOW UVM measurements to sidecar GCS
A reference_info.cose file is usually shipped along with other UVM boot files. This file contains signed measurements of the UVM. We need to pass the contents of this file to the sidecar GCS so that it can make it available to the containers running inside the UVM. Signed-off-by: Amit Barve <[email protected]>
1 parent b7dc4bc commit 8d6f821

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

internal/gcs-sidecar/host.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ func (h *Host) SetWCOWConfidentialUVMOptions(ctx context.Context, securityPolicy
182182

183183
h.securityPolicyEnforcer = p
184184
h.securityPolicyEnforcerSet = true
185+
h.uvmReferenceInfo = securityPolicyRequest.EncodedUVMReference
185186

186187
return nil
187188
}

internal/oci/uvm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ func handleWCOWSecurityPolicy(ctx context.Context, a map[string]string, wopts *u
248248
wopts.SecurityPolicyEnforcer = ParseAnnotationsString(a, annotations.WCOWSecurityPolicyEnforcer, wopts.SecurityPolicyEnforcer)
249249
wopts.DisableSecureBoot = ParseAnnotationsBool(ctx, a, annotations.WCOWDisableSecureBoot, false)
250250
wopts.GuestStateFilePath = ParseAnnotationsString(a, annotations.WCOWGuestStateFile, uvm.GetDefaultConfidentialVMGSPath())
251+
wopts.UVMReferenceInfoFile = ParseAnnotationsString(a, annotations.WCOWReferenceInfoFile, uvm.GetDefaultReferenceInfoFilePath())
251252
wopts.IsolationType = "SecureNestedPaging"
252253
if noSecurityHardware := ParseAnnotationsBool(ctx, a, annotations.NoSecurityHardware, false); noSecurityHardware {
253254
wopts.IsolationType = "GuestStateOnly"

internal/protocol/guestresource/resources.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,5 @@ type LCOWSecurityPolicyFragment struct {
244244
type WCOWConfidentialOptions struct {
245245
EnforcerType string `json:"EnforcerType,omitempty"`
246246
EncodedSecurityPolicy string `json:"EncodedSecurityPolicy,omitempty"`
247-
// Optional security policy
248-
WCOWSecurityPolicy string
249-
// Set when there is a security policy to apply on actual SNP hardware, use this rathen than checking the string length
250-
WCOWSecurityPolicyEnabled bool
251-
// Set which security policy enforcer to use (open door or rego). This allows for better fallback mechanic.
252-
WCOWSecurityPolicyEnforcer string
247+
EncodedUVMReference string `json:"EncodedUVMReference,omitempty"`
253248
}

internal/uvm/create_wcow.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type ConfidentialWCOWOptions struct {
4949
SecurityPolicyEnabled bool // Set when there is a security policy to apply on actual SNP hardware, use this rathen than checking the string length
5050
SecurityPolicy string // Optional security policy
5151
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
5253

5354
/* Below options are only included for testing/debugging purposes - shouldn't be used in regular scenarios */
5455
IsolationType string
@@ -90,6 +91,10 @@ func GetDefaultConfidentialEFIPath() string {
9091
return filepath.Join(defaultConfidentialWCOWOSBootFilesPath(), "boot.vhd")
9192
}
9293

94+
func GetDefaultReferenceInfoFilePath() string {
95+
return filepath.Join(defaultConfidentialWCOWOSBootFilesPath(), "reference_info.cose")
96+
}
97+
9398
// NewDefaultOptionsWCOW creates the default options for a bootable version of
9499
// WCOW. The caller `MUST` set the `BootFiles` on the returned value.
95100
//

internal/uvm/security_policy.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ func WithWCOWSecurityPolicyEnforcer(enforcer string) WCOWConfidentialUVMOpt {
5353
}
5454
}
5555

56+
// WithUVMReferenceInfo reads UVM reference info file and base64 encodes the
57+
// content before setting it for the resource. This is no-op if the
58+
// path is empty or the file doesn't exist.
59+
func WithWCOWUVMReferenceInfo(path string) WCOWConfidentialUVMOpt {
60+
return func(ctx context.Context, r *guestresource.WCOWConfidentialOptions) error {
61+
encoded, err := base64EncodeFileContents(path)
62+
if err != nil {
63+
if os.IsNotExist(err) {
64+
log.G(ctx).WithField("filePath", path).Debug("UVM reference info file not found")
65+
return nil
66+
}
67+
return fmt.Errorf("failed to read UVM reference info file: %w", err)
68+
}
69+
r.EncodedUVMReference = encoded
70+
return nil
71+
}
72+
}
73+
5674
func (uvm *UtilityVM) SetWCOWConfidentialUVMOptions(ctx context.Context, opts ...WCOWConfidentialUVMOpt) error {
5775
if uvm.operatingSystem != "windows" {
5876
return errNotSupported

internal/uvm/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ func (uvm *UtilityVM) Start(ctx context.Context) (err error) {
341341
copts := []WCOWConfidentialUVMOpt{
342342
WithWCOWSecurityPolicy(uvm.createOpts.(*OptionsWCOW).SecurityPolicy),
343343
WithWCOWSecurityPolicyEnforcer(uvm.createOpts.(*OptionsWCOW).SecurityPolicyEnforcer),
344+
WithWCOWUVMReferenceInfo(uvm.createOpts.(*OptionsWCOW).UVMReferenceInfoFile),
344345
}
345346
if err := uvm.SetWCOWConfidentialUVMOptions(ctx, copts...); err != nil {
346347
return err

0 commit comments

Comments
 (0)