From b73cc7c8229278ccf15e5d49133e090de495bcaf Mon Sep 17 00:00:00 2001 From: Tingmao Wang Date: Wed, 18 Nov 2026 23:00:16 +0000 Subject: [PATCH] gcs: Expose transparency-trust-list-base64 in security-context based on injected TTLs In order to enable the application to provide with a relying party a full set of transparent endorsements, we also expose a "first party" TTL in the security context that we believe allows verification of the transparent UVM reference info and TCB reference info. Such a TTL will be delivered via the fragment injection mechanism like for TTLs for transparent fragments, and GCS identifies such a TTL via hard-coded issuer and subject strings. When such a TTL is injected, it is used to populate the transparency-trust-list-base64 file on next container start. Using it as the content of transparency-trust-list-base64 is the only "special treatment" applied to such TTLs. GCS does not otherwise give it any more trust than allowed by the policy. COSE signature and issuer certificate checks are applied to all injected TTLs, before this matching is done. A malformed or not-correctly-signed TTL would not be used for the security context file even if the COSE envelope header claims the correct issuer and subject. Assisted-by: GitHub-Copilot Signed-off-by: Tingmao Wang --- pkg/securitypolicy/securitypolicy.go | 1 + pkg/securitypolicy/securitypolicy_options.go | 62 ++++++++++++++++---- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/pkg/securitypolicy/securitypolicy.go b/pkg/securitypolicy/securitypolicy.go index 32f9ce097b..3d70e94ced 100644 --- a/pkg/securitypolicy/securitypolicy.go +++ b/pkg/securitypolicy/securitypolicy.go @@ -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. diff --git a/pkg/securitypolicy/securitypolicy_options.go b/pkg/securitypolicy/securitypolicy_options.go index 6fbf5a4642..8173058220 100644 --- a/pkg/securitypolicy/securitypolicy_options.go +++ b/pkg/securitypolicy/securitypolicy_options.go @@ -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) @@ -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" + 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) { @@ -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 } @@ -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 + } + s.fragmentInjectedSecurityContextMutex.Unlock() + } + // feed is the "subject" in the new-style envelope terminology. log.G(ctx).WithFields(logrus.Fields{ "issuer": issuer, @@ -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 { @@ -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 {