-
Notifications
You must be signed in to change notification settings - Fork 287
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
Support the capturing of environment variables #327
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ type Config struct { | |
Reporter reporter.Reporter | ||
|
||
Fs *flag.FlagSet | ||
|
||
IncludeEnvVars string | ||
} | ||
|
||
const ( | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |||||||||||||||||
"fmt" | ||||||||||||||||||
"os" | ||||||||||||||||||
"path" | ||||||||||||||||||
"strings" | ||||||||||||||||||
"syscall" | ||||||||||||||||||
"time" | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -88,11 +89,26 @@ func (pm *ProcessManager) updatePidInformation(pid libpf.PID, m *Mapping) (bool, | |||||||||||||||||
if name, err := os.ReadFile(fmt.Sprintf("/prod/%d/comm", pid)); err == nil { | ||||||||||||||||||
processName = string(name) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
envVarMap := make(map[string]string) | ||||||||||||||||||
if envVars, err := os.ReadFile(fmt.Sprintf("/proc/%d/environ", pid)); err == nil { | ||||||||||||||||||
splittedVars := strings.Split(string(envVars), "\000") | ||||||||||||||||||
for _, envVar := range splittedVars { | ||||||||||||||||||
keyValuePair := strings.SplitN(envVar, "=", 2) | ||||||||||||||||||
_, envVarShouldBeCaptured := pm.includeEnvVars[keyValuePair[0]] | ||||||||||||||||||
|
||||||||||||||||||
if envVarShouldBeCaptured { | ||||||||||||||||||
envVarMap[keyValuePair[0]] = keyValuePair[1] | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+98
to
+102
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.
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
info = &processInfo{ | ||||||||||||||||||
name: processName, | ||||||||||||||||||
executable: exePath, | ||||||||||||||||||
mappings: make(map[libpf.Address]*Mapping), | ||||||||||||||||||
mappingsByFileID: make(map[host.FileID]map[libpf.Address]*Mapping), | ||||||||||||||||||
envVariables: envVarMap, | ||||||||||||||||||
tsdInfo: nil, | ||||||||||||||||||
} | ||||||||||||||||||
pm.pidToProcessInfo[pid] = info | ||||||||||||||||||
|
@@ -730,3 +746,14 @@ func (pm *ProcessManager) ProcessedUntil(traceCaptureKTime times.KTime) { | |||||||||||||||||
|
||||||||||||||||||
// Compile time check to make sure we satisfy the interface. | ||||||||||||||||||
var _ tracehandler.TraceProcessor = (*ProcessManager)(nil) | ||||||||||||||||||
|
||||||||||||||||||
func (pm *ProcessManager) EnvVarsForPID(pid libpf.PID) map[string]string { | ||||||||||||||||||
var envVars map[string]string | ||||||||||||||||||
|
||||||||||||||||||
pm.mu.RLock() | ||||||||||||||||||
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. How critical are information about environment variables, that they should hold a global lock on the ProcessManager? 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. When a user requires this information, it has the same criticality as data from other *ForPID functions. In I'd suggest to fetch the data with a single function call / single lock in a follow-up PR. |
||||||||||||||||||
defer pm.mu.RUnlock() | ||||||||||||||||||
if procInfo, ok := pm.pidToProcessInfo[pid]; ok { | ||||||||||||||||||
envVars = procInfo.envVariables | ||||||||||||||||||
} | ||||||||||||||||||
return envVars | ||||||||||||||||||
} |
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.
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.
Are wildcards supposed to be supported?
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.
Not for our usecase
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.
I think with wild cards the mentioned data security issues might become more relevant