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: force-set evt.type for plugin source events #1878

Merged
merged 5 commits into from
Jan 28, 2022
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
4 changes: 2 additions & 2 deletions cmake/modules/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} PLUGINS_SYSTEM_NAME)

ExternalProject_Add(
cloudtrail-plugin
URL "https://download.falco.org/plugins/stable/cloudtrail-0.2.2-${PLUGINS_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}.tar.gz"
URL_HASH "SHA256=1628717e48b2ba1b9c78c9081e2ec23e4d88bb1a7b68b12cf8dff7f247b5b9b1"
URL "https://download.falco.org/plugins/stable/cloudtrail-0.2.3-${PLUGINS_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}.tar.gz"
URL_HASH "SHA256=3dfce36f37a4f834b6078c6b78776414472a6ee775e8f262535313cc4031d0b7"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND "")
Expand Down
4 changes: 2 additions & 2 deletions rules/aws_cloudtrail_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
# anything semver-compatible.
- required_plugin_versions:
- name: cloudtrail
version: 0.2.2
version: 0.2.3
- name: json
version: 0.2.1
version: 0.2.2

# Note that this rule is disabled by default. It's useful only to
# verify that the cloudtrail plugin is sending events properly. The
Expand Down
44 changes: 29 additions & 15 deletions tests/engine/test_rulesets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ TEST_CASE("Should enable/disable for exact match w/ default ruleset", "[rulesets
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("one_rule", exact_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -57,8 +58,9 @@ TEST_CASE("Should enable/disable for exact match w/ specific ruleset", "[ruleset
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("one_rule", exact_match, enabled, non_default_ruleset);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 1);
Expand All @@ -76,8 +78,9 @@ TEST_CASE("Should not enable for exact match different rule name", "[rulesets]")
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("some_other_rule", exact_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 0);
Expand All @@ -88,8 +91,9 @@ TEST_CASE("Should enable/disable for exact match w/ substring and default rulese
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("one_rule", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -103,8 +107,9 @@ TEST_CASE("Should not enable for substring w/ exact_match", "[rulesets]")
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("one_", exact_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 0);
Expand All @@ -115,8 +120,9 @@ TEST_CASE("Should enable/disable for prefix match w/ default ruleset", "[ruleset
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("one_", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -130,8 +136,9 @@ TEST_CASE("Should enable/disable for suffix match w/ default ruleset", "[ruleset
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("_rule", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -145,8 +152,9 @@ TEST_CASE("Should enable/disable for substring match w/ default ruleset", "[rule
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("ne_ru", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -160,8 +168,9 @@ TEST_CASE("Should enable/disable for substring match w/ specific ruleset", "[rul
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable("ne_ru", substring_match, enabled, non_default_ruleset);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 1);
Expand All @@ -179,9 +188,10 @@ TEST_CASE("Should enable/disable for tags w/ default ruleset", "[rulesets]")
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";
std::set<std::string> want_tags = {"some_tag"};

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable_tags(want_tags, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -195,9 +205,10 @@ TEST_CASE("Should enable/disable for tags w/ specific ruleset", "[rulesets]")
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";
std::set<std::string> want_tags = {"some_tag"};

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable_tags(want_tags, enabled, non_default_ruleset);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 1);
Expand All @@ -215,9 +226,10 @@ TEST_CASE("Should not enable for different tags", "[rulesets]")
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";
std::set<std::string> want_tags = {"some_different_tag"};

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable_tags(want_tags, enabled);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 0);
Expand All @@ -228,9 +240,10 @@ TEST_CASE("Should enable/disable for overlapping tags", "[rulesets]")
falco_ruleset r;
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
string source = "syscall";
std::set<std::string> want_tags = {"some_tag", "some_different_tag"};

r.add(rule_name, tags, filter);
r.add(source, rule_name, tags, filter);

r.enable_tags(want_tags, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -241,16 +254,17 @@ TEST_CASE("Should enable/disable for overlapping tags", "[rulesets]")

TEST_CASE("Should enable/disable for incremental adding tags", "[rulesets]")
{
string source = "syscall";
falco_ruleset r;
std::shared_ptr<gen_event_filter> rule1_filter = create_filter();
string rule1_name = "one_rule";
std::set<std::string> rule1_tags = {"rule1_tag"};
r.add(rule1_name, rule1_tags, rule1_filter);
r.add(source, rule1_name, rule1_tags, rule1_filter);

std::shared_ptr<gen_event_filter> rule2_filter = create_filter();
string rule2_name = "two_rule";
std::set<std::string> rule2_tags = {"rule2_tag"};
r.add(rule2_name, rule2_tags, rule2_filter);
r.add(source, rule2_name, rule2_tags, rule2_filter);

std::set<std::string> want_tags;

Expand Down
9 changes: 4 additions & 5 deletions userspace/engine/falco_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void falco_engine::add_filter(std::shared_ptr<gen_event_filter> filter,
throw falco_exception(err);
}

it->second->add(rule, tags, filter);
it->second->add(source, rule, tags, filter);
}

bool falco_engine::is_source_valid(const std::string &source)
Expand All @@ -432,7 +432,7 @@ bool falco_engine::is_plugin_compatible(const std::string &name,
const std::string &version,
std::string &required_version)
{
sinsp_plugin::version plugin_version(version.c_str());
sinsp_plugin::version plugin_version(version);

if(!plugin_version.m_valid)
{
Expand All @@ -447,13 +447,12 @@ bool falco_engine::is_plugin_compatible(const std::string &name,

for(auto &rversion : m_required_plugin_versions[name])
{
sinsp_plugin::version req_version(rversion.c_str());
if(req_version.m_version_major > plugin_version.m_version_major)
sinsp_plugin::version req_version(rversion);
if (!plugin_version.check(req_version))
{
required_version = rversion;
return false;
}

}

return true;
Expand Down
14 changes: 11 additions & 3 deletions userspace/engine/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,19 @@ int falco_rules::add_filter(lua_State *ls)
lua_pop(ls, 1);
}

size_t num_evttypes = lp->filter()->evttypes().size();
// todo(jasondellaluce,leogr,fededp): temp workaround, remove when fixed in libs
size_t num_evttypes = 1; // assume plugin
if(source == "syscall" || source == "k8s_audit")
{
num_evttypes = lp->filter()->evttypes().size();
}

try {
try
{
rules->add_filter(lp->filter(), rule, source, tags);
} catch (exception &e) {
}
catch (exception &e)
{
std::string errstr = string("Could not add rule to falco engine: ") + e.what();
lua_pushstring(ls, errstr.c_str());
lua_error(ls);
Expand Down
10 changes: 6 additions & 4 deletions userspace/engine/ruleset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void falco_ruleset::ruleset_filters::remove_wrapper_from_list(filter_wrapper_lis

void falco_ruleset::ruleset_filters::add_filter(std::shared_ptr<filter_wrapper> wrap)
{
std::set<uint16_t> fevttypes = wrap->filter->evttypes();
std::set<uint16_t> fevttypes = wrap->evttypes();

if(fevttypes.empty())
{
Expand All @@ -91,7 +91,7 @@ void falco_ruleset::ruleset_filters::add_filter(std::shared_ptr<filter_wrapper>

void falco_ruleset::ruleset_filters::remove_filter(std::shared_ptr<filter_wrapper> wrap)
{
std::set<uint16_t> fevttypes = wrap->filter->evttypes();
std::set<uint16_t> fevttypes = wrap->evttypes();

if(fevttypes.empty())
{
Expand Down Expand Up @@ -147,16 +147,18 @@ void falco_ruleset::ruleset_filters::evttypes_for_ruleset(std::set<uint16_t> &ev

for(auto &wrap : m_filters)
{
auto fevttypes = wrap->filter->evttypes();
auto fevttypes = wrap->evttypes();
evttypes.insert(fevttypes.begin(), fevttypes.end());
}
}

void falco_ruleset::add(string &name,
void falco_ruleset::add(string &source,
string &name,
set<string> &tags,
std::shared_ptr<gen_event_filter> filter)
{
std::shared_ptr<filter_wrapper> wrap(new filter_wrapper());
wrap->source = source;
wrap->name = name;
wrap->tags = tags;
wrap->filter = filter;
Expand Down
15 changes: 14 additions & 1 deletion userspace/engine/ruleset.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class falco_ruleset
falco_ruleset();
virtual ~falco_ruleset();

void add(std::string &name,
void add(string &source,
std::string &name,
std::set<std::string> &tags,
std::shared_ptr<gen_event_filter> filter);

Expand Down Expand Up @@ -73,9 +74,21 @@ class falco_ruleset

class filter_wrapper {
public:
std::string source;
std::string name;
std::set<std::string> tags;
std::shared_ptr<gen_event_filter> filter;
std::set<uint16_t> evttypes()
{
// todo(jasondellaluce,leogr): temp workarond, remove when fixed in libs
if(source == "syscall" || source == "k8s_audit")
{
return filter->evttypes();
}
// else assume plugins
return {ppm_event_type::PPME_PLUGINEVENT_E};
// workaround end
}
};

typedef std::list<std::shared_ptr<filter_wrapper>> filter_wrapper_list;
Expand Down