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

Events and Scope flags #3262

Merged
merged 7 commits into from Jul 12, 2023
Merged

Conversation

geyslan
Copy link
Member

@geyslan geyslan commented Jun 23, 2023

1. Explain what the PR does

Close #2810
Close #3261
Close #1543

3429c8e feat(cmd/flags)!: split filter flag (2023/jun/29) Geyslan Gregório <geyslan@gmail.com>

This commit splits the '--filter' flag into two new flags: '--scope' and
'--events'.

The '--scope' flag is used to specify the scope of the events to be
captured like 'comm', 'binary', 'pid', 'uid', 'mntns', 'pidns', 'uts',
'tree', 'follow' and 'container', while the '--events' flag is used to
specify the events and their userland filters like 'args', 'retval' and
'context'.

It also removes the set option previously available for the '--filter'
flag, as it is no longer needed. The '--events' flag is now used to
specify the sets of events to be captured, e.g. '--events fs'.

Other chores:

- analyze '--event' flag now is '--events', to be consistent.
- polcy_file.go validateContext() is removed since we have similar
  validation in further stages.
- Relocates unit tests from flags_test.go to respective new correlated
  files, making it easier to maintain and extend and changes integration
  tests to use PolicyFile instead of Policy.

BREAKING CHANGE: '--filter' flag is now replaced by '--scope' and
'--events' flags and analyze '--event' flag is now '--events'.

Co-authored-by: Yaniv Agman <yanivagman@gmail.com>

2. Explain how to test it

See documentation changes.

3. Other comments

This is the continuation of #3100.

--filter openat.context.processName=ls | only trace 'openat' events that have 'processName' equal to 'ls'
--filter security_file_open.context.container | only trace 'security_file_open' events coming from a container
--filter comm=bash --filter follow | trace all events that originated from bash or from one of the processes spawned by bash
Scope examples:
Copy link
Member Author

Choose a reason for hiding this comment

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

@yanivagman I kept both --help event and --help scope showing the same help message since they have a lot in common (operators info above). But let me know if we must split it as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Event flag only has a subset of the operators, and can have its own help message.
Yet I think it's ok to keep it like that for now.
We can address this in a future PR

docs/docs/config/overview.md Outdated Show resolved Hide resolved
docs/docs/events/builtin/extra/hooked_syscalls.md Outdated Show resolved Hide resolved
docs/docs/filters/filtering.md Outdated Show resolved Hide resolved
docs/docs/filters/filtering.md Outdated Show resolved Hide resolved
docs/docs/filters/filtering.md Outdated Show resolved Hide resolved
pkg/cmd/flags/flags.go Outdated Show resolved Hide resolved
pkg/ebpf/c/common/filtering.h Outdated Show resolved Hide resolved
pkg/ebpf/events_pipeline.go Outdated Show resolved Hide resolved
pkg/policy/policy_file.go Outdated Show resolved Hide resolved
tests/e2e-inst-test.sh Outdated Show resolved Hide resolved
@geyslan geyslan changed the title Event flag Event and Scope flags Jul 6, 2023
This commit splits the '--filter' flag into two new flags: '--scope' and
'--events'.

The '--scope' flag is used to specify the scope of the events to be
captured like 'comm', 'binary', 'pid', 'uid', 'mntns', 'pidns', 'uts',
'tree', 'follow' and 'container', while the '--events' flag is used to
specify the events and their userland filters like 'args', 'retval' and
'context'.

It also removes the set option previously available for the '--filter'
flag, as it is no longer needed. The '--events' flag is now used to
specify the sets of events to be captured, e.g. '--events fs'.

Other chores:

- analyze '--event' flag now is '--events', to be consistent.
- polcy_file.go validateContext() is removed since we have similar
  validation in further stages.
- Relocates unit tests from flags_test.go to respective new correlated
  files, making it easier to maintain and extend and changes integration
  tests to use PolicyFile instead of Policy.

BREAKING CHANGE: '--filter' flag is now replaced by '--scope' and
'--events' flags and analyze '--event' flag is now '--events'.

Co-authored-by: Yaniv Agman <yanivagman@gmail.com>
Comment on lines +59 to +67
// TODO: decide if we want to bind this flag to viper, since we already have a similar
// flag in rootCmd, conflicting with each other.
// The same goes for the other flags (signatures-dir, rego), also in rootCmd.
//
// err := viper.BindPFlag("events", analyze.Flags().Lookup("events"))
// if err != nil {
// fmt.Fprintf(os.Stderr, "Error: %s\n", err)
// os.Exit(1)
// }
Copy link
Member Author

