Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memory monitor measurement logics #408

Merged
merged 2 commits into from
Feb 9, 2024

Conversation

yawangwang
Copy link
Collaborator

@yawangwang yawangwang commented Jan 23, 2024

This PR removes the existing experiment flag EnableMemoryMonitoring and add a new experiment flag EnableMeasureMemoryMonitor to gate the memory monitoring measurement logics.

@yawangwang yawangwang force-pushed the add-mem-monitor-measurement branch 5 times, most recently from 15808b4 to cdd35d8 Compare January 24, 2024 01:11
@yawangwang yawangwang marked this pull request as ready for review January 25, 2024 01:29
}

var memoryMonitoringEnabledBit uint8
if status == "active" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also including "activating" status here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

// measureMemoryMonitor will measure the current memory monitoring state into the COS
// eventlog in the AttestationAgent.
func (r *ContainerRunner) measureMemoryMonitor(ctx context.Context) error {
s, err := systemctl.New()
Copy link
Contributor

Choose a reason for hiding this comment

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

probably don't need to create a new systemctl client here, you can try to pass it in as a parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, try to get the MemoryMonitor status outside of this function

Copy link
Collaborator Author

@yawangwang yawangwang Feb 1, 2024

Choose a reason for hiding this comment

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

Discussed offline, we should measure the memory monitoring decision made by container launcher.
Done.

@yawangwang yawangwang requested a review from jkl73 February 1, 2024 18:43
@yawangwang yawangwang force-pushed the add-mem-monitor-measurement branch 5 times, most recently from abe77fe to 4bf5512 Compare February 2, 2024 18:18
EventType: cel.LaunchSeparatorType,
EventContent: nil, // Success
}
return r.attestAgent.MeasureEvent(separator)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily related to this PR, but we need a unit test to ensure the separator always gets measured. Since you moved this around, can you add one for measureCELEvents? Perhaps also ensure we get the workload digest and ID

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we have a test for different launchspec inputs if that doesn't exist.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, created a fake container and fake container image to "fake" dependencies that measureCELEvents need. Added a unit test to container_runnter_test.go for different launchspec inputs.

@@ -42,6 +43,19 @@ func (s *Systemctl) Stop(unit string) error {
return runSystemdCmd(s.dbus.StopUnitContext, "stop", unit)
}

// GetStatus is the equivalent of `systemctl is-active $unit`.
// The status can be "active", "activating", "deactivating", "inactive" or "failed".
func (s *Systemctl) GetStatus(ctx context.Context, unit string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this should be called IsActive so that it matches the systemctl API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@yawangwang yawangwang force-pushed the add-mem-monitor-measurement branch 3 times, most recently from 6d816fb to f5c6251 Compare February 7, 2024 01:52
}

for _, wantEvent := range tc.wantCELEvents {
if !slices.Contains(gotEvents, cel.CosType(wantEvent)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Order matters here, at least for the separator which should be last. Use cmp.Equal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 554 to 559
if err := r.measureCELEvents(ctx); err != nil {
return fmt.Errorf("failed to measure CEL events: %v", err)
}

if err := r.fetchAndWriteToken(ctx); err != nil {
return fmt.Errorf("failed to fetch and write OIDC token: %v", err)
Copy link
Contributor

@alexmwu alexmwu Feb 7, 2024

Choose a reason for hiding this comment

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

Measurements should happen before experiments turn on and potentially introduce side effects. So please move this back to the beginning of Run. We should measure first, and it's okay to enable memory monitoring after, even if it fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

},
{
name: "measure memory monitoring event and launch separator event",
wantCELEvents: []cel.CosType{cel.LaunchSeparatorType, cel.MemoryMonitorType},
Copy link
Contributor

Choose a reason for hiding this comment

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

wantCELEvents should have the separator last.

Copy link
Contributor

Choose a reason for hiding this comment

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

and above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@yawangwang
Copy link
Collaborator Author

/gcbrun

@yawangwang yawangwang merged commit f1aa3d2 into google:main Feb 9, 2024
11 checks passed
alexmwu added a commit to alexmwu/go-tpm-tools that referenced this pull request Feb 22, 2024
New Features:
[launcher] Add TEE server IPC implementation google#367
[launcher] Enable memory monitoring in CS google#391
Use TDX quote provider to attest and verify google#405
Integrate nonce verification as part of the TDX quote validation procedure. google#395
Add RISC V support google#407
[launcher] Use resizable integrity-fs with in-memory tags google#412

Bug Fixes:
[launcher] Fix launcher exit code google#384
[launcher] Handle exit code checking during deferral evaluation google#392
[cmd] Skip tests that call setGCEAKTemplate google#402
[launcher] Fix teeserver context reset issue & add container signature cache google#397
Set all unused parameters as _ to fix CI lint failure google#411
[launcher] Make customtoken test sleep to mitigate clock skew google#413

Other Changes:
Add eventlog parse logics for memory monitoring google#404
[launcher]: Add memory monitor measurement logics google#408
Update go-tdx-guest version to v0.3.1 google#414

New Contributors:
@KeithMoyer in google#392
@vbalain in google#405
@aimixsaka in google#407
@alexmwu alexmwu mentioned this pull request Feb 22, 2024
alexmwu added a commit that referenced this pull request Feb 22, 2024
New Features:
[launcher] Add TEE server IPC implementation #367
[launcher] Enable memory monitoring in CS #391
Use TDX quote provider to attest and verify #405
Integrate nonce verification as part of the TDX quote validation procedure. #395
Add RISC V support #407
[launcher] Use resizable integrity-fs with in-memory tags #412

Bug Fixes:
[launcher] Fix launcher exit code #384
[launcher] Handle exit code checking during deferral evaluation #392
[cmd] Skip tests that call setGCEAKTemplate #402
[launcher] Fix teeserver context reset issue & add container signature cache #397
Set all unused parameters as _ to fix CI lint failure #411
[launcher] Make customtoken test sleep to mitigate clock skew #413

Other Changes:
Add eventlog parse logics for memory monitoring #404
[launcher]: Add memory monitor measurement logics #408
Update go-tdx-guest version to v0.3.1 #414

New Contributors:
@KeithMoyer in #392
@vbalain in #405
@aimixsaka in #407
alexmwu added a commit to alexmwu/go-tpm-tools that referenced this pull request Mar 29, 2024
New Features:
[launcher] Add TEE server IPC implementation google#367
[launcher] Enable memory monitoring in CS google#391
Use TDX quote provider to attest and verify google#405
Integrate nonce verification as part of the TDX quote validation procedure. google#395
Add RISC V support google#407
[launcher] Use resizable integrity-fs with in-memory tags google#412

Bug Fixes:
[launcher] Fix launcher exit code google#384
[launcher] Handle exit code checking during deferral evaluation google#392
[cmd] Skip tests that call setGCEAKTemplate google#402
[launcher] Fix teeserver context reset issue & add container signature cache google#397
Set all unused parameters as _ to fix CI lint failure google#411
[launcher] Make customtoken test sleep to mitigate clock skew google#413

Other Changes:
Add eventlog parse logics for memory monitoring google#404
[launcher]: Add memory monitor measurement logics google#408
Update go-tdx-guest version to v0.3.1 google#414

New Contributors:
@KeithMoyer in google#392
@vbalain in google#405
@aimixsaka in google#407
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.

None yet

3 participants