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

Add ability to return all fields exported by a factory #75

Merged
merged 1 commit into from
Oct 4, 2021

Conversation

mstemm
Copy link
Contributor

@mstemm mstemm commented Aug 25, 2021

Add the ability to return all fields exported by a factory. This is
important for programs like falco that need to validate rule filter
expressions for various event sources, as well as print out sets of
supported fields.

Previously, falco did direct calls to
sinsp::get_filtercheck_fields_info but we're trying to standardize
everything to work through factories, to make it easier to support new
event sources. This PR supports that work.

Signed-off-by: Mark Stemm [email protected]

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area driver-kmod

/area driver-ebpf

/area libscap

/area libsinsp

/area tests

/area proposals

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

new: add ability to return all fields exported by a filter factory. This will be used by Falco to support multiple event sources.

@leogr
Copy link
Member

leogr commented Aug 26, 2021

/ok-to-test

mstemm added a commit to falcosecurity/falco that referenced this pull request Aug 26, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
Copy link
Contributor

@gnosek gnosek left a comment

Choose a reason for hiding this comment

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

Hmm okay 🤷‍♂️

There's no user of this code added so I have ~zero context on what this is supposed to do

@@ -205,4 +232,7 @@ class gen_event_filter_factory

// Create a new filtercheck
virtual gen_event_filter_check *new_filtercheck(const char *fldname) = 0;

// Return the set of fields supported by this factory
virtual std::list<filter_fieldclass_info> get_fields() = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why lists and not vectors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for random access, just iteration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still, I don't think a list should be the default choice for a container, due to the horrible memory accesses. Probably doesn't matter much here, but maybe at least we'd get cheap .size() with a vector

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://stackoverflow.com/questions/228908/is-listsize-really-on .size() is supposed to be O(1) and actually is in gcc >= 5.0. Also, the only use of this method just iterates (once) anyway.

Comment on lines +216 to +217
std::list<gen_event_filter_factory::filter_fieldclass_info> get_fields() override;

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is the only subclass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the libraries, yes. In falco there's another subclass for "json_events", which are used by the k8s audit rules: https://github.com/leogr/falco/blob/new/plugin-system-api-additions/userspace/engine/json_evt.h#L376.

And after these changes are all merged, we'll be creating a subclass for plugins, so a given plugin can export the set of valid fields used by that plugin.

userspace/libsinsp/filter.cpp Outdated Show resolved Hide resolved

for(int32_t k = 0; k < fci->m_nfields; k++)
{
const filtercheck_field_info* fld = &fci->m_fields[k];
Copy link
Contributor

Choose a reason for hiding this comment

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

fci->m_fields isn't a vector we could iterate over without an explicit index, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

:sadpanda: might be nice to convert it to a vector later.

Comment on lines +2446 to +2476
if(fld->m_flags & EPF_TABLE_ONLY ||
fld->m_flags & EPF_PRINT_ONLY)
{
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these flags mean and why do we want this check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are defined here: https://github.com/falcosecurity/libs/blob/factory-add-get-fields/userspace/libsinsp/event.h#L44. Generally if a field can't be used to filter events, we don't want to print it.

(And btw, this is just moving code from falco that did this in a specific way for syscall filterchecks. This PR makes it generic for a "factory" e.g. source of filters/filterchecks/fields).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation.

if a field can't be used to filter events, we don't want to print it

this should live as a comment above this if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, added.

@mstemm
Copy link
Contributor Author

mstemm commented Sep 10, 2021

By the way, all of these PRs are used in this Falco PR (falcosecurity/falco#1715), if you want to see how they are used.

leogr
leogr previously approved these changes Sep 16, 2021
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

/approve

LGTM, just a note since the next Falco release is very close.

The new get_fields() conflicts with the one already present here in Falco (so basically Falco won't compile until the signature gets adjusted in Falco).
I know that's addressed by falcosecurity/falco#1715. However, we likely have to upgrade the version of the libs in Falco soon and I'm not confident falcosecurity/falco#1715 will get merged in time.

Thus, I wouldn't risk blocking the Falco release. So,
/hold
for the moment.

@poiana
Copy link
Contributor

poiana commented Sep 16, 2021

LGTM label has been added.

Git tree hash: 883da564554e61b2aecfa056eadf99a7466a151d

@mstemm
Copy link
Contributor Author

mstemm commented Sep 16, 2021

That's fine--I wouldn't merge any of #74, #75, #76, or #77 individually. Just merge them all at once (after the release, most likely) and then I can fix things up with the corresponding falco release.

@leogr
Copy link
Member

leogr commented Sep 17, 2021

That's fine--I wouldn't merge any of #74, #75, #76, or #77 individually. Just merge them all at once (after the release, most likely) and then I can fix things up with the corresponding falco release.

Perfect! I will review the other PRs soon.
Thank you.

gnosek
gnosek previously approved these changes Oct 1, 2021
@mstemm
Copy link
Contributor Author

mstemm commented Oct 1, 2021

Falco 0.30.0 is released so I'm removing the hold.
/hold cancel

Add the ability to return all fields exported by a factory. This is
important for programs like falco that need to validate rule filter
expressions for various event sources, as well as print out sets of
supported fields.

Previously, falco did direct calls to
sinsp::get_filtercheck_fields_info but we're trying to standardize
everything to work through factories, to make it easier to support new
event sources. This PR supports that work.

Signed-off-by: Mark Stemm <[email protected]>
@mstemm mstemm dismissed stale reviews from gnosek and leogr via 1fdf3af October 1, 2021 16:43
@mstemm mstemm force-pushed the factory-add-get-fields branch from 59ff689 to 1fdf3af Compare October 1, 2021 16:43
@poiana poiana removed the lgtm label Oct 1, 2021
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

/approve

@poiana poiana added the lgtm label Oct 4, 2021
@poiana
Copy link
Contributor

poiana commented Oct 4, 2021

LGTM label has been added.

Git tree hash: f3f1fe505e425a28717cfb3c660ab20bf0034e88

@poiana
Copy link
Contributor

poiana commented Oct 4, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: leogr, mstemm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 59a8145 into master Oct 4, 2021
@poiana poiana deleted the factory-add-get-fields branch October 4, 2021 08:28
mstemm added a commit to leogr/falco that referenced this pull request Oct 4, 2021
mstemm added a commit to falcosecurity/falco that referenced this pull request Oct 4, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
mstemm added a commit to falcosecurity/falco that referenced this pull request Oct 4, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
mstemm added a commit to falcosecurity/falco that referenced this pull request Oct 5, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
mstemm added a commit to falcosecurity/falco that referenced this pull request Oct 5, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
mstemm added a commit to falcosecurity/falco that referenced this pull request Oct 5, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
mstemm added a commit to falcosecurity/falco that referenced this pull request Oct 7, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
poiana pushed a commit to falcosecurity/falco that referenced this pull request Oct 12, 2021
Take advantage of the changes in
falcosecurity/libs#75 to have a
general-purpose way to list fields for a given event source.

in the engine, list_fields() now takes a source, iterates over filter
factories, and calls get_fields() for each factory, printing the results.

list_source_fields now calls the engine regardless of source.

Signed-off-by: Mark Stemm <[email protected]>
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.

4 participants