Choose a reason for hiding this comment

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

I've detected viper flags conflicts between rootCmd and analyze. The same viper instance is being used, which means that the settings have to be defined in the global config file. But rootCmd events (former filter) is a flag designedly not bound to the global config file as we can see below.

But there are other conflicts like signatures-dir and rego, both already bound in the rootCmd.

I suppose that analyze events flag is not a global config flag, right? So, probably we can remove these mentioned bindings in analyze. WDYT @josedonizetti?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@geyslan I believe this is related: spf13/viper#233

Copy link
Member Author

Choose a reason for hiding this comment

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

@geyslan I believe this is related: spf13/viper#233

Thanks for the reference. A possible solution, if we decide to bind these flags to global config file, is to do it in PreRun(), so it won't override as in init(): spf13/viper#233 (comment)

For now, leaving them commented.

@geyslan
Copy link
Member Author

geyslan commented Jul 10, 2023

@yanivagman ready for review.

@geyslan geyslan changed the title Event and Scope flags Events and Scope flags Jul 10, 2023
Copy link
Collaborator

@yanivagman yanivagman left a comment

Choose a reason for hiding this comment

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

Some nit comments, but otherwise LGTM

docs/docs/config/overview.md Outdated Show resolved Hide resolved
docs/docs/events/custom/analyze.md Outdated Show resolved Hide resolved
docs/docs/filters/filtering.md Outdated Show resolved Hide resolved
pkg/cmd/flags/filter.go Outdated Show resolved Hide resolved
pkg/cmd/flags/filter.go Outdated Show resolved Hide resolved
geyslan and others added 4 commits July 12, 2023 07:31
Co-authored-by: Yaniv Agman <yanivagman@gmail.com>
Co-authored-by: Yaniv Agman <yanivagman@gmail.com>
Co-authored-by: Yaniv Agman <yanivagman@gmail.com>
Co-authored-by: Yaniv Agman <yanivagman@gmail.com>
pkg/cmd/flags/filter.go Outdated Show resolved Hide resolved
@geyslan
Copy link
Member Author

geyslan commented Jul 12, 2023

@yanivagman @rafaeldtinoco @josedonizetti, just a note to, when merging this, squash the commits leaving the message of the main one as it is (the other commits were just review suggestions accepted directly in github).

docs/docs/config/overview.md Outdated Show resolved Hide resolved
@geyslan
Copy link
Member Author

geyslan commented Jul 12, 2023

@yanivagman @rafaeldtinoco @josedonizetti, just a note to, when merging this, squash the commits leaving the message of the main one as it is (the other commits were just review suggestions accepted directly in github).

Synced offline and merging it.

@geyslan geyslan merged commit 2555190 into aquasecurity:main Jul 12, 2023
25 checks passed
@geyslan geyslan deleted the 1543-2810-event-flag branch July 31, 2023 22:18
geyslan added a commit to geyslan/tracee that referenced this pull request Oct 10, 2023
After the changes of aquasecurity#3262, at this stage, policies.Map() length is
always greater than 0.
geyslan added a commit to geyslan/tracee that referenced this pull request Oct 10, 2023
After the changes of aquasecurity#3262, at this stage, policies.Map() length is
always greater than 0.
geyslan added a commit to geyslan/tracee that referenced this pull request Oct 16, 2023
After the changes of aquasecurity#3262, at this stage, policies.Map() length is
always greater than 0.
geyslan added a commit to geyslan/tracee that referenced this pull request Oct 16, 2023
After the changes of aquasecurity#3262, at this stage, policies.Map() length is
always greater than 0.
geyslan added a commit to geyslan/tracee that referenced this pull request Oct 26, 2023
After the changes of aquasecurity#3262, at this stage, policies.Map() length is
always greater than 0.
geyslan added a commit that referenced this pull request Oct 30, 2023
After the changes of #3262, at this stage, policies.Map() length is
always greater than 0.
AnaisUrlichs pushed a commit to AnaisUrlichs/tracee that referenced this pull request Nov 2, 2023
After the changes of aquasecurity#3262, at this stage, policies.Map() length is
always greater than 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants