Skip to content

Conversation

@olsajiri
Copy link
Contributor

@olsajiri olsajiri commented Oct 13, 2025

storing environment variables into process event data, enabled with --enable-process-environment-variables option,
and we allow to redact info from the variables

reworked a bit the exec data parsing and added the environment variables parsing contributed by @slntopp,
I left the SOB info in some changes, @slntopp please shout if you want to make some changes

@netlify
Copy link

netlify bot commented Oct 13, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit e0d7b24
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/69283ad5cf26ef00083b442d
😎 Deploy Preview https://deploy-preview-4184--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@olsajiri olsajiri added the release-note/minor This PR introduces a minor user-visible change label Oct 13, 2025
@olsajiri olsajiri force-pushed the pr/olsajiri/exec branch 3 times, most recently from 0fbb328 to 9dd22a4 Compare October 13, 2025 22:08
@olsajiri olsajiri force-pushed the pr/olsajiri/exec branch 2 times, most recently from e35bac7 to 310e337 Compare October 17, 2025 11:42
@olsajiri olsajiri force-pushed the pr/olsajiri/exec branch 3 times, most recently from f906c12 to 6a4eec3 Compare November 11, 2025 20:59
@olsajiri olsajiri changed the title Pr/olsajiri/exec tetragon: Add support to retrieve environment variables Nov 11, 2025
@olsajiri olsajiri marked this pull request as ready for review November 11, 2025 21:06
@olsajiri olsajiri requested review from a team and mtardy as code owners November 11, 2025 21:06
@olsajiri olsajiri requested review from jrfastab and kkourt November 11, 2025 21:06
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

Left some comments but the PR is egregious :) Great job!

@olsajiri olsajiri force-pushed the pr/olsajiri/exec branch 2 times, most recently from f4de6a0 to b546118 Compare November 18, 2025 22:16
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks!

Please find some comments below.

var desc dataapi.DataEventDesc

dr := bytes.NewReader(args)
if exec.SizePath != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there legitimate cases where this can be zero? (similarly for the other added sizes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, if probe read fails on the envs data, then EVENT_ERROR_ARGS should be set

Copy link
Contributor

Choose a reason for hiding this comment

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

But we continue reading everything else if I understand correctly from the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

}

#ifdef __LARGE_BPF_PROG
FUNC_INLINE __u32 read_envs(void *ctx, struct msg_execve_event *event)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this work correctly for execs happening from inside the kernel (e.g, call_usrmodehelper and friends).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, environment is stored the same way, so we get it.. like:

{"process_exec":{"process":{"exec_id":"cWVtdS0xOjUyNzE3MDc3ODA3MjoxMjYxOA==","pid":12618,"uid":0,"cwd":"/","binary":"/usr/lib/systemd/systemd-coredump","arguments":"12617 1000 1000 11 1763675427 102400000000 qemu-1 1 3","flags":"execve rootcwd clone","start_time":"2025-11-20T21:50:27.329868374Z","auid":4294967295,"parent_exec_id":"cWVtdS0xOjI5NzAwMDAwMDA6Mg==","tid":12618,"in_init_tree":false,"environment_variables":"HOME=/ TERM=linux PATH=/sbin:/usr/sbin:/bin:/usr/bin"},"parent":{"exec_id":"cWVtdS0xOjI5NzAwMDAwMDA6Mg==","pid":2,"uid":0,"binary":"[kthreadd]","flags":"procFS","start_time":"2025-11-20T21:41:43.129089721Z","auid":4294967295,"parent_exec_id":"cWVtdS0xOjE6MA==","tid":2,"in_init_tree":false}},"node_name":"qemu-1","time":"2025-11-20T21:50:27.329867762Z"}

// tool like nsenter or kubectl exec.
google.protobuf.BoolValue in_init_tree = 20;
// Environment variables passed to the binary at execution.
string environment_variables = 21;
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Should we parse this in user-space and offer an array to the user?
E.g.,

message EnvEntry {
   string Key = 1;
   string Value = 2;
}

