-
Notifications
You must be signed in to change notification settings - Fork 168
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
Send TPM logs and EFI variables to monitor app #4672
Open
rucoder
wants to merge
8
commits into
lf-edge:master
Choose a base branch
from
rucoder:rucoder/monitor-tpm-log
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+226
−7
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f52e94
Use eve-rust 1.84.1 for building monitor
rucoder d16427a
Enable BigFrames for monitor IPC transport
rucoder 2dbdb84
Fix isOnboarded() for monitor
rucoder 7f5054a
Add functions and types to read EFI variables
rucoder 12a0502
Add types and functions to send TPM log to monitor
rucoder 0b020f9
Send TPM logs when Vault goes to error state
rucoder 73ca9e6
Add .dockerignore to pkg/monitor
rucoder 269e566
Integrate monitor-rs version v0.2.1
rucoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eve-monitor-rs/target/ | ||
.idea | ||
.vscode | ||
**/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,8 +90,9 @@ func (s *monitorIPCServer) handleConnection(conn net.Conn) { | |
s.Lock() | ||
defer s.Unlock() | ||
// the format of the frame is length + data | ||
// where the length is 16 bit unsigned integer | ||
// where the length is 32 bit unsigned integer | ||
s.codec = framed.NewReadWriteCloser(conn) | ||
s.codec.EnableBigFrames() | ||
|
||
go func() { | ||
defer s.close() | ||
|
@@ -169,14 +170,24 @@ func (s *monitorIPCServer) sendIpcMessage(t string, msg any) error { | |
defer s.Unlock() | ||
|
||
var err error | ||
var data []byte | ||
|
||
if data, err := json.Marshal(msg); err == nil { | ||
if data, err = json.Marshal(msg); err == nil { | ||
ipcMessage := ipcMessage{Type: t, Message: json.RawMessage(data)} | ||
if data, err = json.Marshal(ipcMessage); err == nil { | ||
log.Noticef("Sending IPC message: %s", string(data)) | ||
if t == "TpmLogs" { | ||
log.Noticef("Sending IPC message: %s", t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about use |
||
} else { | ||
log.Noticef("Sending IPC message: %s", string(data)) | ||
} | ||
_, err = s.codec.Write(data) | ||
|
||
if err != nil { | ||
log.Errorf("Failed to send IPC message: %v", err) | ||
} | ||
} | ||
} | ||
|
||
return err | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) 2025 Zededa, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package monitor | ||
|
||
import ( | ||
"io/fs" | ||
"reflect" | ||
"sort" | ||
"testing" | ||
"testing/fstest" | ||
) | ||
|
||
func TestReadEfiVars(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fsys fstest.MapFS | ||
want []efiVariable | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "successful read with multiple boot variables", | ||
fsys: fstest.MapFS{ | ||
"BootOrder": &fstest.MapFile{Data: []byte{0x01, 0x02}}, | ||
"Boot0001": &fstest.MapFile{Data: []byte("var1")}, | ||
"Boot0002": &fstest.MapFile{Data: []byte("var2")}, | ||
"BootDir": &fstest.MapFile{Mode: fs.ModeDir}, // Should be skipped | ||
"Invalid": &fstest.MapFile{Data: []byte("invalid")}, // Doesn't match regex | ||
}, | ||
want: []efiVariable{ | ||
{Name: "BootOrder", Value: []byte{0x01, 0x02}}, | ||
{Name: "Boot0001", Value: []byte("var1")}, | ||
{Name: "Boot0002", Value: []byte("var2")}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "missing BootOrder file", | ||
fsys: fstest.MapFS{ | ||
"Boot0001": &fstest.MapFile{Data: []byte("var1")}, | ||
}, | ||
want: []efiVariable{}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid boot variable", | ||
fsys: fstest.MapFS{ | ||
"BootOrder": &fstest.MapFile{Data: []byte{0x01, 0x02}}, | ||
"Boot123": &fstest.MapFile{Data: []byte("var1")}, // Doesn't match regex | ||
"Boot0001": &fstest.MapFile{Data: []byte("var1")}, | ||
}, | ||
want: []efiVariable{ | ||
{Name: "Boot0001", Value: []byte("var1")}, | ||
{Name: "BootOrder", Value: []byte{0x01, 0x02}}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := readEfiVars(tt.fsys) | ||
if (err != nil) != tt.wantErr { | ||
t.Logf("Test: %s", tt.name) | ||
t.Fatalf("readEfiVars() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
if !tt.wantErr { | ||
// Sort boot variables for consistent comparison | ||
sortBootVars(got) | ||
sortBootVars(tt.want) | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Logf("Test: %s", tt.name) | ||
t.Fatalf("readEfiVars() = %+v, want %+v", got, tt.want) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// sortBootVars sorts boot variables by Name | ||
func sortBootVars(vars []efiVariable) { | ||
sort.Slice(vars, func(i, j int) bool { | ||
return vars[i].Name < vars[j].Name | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we need to have these on .gitignore as well?