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

Refactor/full analyze mode #3673

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

AlonZivony
Copy link
Collaborator

1. Explain what the PR does

Fix #3520

2. Explain how to test it

3. Other comments

@AlonZivony
Copy link
Collaborator Author

@rafaeldtinoco @josedonizetti the current analyze mode is working (checked manually) with process tree.
I need you LGTM to do the work left of tests, format and documentation.

@AlonZivony AlonZivony marked this pull request as ready for review November 13, 2023 14:06
@AlonZivony
Copy link
Collaborator Author

Optional feature - if stdin of tracee upon startup does not point to /dev/pts (normal stdin path), then run automatically tracee analyze.
For example:
cat tracee_output.json | ./tracee -e ld_preload will run in analyze mode on the events from tracee_output.json.
This will make the behavior similar to python for example.

A point of thought:
Do we really want analyze command?
We can just assume by the use of the --input flag that we are in analyze mode, avoiding the clumsy command line.

@NDStrahilevitz
Copy link
Collaborator

@AlonZivony When you go back to working on this, is it reasonable in your opinion to include the DNS Cache?

@AlonZivony
Copy link
Collaborator Author

@AlonZivony When you go back to working on this, is it reasonable in your opinion to include the DNS Cache?

This PR is not giving the analyze mode all the options of the normal mode.
You can see that I didn't support many flags of Tracee.
I am not sure about this DNS cache implementation you want, but I guess it could be possible. But not in this PR (it is big enough as it is)

@rafaeldtinoco rafaeldtinoco requested review from yanivagman and removed request for rafaeldtinoco January 5, 2024 16:21
@@ -38,12 +39,13 @@ func InitNamespacesEvent() trace.Event {
initNamespacesArgs := getInitNamespaceArguments()

initNamespacesEvent := trace.Event{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest you turn this to a data source.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So for now this is used as state initializer.
This info could be also saved to a datasource.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm saying we make this a builtin data source, instead of having an event which initializes some shared state (which is what data sources are for). I think this will only be in v0.21 or v0.22, so this can be done as a prep PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But you will still need an event to initialize the datasource in analyze mode...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I had in mind using signals for things like that. In addition to what i've written below, I think --export-analyze should give a separate output of signals, which can be fed back to the control plane running in analyze.

You're right, this needs to be an event or a signal. But, it doesn't need to be an externally visible event. So initialize a data source with this info after the userspace code which would previously emit the event. If running with --export-analyze, dump it as a signal as well.

)

// EventsProducer is a type that is able to generate events
type EventsProducer interface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the eBPF event decoder could be considered such an object no? This could be a useful abstraction.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, this was the idea :)
I tried to fit to the current design

"github.com/aquasecurity/tracee/pkg/capabilities"
"github.com/aquasecurity/tracee/pkg/config"
"github.com/aquasecurity/tracee/pkg/errfmt"
cap2 "kernel.org/pub/linux/libs/security/libcap/cap"
Copy link
Collaborator

Choose a reason for hiding this comment

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

why alias?

@@ -122,6 +123,8 @@ type Tracee struct {
streamsManager *streams.StreamsManager
// policyManager manages policy state
policyManager *policyManager
// producer produce events in analyze mode instead of eBPF programs
producer producer.EventsProducer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps not relevant for this PR, but I see a future where this is a one-tracee-many-producers relation. @josedonizetti WDYT?

Copy link
Collaborator

@NDStrahilevitz NDStrahilevitz left a comment

Choose a reason for hiding this comment

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

The commits need to be organized. It also seems like this is still a WIP. Are you planning on merging this release or the next one?
Anyway, there should also be a test for the mode before merging.

@@ -118,6 +120,8 @@ func (t *Tracee) registerEventProcessors() {
// Convert all time relate args to nanoseconds since epoch.
// NOTE: Make sure to convert time related args (of your event) in here.
t.RegisterEventProcessor(events.SchedProcessFork, t.processSchedProcessFork)
}
if !t.config.Output.ExportAnalyze {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why disable? This adds another layer of confusion to normalization. I'd also urge again that normalization is done as the first procession as its easier to reason about for a user writing an extension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So we need the timestamps to match the kernel times in the analyze mode for the process tree to work there.
We can do it by either change the timestamps in the back when reading in analyze mode, or when exporting.
For now it was more convenient for this POC to export kernel times.

@@ -820,6 +834,10 @@ func (t *Tracee) getOptionsConfig() uint32 {
cOptVal = cOptVal | optForkProcTree // tell sched_process_fork to be prolix
}

if t.config.Output.ExportAnalyze {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds like exportanalyze should just enable the process tree, instead of having its own logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right :)

@AlonZivony
Copy link
Collaborator Author

The commits need to be organized. It also seems like this is still a WIP. Are you planning on merging this release or the next one? Anyway, there should also be a test for the mode before merging.

You are right, this is more of a POC PR.
I didn't want to implement the specifics before the overall idea is approved.
You can think of this as a DR stage, where I want to have approval on all the patterns, abstractions and general solution.
As you noticed, I didn't implement tests, kept many features blocked for this to work in this current stage and didn't document to much (as it is prone to change).
If I get the OK for this, we can discuss how to move on with the full implementation.

@NDStrahilevitz
Copy link
Collaborator

The commits need to be organized. It also seems like this is still a WIP. Are you planning on merging this release or the next one? Anyway, there should also be a test for the mode before merging.

You are right, this is more of a POC PR. I didn't want to implement the specifics before the overall idea is approved. You can think of this as a DR stage, where I want to have approval on all the patterns, abstractions and general solution. As you noticed, I didn't implement tests, kept many features blocked for this to work in this current stage and didn't document to much (as it is prone to change). If I get the OK for this, we can discuss how to move on with the full implementation.

The ability added in this PR is necessary for us to deprecate tracee-ebpf and tracee-rules. So this, or something similar is necessary as well. And it does seem like a useful feature to have anyway.

I think the concept of the event producer is good, and I already have some ideas on where to use it in the future.

I think it would be even better if we would make the pipeline its own object, which we can build as needed depending on the context (basically making it more declarative). I think it would make implementing this idea much nicer. I'm less sure of how easy it would be as a PR (probably not as it would be a big refactor), but I also fear it is becoming more necessary as we approach extensions/plugins and basically allowed external change of behavior in tracee.

@geyslan
Copy link
Member

geyslan commented Feb 21, 2024

We have this update #3875

Please rebase your PR against main to make use of the new workflow setup.

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

Successfully merging this pull request may close these issues.

Analyze mode should support same (or similar) features as regular pipeline.
4 participants