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(engine): add selective rule overrides #2981

Merged
merged 7 commits into from
Dec 22, 2023

Conversation

LucaGuerra
Copy link
Contributor

@LucaGuerra LucaGuerra commented Dec 19, 2023

What type of PR is this?

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

/kind feature

Any specific area of the project related to this PR?

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

/area engine

/area tests

What this PR does / why we need it:

This is a rather straightforward implementation of #1340 (comment) . See the comment for examples.

It is now possible to use the override key in rules, lists and macros. Some fields can be overridden: for lists and macros there is only one field that we care about, while for rules, the following fields have been selected:

  • Available for append: {"condition", "output", "desc", "tags", "exceptions"}
  • Available for replace: {"condition", "output", "desc", "priority", "tags", "exceptions", "enabled", "warn_evttypes", "skip-if-unknown-filter"}

As per the discussion linked above, it is an error to specify both append: true and any override. Given the syntax it is not possible to attempt to both replace and append the same field in the same entry.

Also, if you specify the override key you must specify all the fields that you wish to override and only those fields.

Which issue(s) this PR fixes:

Fixes #1340

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

new(engine): add selective overrides for Falco rules

Also, this needs to be documented ( cc @mikegcoleman )

Copy link

This PR may bring feature or behavior changes in the Falco engine and may require the engine version to be bumped.

Please double check userspace/engine/falco_engine_version.h file. See versioning for FALCO_ENGINE_VERSION.

/hold

@LucaGuerra
Copy link
Contributor Author

/milestone 0.37.0

@poiana poiana added this to the 0.37.0 milestone Dec 19, 2023
@incertum
Copy link
Contributor

Thank you @LucaGuerra could you let me know when it would be ready to test drive it?

@@ -185,7 +191,7 @@ void rule_loader::collector::append(configuration& cfg, list_info& info)
{
auto prev = m_list_infos.at(info.name);
THROW(!prev,
"List has 'append' key but no list by that name already exists",
"List has 'append' key or an append override but no list by that name already exists",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for the reviewer: this string change is making our testing pipelines fail. No big deal, once we pick the right string I can update the pipelines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the code to revert the error messages, I really want to be sure that our tests are happy before merging. Messages can be updated in a subsequent PR coordinated with testing.

@LucaGuerra LucaGuerra force-pushed the new/rule-override branch 2 times, most recently from dcb1205 to 57a5ce5 Compare December 20, 2023 11:34
@LucaGuerra LucaGuerra marked this pull request as ready for review December 20, 2023 11:34
@poiana poiana requested a review from FedeDP December 20, 2023 11:34
@LucaGuerra LucaGuerra changed the title wip: new(engine): add selective overrides new(engine): add selective overrides Dec 20, 2023
@LucaGuerra
Copy link
Contributor Author

@incertum if you are able to test this it would be appreciated :)

@leogr leogr changed the title new(engine): add selective overrides new(engine): add selective rule overrides Dec 20, 2023
Copy link
Contributor

@incertum incertum left a comment

Choose a reason for hiding this comment

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

First pass review focused on the tests. Could we add some more? See comment.

Code implementation LGTM and @jasondellaluce already approved the approach as well 😄.

#include "rule_loader_reader.h"
#include "rule_loader_compiler.h"

class engine_loader_test : public ::testing::Test {
Copy link
Contributor

Choose a reason for hiding this comment

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

Very neat setup @LucaGuerra much more elegant ❤️ than what I had tried in the past 🤦‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed we actually do something similar in at least three different locations in the test suite (including this one). This is out of scope for this PR but we need to consolidate them and have one fixture to allow loading engine + rulesets.

Copy link
Contributor

Choose a reason for hiding this comment

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

Big +1, it would be super useful to do this cleanup!

unit_tests/engine/test_rule_loader.cpp Show resolved Hide resolved
Signed-off-by: Luca Guerra <luca@guerra.sh>
Signed-off-by: Luca Guerra <luca@guerra.sh>
Signed-off-by: Luca Guerra <luca@guerra.sh>
…d in an override

Signed-off-by: Luca Guerra <luca@guerra.sh>
@incertum
Copy link
Contributor

Also, for more complex cases (e.g. enabling/disabling with tags) I think they may be out of scope for this PR and if you can think about unit or integration tests for those cases it would be great to add them.

Agreed, just wanted to mention it once again 🙃


ASSERT_FALSE(load_rules(rules_content, "rules.yaml"));
// std::cout << m_load_result_json.dump(4) << std::endl;
ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find("no rule by that name already exists") != std::string::npos);
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] you are overriding a rule, but no rule by that name already exists or similar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an "error message contains" not equals :)

Copy link
Contributor

Choose a reason for hiding this comment

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

:)

std::string rule_name = "failing_rule";

ASSERT_FALSE(load_rules(rules_content, "rules.yaml"));
ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find("Unexpected key 'priority'") != std::string::npos);
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] same can we make the error message more expressive?

Signed-off-by: Luca Guerra <luca@guerra.sh>
Signed-off-by: Luca Guerra <luca@guerra.sh>
Signed-off-by: Luca Guerra <luca@guerra.sh>
Copy link
Contributor

@incertum incertum left a comment

Choose a reason for hiding this comment

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

/approve

Wonderful work @LucaGuerra, thank you!

@poiana
Copy link
Contributor

poiana commented Dec 22, 2023

LGTM label has been added.

Git tree hash: 417d7652d4a972fbad0cae0b2c25f0aab668b43b

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

/hold

Super job Luca! I'm approving and holding just so that you can decide when you feel confident in merging this, but it looks great to me.

@poiana
Copy link
Contributor

poiana commented Dec 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: incertum, jasondellaluce, LucaGuerra

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 [LucaGuerra,incertum,jasondellaluce]

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

@incertum
Copy link
Contributor

/unhold

Had spoken with Luca on slack. We are good to merge it.

@poiana poiana merged commit 728c8d7 into falcosecurity:master Dec 22, 2023
29 of 30 checks passed
@LucaGuerra LucaGuerra deleted the new/rule-override branch December 22, 2023 23:24
@incertum
Copy link
Contributor

The following 2 issues were duplicates of the primary issue #1340:

Link them for tracking.

@mikegcoleman
Copy link

Added a docs issue to track the documentation need

falcosecurity/falco-website#1226

@pmusa
Copy link

pmusa commented Feb 1, 2024

I think this part also needs to be updated:
https://falco.org/docs/rules/controlling-rules/#via-custom-rule-definition

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.

[FEATURE] Support selective rule overrides / merging
6 participants