Skip to content
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
33 changes: 33 additions & 0 deletions unit_tests/engine/test_rule_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,3 +1327,36 @@ TEST_F(test_falco_engine, empty_string_source_addl_rule) {

EXPECT_TRUE(load_rules(rules_content, "rules.yaml"));
}

TEST_F(test_falco_engine, deprecated_field_in_output) {
std::string rules_content = R"END(
- rule: test_rule_with_evt_dir_in_output
desc: test rule with evt.dir in output
condition: evt.type = close
output: user=%user.name command=%proc.cmdline file=%fd.name evt.dir=%evt.dir
priority: INFO
)END";

ASSERT_TRUE(load_rules(rules_content, "rules.yaml"));
ASSERT_VALIDATION_STATUS(yaml_helper::validation_ok) << m_load_result->schema_validation();
ASSERT_TRUE(has_warnings());
ASSERT_TRUE(check_warning_message(
"usage of deprecated field 'evt.dir' has been detected in the rule output"))
<< m_load_result_string;
EXPECT_EQ(num_rules_for_ruleset(), 1);
}

TEST_F(test_falco_engine, no_deprecated_field_warning_in_output) {
std::string rules_content = R"END(
- rule: test_rule_without_evt_dir
desc: test rule without evt.dir in output
condition: evt.type = close
output: user=%user.name command=%proc.cmdline file=%fd.name
priority: INFO
)END";

ASSERT_TRUE(load_rules(rules_content, "rules.yaml"));
ASSERT_VALIDATION_STATUS(yaml_helper::validation_ok) << m_load_result->schema_validation();
ASSERT_FALSE(check_warning_message("evt.dir")) << m_load_result_string;
EXPECT_EQ(num_rules_for_ruleset(), 1);
}
23 changes: 23 additions & 0 deletions userspace/engine/rule_loader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ static bool is_format_valid(const falco_source& source, std::string fmt, std::st
}
}

static void check_deprecated_fields_in_output(const std::string& fmt,
const rule_loader::context& ctx,
rule_loader::result& res) {
// Check for evt.dir field usage in output format
for(int i = 0;
i < static_cast<int>(falco::load_result::deprecated_field::DEPRECATED_FIELD_NOT_FOUND);
i++) {
auto df = falco::load_result::deprecated_field(i);
if(fmt.find(falco::load_result::deprecated_field_str(df)) != std::string::npos) {
res.add_deprecated_field_warning(df,
"usage of deprecated field '" +
falco::load_result::deprecated_field_str(df) +
"' has been detected in the rule output",
ctx);
}
}
}

static void build_rule_exception_infos(
const std::vector<rule_loader::rule_exception_info>& exceptions,
std::set<std::string>& exception_fields,
Expand Down Expand Up @@ -478,13 +496,18 @@ void rule_loader::compiler::compile_rule_infos(const configuration& cfg,
r.output_ctx);
}

// check for deprecated fields in output format
check_deprecated_fields_in_output(rule.output, r.output_ctx, *cfg.res);

// validate the rule's extra fields if any
for(auto const& ef : rule.extra_output_fields) {
if(!is_format_valid(*cfg.sources.at(r.source), ef.second.first, err)) {
throw rule_load_exception(falco::load_result::error_code::LOAD_ERR_COMPILE_OUTPUT,
err,
r.output_ctx);
}
// check for deprecated fields in extra output fields
check_deprecated_fields_in_output(ef.second.first, r.output_ctx, *cfg.res);
}

if(!compile_condition(cfg,
Expand Down
Loading