And return:

    repeated EnvEntry environment_variables = 21

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 sure.. as you already mentioned catching this impacts performance already,
also it's sort of similar to args string which we handle the same way together with the redaction support

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but splitting a string in userspace (I'm guessing based on a ) character shouldn't have a big impact on performance, no?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'm wondering too if it's not a nice UX improvement that is pretty cheap considering everything that we already do in this gRPC conversion. No strong feelings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will add that

Comment on lines 397 to 409
flags.Bool(KeyEnableProcessEnvironmentVariables, false, "Include environment variables in process_exec events. Disabled by default. Note that this option can significantly increase the size of the events and may impact performance")

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a note about sensitive information in the flag.

E.g., "Include environment variables in process_exec events. Disabled by default. Note that this option can significantly increase the size of the events and may impact performance, as well as capture sensitive information such as passwords in the events"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Member

Choose a reason for hiding this comment

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

"as well as capture sensitive information such as passwords in the events" might be super verbose but we can also mention the feature we have for redacting such content here.

Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

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

Thanks, here are a few comments, I think using size based parsing is cleaner indeed and easier to understand than searching for those NULL bytes.

// tool like nsenter or kubectl exec.
google.protobuf.BoolValue in_init_tree = 20;
// Environment variables passed to the binary at execution.
string environment_variables = 21;
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'm wondering too if it's not a nice UX improvement that is pretty cheap considering everything that we already do in this gRPC conversion. No strong feelings.

@mtardy mtardy added release-note/major This PR introduces major new functionality and removed release-note/minor This PR introduces a minor user-visible change labels Nov 20, 2025
As the comment suggested the filename could be sent through
data event, let's read the filename instead.

Signed-off-by: Jiri Olsa <[email protected]>
We can return just proc object and error without the bool state.

Making nopMsgProcess part of execParse init code so there's no
longer need for the function.

Signed-off-by: Jiri Olsa <[email protected]>
We are about to add another extra info to the exec event (environment
variables), so instead of relying on separators lets add size for each
data and allow the user space easier parsing.

Signed-off-by: Jiri Olsa <[email protected]>
Let's share the functionality in single function.

Signed-off-by: Jiri Olsa <[email protected]>
Adding test for execParse with api.EventErrorFilename and make
sure we get proper results.

Signed-off-by: Jiri Olsa <[email protected]>
Add test for execParse with just filename and make sure
we get proper results.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri olsajiri marked this pull request as draft November 26, 2025 12:02
slntopp and others added 3 commits November 26, 2025 14:29
Adding support to read environment variables.

It's guarded with tg_conf_map::env_vars_enabled variable and
same as for arguments we either use space in the exec event
or send it through separate data event.

Signed-off-by: Mikita Iwanowski <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
It will store environment variables for the process.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri olsajiri force-pushed the pr/olsajiri/exec branch 2 times, most recently from c69ad85 to 02c4cb2 Compare November 26, 2025 22:11
slntopp and others added 10 commits November 27, 2025 09:58
Adding parsing of the environment variables data from the exec
event and the --enable-process-environment-variables option to
enable this feature.

Signed-off-by: Mikita Iwanowski <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Add test for execParse with filename, args, cwd, envs and make
sure we get proper results.

Signed-off-by: Jiri Olsa <[email protected]>
Add test for execParse with filename, args, cwd and empty envs
and make sure we get proper results.

Signed-off-by: Jiri Olsa <[email protected]>
Add support to redact data from environment variables.

Signed-off-by: Jiri Olsa <[email protected]>
Adding redact test for environment variables.

Signed-off-by: Jiri Olsa <[email protected]>
Adding support to filter specific environment variables with
--filter-environment-variables VAR1[,VAR2..] option.

Only specified variables will be part of the event, like with:
  --filter-environment-variables "TEST_VAR1"

only TEST_VAR1 will be stored in the event.

Signed-off-by: Jiri Olsa <[email protected]>
Adding observer test with basic check for environment variables.

Signed-off-by: Jiri Olsa <[email protected]>
Adding observer test with check for environment variables with
applied filter.

Signed-off-by: Jiri Olsa <[email protected]>
Adding observer test with check for environment variables with
applied filter and redaction.

Signed-off-by: Jiri Olsa <[email protected]>
Adding docs for environment variables redaction.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri olsajiri marked this pull request as ready for review November 27, 2025 13:27
@olsajiri olsajiri requested review from FedeDP, kkourt and mtardy November 28, 2025 16:28
Copy link
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

"size", strutils.SizeWithSuffix(entries*int(unsafe.Sizeof(execvemap.ExecveValue{}))))

if option.Config.EnableProcessEnvironmentVariables {
Execve.RewriteConstants["ENV_VARS_ENABLED"] = uint8(1)
Copy link
Member

Choose a reason for hiding this comment

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

nice thanks

Comment on lines +277 to +278
It's also possible to store only requested environment variables with
'--filter-environment-variables VAR1[,VAR2..]` option.
Copy link
Member

Choose a reason for hiding this comment

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

nit: feel free to ignore

Suggested change
It's also possible to store only requested environment variables with
'--filter-environment-variables VAR1[,VAR2..]` option.
It's also possible to store only requested environment variables with the
'--filter-environment-variables VAR1[,VAR2..]` option.

Also this could be documented in the part that describes this feature, but if we don't have any, that's cool

Comment on lines +156 to +157
with_errmetrics(probe_read, &env_start, sizeof(env_start), _(&mm->env_start));
with_errmetrics(probe_read, &env_end, sizeof(env_end), _(&mm->env_end));
Copy link
Member

Choose a reason for hiding this comment

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

cool to use errmetrics here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/major This PR introduces major new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants