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

new: add possibility to retrieve details about rules with filter_details_visitor #2544

Merged
merged 10 commits into from
May 19, 2023

Conversation

loresuso
Copy link
Member

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

/kind release

Any specific area of the project related to this PR?

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

/area build

/area engine

/area tests

/area proposals

/area CI

What this PR does / why we need it:
This PR introduces a specialized visitor that can be used to construct a normalized form of a rule, containing all the macros, lists, operators, and fields it uses in JSON format. The functionality is embedded in the -l/-L flags and can be triggered when the output is set to JSON.
This functionality can be used later in CI tools for rules to e.g understand how to automatically handle and increase rules version.

Example:

$ sudo ./userspace/falco/falco -c ../falco.yaml -l "Launch Privileged Container" -o "json_output=true" | jq 
Fri May 12 10:23:13 2023: Falco version: 0.34.1-194+f5c7574 (x86_64)
Fri May 12 10:23:13 2023: Falco initialized with configuration file: ../falco.yaml
Fri May 12 10:23:13 2023: Loading rules from file /etc/falco/falco_rules.yaml
Fri May 12 10:23:13 2023: Loading rules from file /etc/falco/falco_rules.local.yaml
{
  "conditionFields": [
    "evt.num",
    "container.id",
    "container.privileged",
    "container.image.repository",
    "proc.vpid",
    "evt.dir",
    "evt.type"
  ],
  "description": "Detect the initial process started in a privileged container. Exceptions are made for known trusted images.",
  "exceptionFields": [],
  "lists": [
    "redhat_io_images_privileged",
    "falco_privileged_images",
    "trusted_images"
  ],
  "macros": [
    "redhat_image",
    "aws_eks_core_images",
    "user_trusted_containers",
    "allowed_openshift_registry_root",
    "openshift_image",
    "never_true",
    "falco_privileged_containers",
    "user_privileged_containers",
    "container",
    "spawned_process",
    "allowed_aws_ecr_registry_root_for_eks",
    "container_started"
  ],
  "name": "Launch Privileged Container",
  "operators": [
    "endswith",
    "startswith",
    "in",
    "!=",
    "="
  ],
  "outputFields": [
    "user.name",
    "user.loginuid",
    "proc.cmdline",
    "proc.pid",
    "container.name",
    "container.id",
    "container.image.repository",
    "container.image.tag"
  ],
  "priority": "Informational"
}

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

update: get rules details with `-l` or `-L` flags when json output format is specified

@loresuso
Copy link
Member Author

cc @jasondellaluce

@loresuso loresuso force-pushed the filter-details-visitor branch from 0004597 to 2527699 Compare May 12, 2023 10:32
@FedeDP
Copy link
Contributor

FedeDP commented May 12, 2023

This is super cool and highly requested! Thank you @loresuso !

@loresuso loresuso force-pushed the filter-details-visitor branch from 3b1ff62 to e713ae0 Compare May 12, 2023 10:59
@jasondellaluce
Copy link
Contributor

Links to #2372 and potentially fixes it, if we just add the information about the evt.types matched by each rule.

@loresuso
Copy link
Member Author

loresuso commented May 15, 2023

Last two commits address the following:

  • retrieving information about enabled rules
  • information about lists and macros when the global -L option is specified

