From 982e3543fea9f6d79c2e997fcd70b197f1372c4c Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Thu, 8 Feb 2024 14:34:19 +0100 Subject: [PATCH 1/2] fix(userspace/engine): always consider all rules (even the ones below min_prio) in m_rule_stats_manager. Signed-off-by: Federico Di Pierro Co-authored-by: Andrea Terzolo --- userspace/engine/falco_engine.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/userspace/engine/falco_engine.cpp b/userspace/engine/falco_engine.cpp index ad8ed3b7ac8..c2bda72f792 100644 --- a/userspace/engine/falco_engine.cpp +++ b/userspace/engine/falco_engine.cpp @@ -207,7 +207,6 @@ std::unique_ptr falco_engine::load_rules(const std::string &rules_c // clear the rules known by the engine and each ruleset m_rules.clear(); for (auto &src : m_sources) - // add rules to each ruleset { src.ruleset = create_ruleset(src.ruleset_factory); @@ -219,12 +218,6 @@ std::unique_ptr falco_engine::load_rules(const std::string &rules_c // add rules to the engine and the rulesets for (const auto& rule : m_last_compile_output->rules) { - // skip the rule if below the minimum priority - if (rule.priority > m_min_priority) - { - continue; - } - auto info = m_rule_collector->rules().at(rule.name); if (!info) { @@ -233,10 +226,14 @@ std::unique_ptr falco_engine::load_rules(const std::string &rules_c } auto source = find_source(rule.source); - auto rule_id = m_rules.insert(rule, rule.name); - m_rules.at(rule_id)->id = rule_id; + m_rules.insert(rule, rule.name); // By default rules are enabled/disabled for the default ruleset + // skip the rule if below the minimum priority + if (rule.priority > m_min_priority) + { + continue; + } if(info->enabled) { source->ruleset->enable(rule.name, true, m_default_ruleset_id); From 3370a0b40739862e770327e80d796e2d6dc3240c Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Thu, 8 Feb 2024 14:45:33 +0100 Subject: [PATCH 2/2] chore(userspace/engine): introduce proper check to avoid future issues throwing an exception. Signed-off-by: Federico Di Pierro --- userspace/engine/falco_engine.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/userspace/engine/falco_engine.cpp b/userspace/engine/falco_engine.cpp index c2bda72f792..2bd3790970e 100644 --- a/userspace/engine/falco_engine.cpp +++ b/userspace/engine/falco_engine.cpp @@ -226,7 +226,13 @@ std::unique_ptr falco_engine::load_rules(const std::string &rules_c } auto source = find_source(rule.source); - m_rules.insert(rule, rule.name); + auto rule_id = m_rules.insert(rule, rule.name); + if (rule_id != rule.id) + { + throw falco_exception("Incompatible ID for rule: " + rule.name + + " | compiled ID: " + std::to_string(rule.id) + + " | stats_mgr ID: " + std::to_string(rule_id)); + } // By default rules are enabled/disabled for the default ruleset // skip the rule if below the minimum priority