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
1 change: 1 addition & 0 deletions pkg/securitypolicy/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
HashEnvelopeReferenceInfoFilename = "transparent-reference-info-base64"
TCBReferenceInfoFilename = "tcb-reference-info-base64"
PlatformReferenceInfoFilename = "platform-reference-info-base64"
TransparencyTrustListFilename = "transparency-trust-list-base64"
)

// PolicyConfig contains toml or JSON config for security policy.
Expand Down
62 changes: 52 additions & 10 deletions pkg/securitypolicy/securitypolicy_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ type SecurityOptions struct {
UvmHashEnvelopeReferenceInfo string
policyMutex sync.Mutex

// Used for both tcbReferenceInfo and platformReferenceInfo
platformReferenceInfoMutex sync.RWMutex
tcbReferenceInfo []byte
platformReferenceInfo []byte
fragmentInjectedSecurityContextMutex sync.RWMutex
tcbReferenceInfo []byte
platformReferenceInfo []byte
// The "first-party TTL" we will put in security-context the next time
// we start a container. This is populated when we receive a fragment
// injection request with a TTL, and the TTL issuer and subject
// matches constants defined below.
transparencyTrustList []byte
transparencyTrustListSVN int64

logWriter io.Writer
runtimeLoggingChanged func(bool)
Expand Down Expand Up @@ -179,6 +184,21 @@ const (
mediaTypePlatformReferenceInfo = "application/vnd.platform-reference-info.v1+cose"
)

// The following 4 constants identify our "first party" TTL, which when
// received we will put in the security-context directory. It is intended
// for the application to send alongside the transparent UVM or TCB
// reference info to a relying party. A matching TTL is added to the
// security context regardless of whether it is accepted by the Rego
// policy (from the gcs's perspective it being in the security-context is
// purely infromative, and we do not otherwise give such a TTL special
// privileges or use keys in it without first consulting the policy).
const (
firstPartyTTLIssuer = "did:x509:0:sha256:I__iuL25oXEVFdTP_aBLx_eT1RPHbCQ_ECBQfYZpt9s::eku:1.3.6.1.4.1.311.76.59.1.3"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how like are these to change in the future? Would we rather (e.g.) go embed and supply a JSON array with values at compile time?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as the issuer for fragments and UVM endorsements. Hopefully not likely, because this value needs to be communicated to Relying Parties, who need to pin it and use to verify the TTLs we publish, it's not something we can change unilaterally without breaking RPs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Amaury, I think basically once this goes live we will not have an easy way to change it anymore (same for issuer of UVM endorsement etc)

firstPartyTTLSubject = "mcr.microsoft.com/aci/aci-cc-ttl"
firstPartyTTLIssuerTest = "did:x509:0:sha256:wVkSM46SDpw4LuyEYoH6r5ym07whL5lWxNlGN-UPtf4::eku:1.3.6.1.4.1.311.10.3.13"
firstPartyTTLSubjectTest = "acidevacr.azurecr.io/internal/aci/aci-cc-ttl"
)

// asInt64 coerces a CBOR-decoded integer value (which may be returned as
// int64, uint64 or int by different decoders) to an int64.
func asInt64(v interface{}) (int64, error) {
Expand Down Expand Up @@ -308,13 +328,13 @@ func (s *SecurityOptions) InjectFragment(ctx context.Context, fragment *guestres

// We do not need to validate this.
if mediaType == mediaTypeTCBReferenceInfo || mediaType == mediaTypePlatformReferenceInfo {
s.platformReferenceInfoMutex.Lock()
s.fragmentInjectedSecurityContextMutex.Lock()
if mediaType == mediaTypeTCBReferenceInfo {
s.tcbReferenceInfo = append(s.tcbReferenceInfo[:0], raw...)
} else {
s.platformReferenceInfo = append(s.platformReferenceInfo[:0], raw...)
}
s.platformReferenceInfoMutex.Unlock()
s.fragmentInjectedSecurityContextMutex.Unlock()
return nil
}

Expand Down Expand Up @@ -383,6 +403,20 @@ func (s *SecurityOptions) InjectFragment(ctx context.Context, fragment *guestres
return errors.Wrap(err, "failed to parse transparency trust list payload")
}

if (issuer == firstPartyTTLIssuer && feed == firstPartyTTLSubject) ||
(issuer == firstPartyTTLIssuerTest && feed == firstPartyTTLSubjectTest) {
s.fragmentInjectedSecurityContextMutex.Lock()
// This SVN non-rollback check is just to prevent older TTLs
// from overwriting newer ones even if the older one comes
// later in the injection order. It is not otherwise a
// security feature.
if len(s.transparencyTrustList) == 0 || s.transparencyTrustListSVN <= *svnFromCwt {
s.transparencyTrustList = append(s.transparencyTrustList[:0], raw...)
s.transparencyTrustListSVN = *svnFromCwt
Comment on lines +413 to +415
}
s.fragmentInjectedSecurityContextMutex.Unlock()
}

// feed is the "subject" in the new-style envelope terminology.
log.G(ctx).WithFields(logrus.Fields{
"issuer": issuer,
Expand Down Expand Up @@ -466,22 +500,25 @@ 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.platformReferenceInfoMutex.RLock()
var tcbReferenceInfoBase64, platformReferenceInfoBase64 string
s.fragmentInjectedSecurityContextMutex.RLock()
var tcbReferenceInfoBase64, platformReferenceInfoBase64, transparencyTrustListBase64 string
if len(s.tcbReferenceInfo) > 0 {
tcbReferenceInfoBase64 = base64.StdEncoding.EncodeToString(s.tcbReferenceInfo)
}
if len(s.platformReferenceInfo) > 0 {
platformReferenceInfoBase64 = base64.StdEncoding.EncodeToString(s.platformReferenceInfo)
}
s.platformReferenceInfoMutex.RUnlock()
if len(s.transparencyTrustList) > 0 {
transparencyTrustListBase64 = base64.StdEncoding.EncodeToString(s.transparencyTrustList)
}
s.fragmentInjectedSecurityContextMutex.RUnlock()
// HostAMDCertificate is a deprecated alias of the LCOW key. Prefer that
// key, but preserve support for callers that supply the WCOW key.
hostAMDCert := spec.Annotations[annotations.LCOWHostAMDCertificate]
if hostAMDCert == "" {
hostAMDCert = spec.Annotations[annotations.WCOWHostAMDCertificate]
}
if len(encodedPolicy) > 0 || len(hostAMDCert) > 0 || len(s.UvmReferenceInfo) > 0 || len(s.UvmHashEnvelopeReferenceInfo) > 0 || len(tcbReferenceInfoBase64) > 0 || len(platformReferenceInfoBase64) > 0 {
if len(encodedPolicy) > 0 || len(hostAMDCert) > 0 || len(s.UvmReferenceInfo) > 0 || len(s.UvmHashEnvelopeReferenceInfo) > 0 || len(tcbReferenceInfoBase64) > 0 || len(platformReferenceInfoBase64) > 0 || len(transparencyTrustListBase64) > 0 {
// Use os.MkdirTemp to make sure that the directory is unique.
securityContextDir, err := os.MkdirTemp(spec.Root.Path, SecurityContextDirTemplate)
if err != nil {
Expand Down Expand Up @@ -517,6 +554,11 @@ func (s *SecurityOptions) WriteSecurityContextDir(spec *specs.Spec) (string, err
return "", fmt.Errorf("failed to write platform reference info: %w", err)
}
}
if len(transparencyTrustListBase64) > 0 {
if err := writeFileInDir(securityContextDir, TransparencyTrustListFilename, []byte(transparencyTrustListBase64), 0777); err != nil {
return "", fmt.Errorf("failed to write transparency trust list: %w", err)
}
}

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