Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jkl73
Copy link
Contributor

@jkl73 jkl73 commented Sep 7, 2024

CEL code was written based on TPM PCR. Now we want to support RTMR based CEL.

  1. Add a new AppendEventRTMR to support rtmr CEL

@jkl73 jkl73 force-pushed the parsertmrverify branch 2 times, most recently from f59a705 to f712448 Compare September 11, 2024 00:11
@jkl73 jkl73 changed the title Add support for CEL replay on RMTR/MRTD Refactor CEL AppendEvent, to support RTMR Sep 11, 2024
@jkl73
Copy link
Contributor Author

jkl73 commented Sep 11, 2024

/gcbrun

@jkl73 jkl73 requested a review from alexmwu September 11, 2024 01:03
@jkl73 jkl73 force-pushed the parsertmrverify branch 4 times, most recently from a6590ed to 878d7ad Compare September 21, 2024 00:13
@jkl73
Copy link
Contributor Author

jkl73 commented Sep 21, 2024

/gcbrun

@jkl73
Copy link
Contributor Author

jkl73 commented Sep 21, 2024

/gcbrun

1 similar comment
@jkl73
Copy link
Contributor Author

jkl73 commented Sep 21, 2024

/gcbrun

@jkl73
Copy link
Contributor Author

jkl73 commented Sep 21, 2024

/gcbrun

}

// append TPM PCR event to eventlog
return a.cosCel.AppendEvent(cel.CosEventPCR, event, tpmDigestsmap)
Copy link
Collaborator

Choose a reason for hiding this comment

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

MeasureEvent only appends TPM PCR event, do u have a plan to have support for measuring RTMR event to event log and integration into the current container runner for TDX CS image?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is done in a different PR. #478

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AppendEvent is now register-agnostics, then actual "extend" operation on pcr or rtmr should be done outside "AppendEvent" function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Given that MeasureEvent appends TPM PCR event, could you rename it to something like MeasurePCREvent to distinguish it from RMTR event measurement?

return getCosStateFromCEL(rawCanonicalEventLog, cryptoHash, pcrs.GetPcrs())
}

func parseCanonicalEventLogRTMR(rawCanonicalEventLog []byte, rtmrs [][]byte) (*pb.MachineState, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two things:

  1. could you export this function because GAV will likely consume it.
  2. From GAV perspective, what's the source of rtmrs? I know rawCanonicalEventLog comes from this proto field(https://source.corp.google.com/piper///depot/google3/google/cloud/confidentialcomputing/v1main/service.proto;rcl=650697927;l=231), but where can I locate rtmrs which is a digest array?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to Yawang. Could you export this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

You should just use the register.RTMRBank type since that's what go-eventlog and go-tdx-guest use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • could you export this function because GAV will likely consume it.

I thought this function is only going to be consumed by the server.VerifyAttestation? But sure I can export it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

GAV will consume this function to parse and verify CosState from CEL logs for TDX RTMR. Also looks like this function is not called by server.VerifyAttestation from your PR changes.. so I think export is needed here.

@jkl73 jkl73 requested a review from qinkunbao September 24, 2024 00:29
Copy link
Contributor

@alexmwu alexmwu left a comment

Choose a reason for hiding this comment

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

Given this PR has breaking changes, please note what broke (AppendEvent, Replay) in the description.

type Record struct {
RecNum uint64
PCR uint8
PCR uint8 // can also be RTMR index
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we ever check with the TCG WG about putting a RTMR or CCMR type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not yet, I'll send an email

}
}

func (c *CEL) AppendEvent(index int, event Content, digestsMap map[crypto.Hash][]byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

You do not mention how callers should populate digestsMap. Regardless, passing digestsMap seems like the wrong interface since the value is derivable from content.

Maybe we should pass either a func or a type that implements an interface as follows:

type Extender interface {
  // Extend hash extends the given MR bank's index with the supplied digest.
  Extend(crypto.Hash, int, []byte) error
}

This also has the pro of decoupling the cel package from needing a real/simulated TPM to test AppendEvent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought about this I also think it's better. We need have configfsi.Client type and the tpm type to implement this interface, I think I can do this later.

For now I just created two separate functions fro RTMR and PCR.

return getCosStateFromCEL(rawCanonicalEventLog, cryptoHash, pcrs.GetPcrs())
}

func parseCanonicalEventLogRTMR(rawCanonicalEventLog []byte, rtmrs [][]byte) (*pb.MachineState, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should just use the register.RTMRBank type since that's what go-eventlog and go-tdx-guest use.

@jkl73 jkl73 force-pushed the parsertmrverify branch 3 times, most recently from c1e95d0 to bb5785b Compare October 2, 2024 23:25
Comment on lines 806 to 822
// Faking PCR with RTMR
imposterPcrBank := map[uint32][]byte{}
imposterPcrBank[1] = rtmrBank.RTMRs[0].Digest
imposterPcrBank[2] = rtmrBank.RTMRs[1].Digest
imposterPcrBank[3] = rtmrBank.RTMRs[2].Digest
imposterPcrBank[4] = rtmrBank.RTMRs[3].Digest
imposterPcrs := &pb.PCRs{Hash: pb.HashAlgo_SHA384, Pcrs: imposterPcrBank}

if msState, err = ParseCosCanonicalEventLogPCR(buf.Bytes(), imposterPcrs); err != nil {
t.Errorf("expecting no error from parseCosEventLogRTMR(), but get %v", err)
} else {
if diff := cmp.Diff(msState.Cos.Container, &attestpb.ContainerState{}, protocmp.Transform()); diff != "" {
t.Error("expect no claims when replaying against imposter PCR")
}
if diff := cmp.Diff(msState.Cos.HealthMonitoring, &attestpb.HealthMonitoringState{}, protocmp.Transform()); diff != "" {
t.Error("expect no claims when replaying against imposter PCR")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go in a separate test that makes it clear what you're trying to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will refactor in the next PR

}

// AppendEventPCR appends a new PCR record to the CEL.
func (c *CEL) AppendEventPCR(tpm io.ReadWriteCloser, pcr int, hashAlgos []crypto.Hash, event Content) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I will again note that adding an AppendEvent[RegisterType] seems like the wrong interface. We will have to add a new one if we ever want to support NV registers, ARM registers, SVSM-simulated registers, GPU registers, etc.. This also introduces new dependencies every time we support a new register type since we have to create AppendEventARM and then import the ARM register library. Hopefully that's not often, but it's possible other companies decide to follow the Intel model.

I do think passing an extend func/interface as a parameter is the right call due to the decoupling, but I will leave this as optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, AppendEvent should work on arbitrary register type (instead of creating one AppendEvent for each). The change involves upstream go-tdx-guest, I will keep this for now, and update it in a later PR.

@qinkunbao
Copy link
Contributor

/gcbrun

@jkl73 jkl73 force-pushed the parsertmrverify branch 4 times, most recently from dd82acc to 96b1a14 Compare October 3, 2024 18:51
@jkl73
Copy link
Contributor Author

jkl73 commented Oct 3, 2024

/gcbrun

Add new RTMR CEL AppendEventRTMR
Redirect AppendEvent to AppendEventPCR

Signed-off-by: Jiankun Lu <[email protected]>
@jkl73
Copy link
Contributor Author

jkl73 commented Oct 3, 2024

/gcbrun

@jkl73 jkl73 merged commit 3332c30 into google:main Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants