Skip to content
Open
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
1 change: 1 addition & 0 deletions pkg/securitypolicy/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
HostAMDCertFilename = "host-amd-cert-base64"
ReferenceInfoFilename = "reference-info-base64"
HashEnvelopeReferenceInfoFilename = "transparent-reference-info-base64"
TCBReferenceInfoFilename = "tcb-reference-info"
)

// PolicyConfig contains toml or JSON config for security policy.
Expand Down
24 changes: 22 additions & 2 deletions pkg/securitypolicy/securitypolicy_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type SecurityOptions struct {
UvmReferenceInfo string
UvmHashEnvelopeReferenceInfo string
policyMutex sync.Mutex
tcbReferenceInfoMutex sync.RWMutex
tcbReferenceInfo []byte
logWriter io.Writer
}

Expand Down Expand Up @@ -114,6 +116,9 @@ const (
mediaTypeFragment = "application/cose-x509+rego"
// mediaTypeTransparencyTrustList is a signed Transparency Trust List (TTL).
mediaTypeTransparencyTrustList = "application/vnd.transparency-trust-list.v1+cose"
// mediaTypeTCBReferenceInfo is a TCB reference information COSE blob made
// available to subsequently created containers.
mediaTypeTCBReferenceInfo = "application/vnd.tcb-reference-info.v1+cose"
)

// asInt64 coerces a CBOR-decoded integer value (which may be returned as
Expand Down Expand Up @@ -163,7 +168,7 @@ func (s *SecurityOptions) InjectFragment(ctx context.Context, fragment *guestres
mediaType = mediaTypeFragment
}
switch mediaType {
case mediaTypeFragment, mediaTypeTransparencyTrustList:
case mediaTypeFragment, mediaTypeTransparencyTrustList, mediaTypeTCBReferenceInfo:
default:
// The host (azcri) only ever injects blobs whose media type it knows
// we handle, so receiving an unrecognized one means either a host bug
Expand All @@ -190,6 +195,13 @@ func (s *SecurityOptions) InjectFragment(ctx context.Context, fragment *guestres
if err != nil {
return fmt.Errorf("InjectFragment failed COSE validation: %w", err)
}
// We do not need to validate this.
if mediaType == mediaTypeTCBReferenceInfo {
s.tcbReferenceInfoMutex.Lock()
s.tcbReferenceInfo = append(s.tcbReferenceInfo[:0], raw...)
s.tcbReferenceInfoMutex.Unlock()
return nil
}

cwtClaimsRaw, hasCwtClaims := unpacked.Protected[cosesign1.COSE_Header_CWTClaims]
var cwtClaims map[any]any
Expand Down Expand Up @@ -338,8 +350,11 @@ func writeFileInDir(dir string, filename string, data []byte, perm os.FileMode)
// because there was nothing to write.
func (s *SecurityOptions) WriteSecurityContextDir(spec *specs.Spec) (string, error) {
encodedPolicy := s.PolicyEnforcer.EncodedSecurityPolicy()
s.tcbReferenceInfoMutex.RLock()
tcbReferenceInfo := append([]byte(nil), s.tcbReferenceInfo...)
s.tcbReferenceInfoMutex.RUnlock()
hostAMDCert := spec.Annotations[annotations.WCOWHostAMDCertificate]
if len(encodedPolicy) > 0 || len(hostAMDCert) > 0 || len(s.UvmReferenceInfo) > 0 || len(s.UvmHashEnvelopeReferenceInfo) > 0 {
if len(encodedPolicy) > 0 || len(hostAMDCert) > 0 || len(s.UvmReferenceInfo) > 0 || len(s.UvmHashEnvelopeReferenceInfo) > 0 || len(tcbReferenceInfo) > 0 {
// Use os.MkdirTemp to make sure that the directory is unique.
securityContextDir, err := os.MkdirTemp(spec.Root.Path, SecurityContextDirTemplate)
if err != nil {
Expand All @@ -365,6 +380,11 @@ func (s *SecurityOptions) WriteSecurityContextDir(spec *specs.Spec) (string, err
return "", fmt.Errorf("failed to write UVM hash envelope reference info: %w", err)
}
}
if len(tcbReferenceInfo) > 0 {
if err := writeFileInDir(securityContextDir, TCBReferenceInfoFilename, tcbReferenceInfo, 0777); err != nil {
return "", fmt.Errorf("failed to write TCB reference info: %w", err)
}
}

if len(hostAMDCert) > 0 {
if err := writeFileInDir(securityContextDir, HostAMDCertFilename, []byte(hostAMDCert), 0777); err != nil {
Expand Down
Loading