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

fix(userspace/engine): make sure exception fields are not optional in replace mode #3108

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions unit_tests/engine/test_rule_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,42 @@ TEST_F(test_falco_engine, rule_override_with_enabled)
EXPECT_EQ(num_rules_for_ruleset(), 1);
}

TEST_F(test_falco_engine, rule_override_exceptions_required_fields)
{
std::string rules_content = R"END(
- rule: test_rule
desc: test rule description
condition: evt.type = close
output: user=%user.name command=%proc.cmdline file=%fd.name
priority: INFO
exceptions:
- name: test_exception
fields: proc.name
comps: in
values: ["cat"]

# when appending, it's fine to provide partial exception definitions
- rule: test_rule
exceptions:
- name: test_exception
values: [echo]
override:
exceptions: append

# when replacing, we don't allow partial exception definitions
- rule: test_rule
exceptions:
- name: test_exception
values: [id]
override:
exceptions: replace
)END";

ASSERT_FALSE(load_rules(rules_content, "rules.yaml"));
ASSERT_FALSE(has_warnings());
ASSERT_TRUE(check_error_message("Item has no mapping for key 'fields'")) << m_load_result_json.dump();
}

TEST_F(test_falco_engine, rule_not_enabled)
{
std::string rules_content = R"END(
Expand Down
4 changes: 2 additions & 2 deletions userspace/engine/rule_loader_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ void rule_loader::reader::read_item(

if (check_update_expected(expected_keys, override_replace, "replace", "exceptions", ctx))
{
read_rule_exceptions(cfg, item, v.exceptions, ctx, true);
read_rule_exceptions(cfg, item, v.exceptions, ctx, false);
}

if (check_update_expected(expected_keys, override_replace, "replace", "output", ctx))
Expand Down Expand Up @@ -771,7 +771,7 @@ void rule_loader::reader::read_item(
decode_optional_val(item, "warn_evttypes", v.warn_evttypes, ctx);
decode_optional_val(item, "skip-if-unknown-filter", v.skip_if_unknown_filter, ctx);
decode_tags(item, v.tags, ctx);
read_rule_exceptions(cfg, item, v.exceptions, ctx, has_append_flag);
read_rule_exceptions(cfg, item, v.exceptions, ctx, false);
collector.define(cfg, v);
}
}
Expand Down
Loading