This will allow to check for instance (check https://github.com/falcosecurity/rules/blob/main/RELEASE.md for further details):

  • if a rule used to be disabled and then enabled, patch number of version of the rule must be increased
  • adding, removing elements from lists, same as above

Currently working on adding evt.type information

@loresuso loresuso force-pushed the filter-details-visitor branch from c803516 to b9c8ac1 Compare May 16, 2023 09:35
@loresuso loresuso force-pushed the filter-details-visitor branch 3 times, most recently from 9b2d14d to eabd030 Compare May 16, 2023 12:44
Copy link
Member

@Andreagit97 Andreagit97 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 minor comments, LGTM!

userspace/engine/falco_engine.cpp Show resolved Hide resolved
userspace/engine/falco_engine.cpp Outdated Show resolved Hide resolved
@@ -126,13 +126,13 @@ falco::app::run_result falco::app::actions::load_rules_files(falco::app::state&

if (s.options.describe_all_rules)
Copy link
Member

Choose a reason for hiding this comment

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

I would initialize both describe_all_rules and describe_rule variables here

options::options()
	: event_buffer_format(sinsp_evt::PF_NORMAL),
	  gvisor_config(""),	
	  list_fields(false),
	  list_plugins(false),
	  list_syscall_events(false),
	  markdown(false),
	  modern_bpf(false)
{
}

Copy link
Member Author

Choose a reason for hiding this comment

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

They should already have their default I guess in options.cpp

@loresuso loresuso force-pushed the filter-details-visitor branch from ed9b102 to b886a00 Compare May 18, 2023 09:12
@poiana poiana added size/XXL and removed size/XL labels May 18, 2023
@loresuso loresuso force-pushed the filter-details-visitor branch from b886a00 to e58a4a8 Compare May 18, 2023 09:39
@leogr
Copy link
Member

leogr commented May 18, 2023

/milestone 0.35.0

@poiana poiana added this to the 0.35.0 milestone May 18, 2023
userspace/engine/filter_details_resolver.cpp Outdated Show resolved Hide resolved
userspace/engine/filter_details_resolver.cpp Show resolved Hide resolved
userspace/engine/falco_engine.cpp Outdated Show resolved Hide resolved
userspace/engine/falco_engine.cpp Outdated Show resolved Hide resolved
userspace/engine/falco_engine.cpp Outdated Show resolved Hide resolved
userspace/engine/falco_engine.cpp Outdated Show resolved Hide resolved
userspace/engine/falco_engine.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

Looks good Lore:

userspace/engine/filter_details_resolver.cpp Show resolved Hide resolved
userspace/engine/filter_details_resolver.cpp Show resolved Hide resolved
userspace/engine/filter_details_resolver.cpp Outdated Show resolved Hide resolved
userspace/engine/filter_details_resolver.cpp Show resolved Hide resolved
userspace/engine/filter_details_resolver.cpp Outdated Show resolved Hide resolved
userspace/engine/filter_details_resolver.cpp Show resolved Hide resolved
userspace/engine/filter_details_resolver.cpp Show resolved Hide resolved
userspace/engine/falco_engine.cpp Outdated Show resolved Hide resolved
loresuso added 3 commits May 19, 2023 10:35
Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
…etails when requested

Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
@loresuso loresuso force-pushed the filter-details-visitor branch from 5178406 to d97d862 Compare May 19, 2023 10:38
@loresuso
Copy link
Member Author

loresuso commented May 19, 2023

Just rebased and everything's green, I think we are there now!

loresuso added 7 commits May 19, 2023 12:16
… getting details of all rules

Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
…ption

Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
… details

Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
- avoiding inspector to be allocated for each rule
- use two boolean values for expecting macros and lists
- move items of lists alongside name, under info
- use snake case for json output, like we do for e.g alerts
- correctly retrieve evt names
- consider two levels of lists for exception operators

Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
@loresuso loresuso force-pushed the filter-details-visitor branch from d97d862 to f662353 Compare May 19, 2023 12:16
Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

/approve

Thanks! This is great!

@poiana
Copy link
Contributor

poiana commented May 19, 2023

LGTM label has been added.

Git tree hash: 76ba42e28e821ab6c89ef3774628d821c834d360

Copy link
Member

@Andreagit97 Andreagit97 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
Copy link
Contributor

poiana commented May 19, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, jasondellaluce, loresuso

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:
  • OWNERS [Andreagit97,jasondellaluce]

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 e47ece4 into falcosecurity:master May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants