-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(app): add append_output configuration option with fields and format
Signed-off-by: Luca Guerra <[email protected]>
- Loading branch information
1 parent
8a3cb76
commit 2e4fb9f
Showing
19 changed files
with
629 additions
and
102 deletions.
There are no files selected for viewing
Submodule falcosecurity-rules
updated
10 files
+0 −3 | .github/FALCO_VERSIONS | |
+2 −2 | .github/scripts/requirements.txt | |
+0 −6 | .github/workflows/.yamllint | |
+1 −1 | .github/workflows/release.yaml | |
+4 −6 | .github/workflows/rules.yaml | |
+0 −2 | .github/workflows/yaml-lint.yaml | |
+0 −3 | rules/OWNERS | |
+10 −31 | rules/falco-incubating_rules.yaml | |
+40 −31 | rules/falco-sandbox_rules.yaml | |
+7 −8 | rules/falco_rules.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* | ||
Copyright (C) 2024 The Falco Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "../test_falco_engine.h" | ||
|
||
TEST_F(test_falco_engine, extra_format_all) | ||
{ | ||
std::string rules_content = R"END( | ||
- rule: legit_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: user=%user.name command=%proc.cmdline file=%fd.name | ||
priority: INFO | ||
)END"; | ||
|
||
m_engine->add_extra_output_format("evt.type=%evt.type", "", "", "", false); | ||
ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; | ||
|
||
EXPECT_EQ(get_compiled_rule_output("legit_rule"),"user=%user.name command=%proc.cmdline file=%fd.name evt.type=%evt.type"); | ||
} | ||
|
||
TEST_F(test_falco_engine, extra_format_by_rule) | ||
{ | ||
std::string rules_content = R"END( | ||
- rule: legit_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: out 1 | ||
priority: INFO | ||
- rule: another_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: out 2 | ||
priority: INFO | ||
)END"; | ||
|
||
m_engine->add_extra_output_format("evt.type=%evt.type", "", "", "legit_rule", false); | ||
ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; | ||
|
||
EXPECT_EQ(get_compiled_rule_output("legit_rule"),"out 1 evt.type=%evt.type"); | ||
EXPECT_EQ(get_compiled_rule_output("another_rule"),"out 2"); | ||
} | ||
|
||
TEST_F(test_falco_engine, extra_format_by_tag_rule) | ||
{ | ||
std::string rules_content = R"END( | ||
- rule: legit_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: out 1 | ||
priority: INFO | ||
tags: [tag1] | ||
- rule: another_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: out 2 | ||
priority: INFO | ||
tags: [tag1] | ||
)END"; | ||
|
||
m_engine->add_extra_output_format("extra 1", "", "tag1", "", false); | ||
m_engine->add_extra_output_format("extra 2", "", "", "another_rule", false); | ||
|
||
ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; | ||
|
||
EXPECT_EQ(get_compiled_rule_output("legit_rule"),"out 1 extra 1"); | ||
EXPECT_EQ(get_compiled_rule_output("another_rule"),"out 2 extra 1 extra 2"); | ||
} | ||
|
||
TEST_F(test_falco_engine, extra_format_replace_container_info) | ||
{ | ||
std::string rules_content = R"END( | ||
- rule: legit_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: out 1 (%container.info) | ||
priority: INFO | ||
tags: [tag1] | ||
- rule: another_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: out 2 | ||
priority: INFO | ||
tags: [tag1] | ||
)END"; | ||
|
||
m_engine->add_extra_output_format("extra 1", "", "", "", true); | ||
|
||
ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; | ||
|
||
EXPECT_EQ(get_compiled_rule_output("legit_rule"), "out 1 (extra 1)"); | ||
EXPECT_EQ(get_compiled_rule_output("another_rule"), "out 2 extra 1"); | ||
} | ||
|
||
TEST_F(test_falco_engine, extra_format_do_not_replace_container_info) | ||
{ | ||
std::string rules_content = R"END( | ||
- rule: legit_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: out 1 (%container.info) | ||
priority: INFO | ||
tags: [tag1] | ||
)END"; | ||
|
||
ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; | ||
|
||
auto output = get_compiled_rule_output("legit_rule"); | ||
EXPECT_TRUE(output.find("%container.info") == output.npos); | ||
} | ||
|
||
TEST_F(test_falco_engine, extra_fields_all) | ||
{ | ||
std::string rules_content = R"END( | ||
- rule: legit_rule | ||
desc: legit rule description | ||
condition: evt.type=open | ||
output: user=%user.name command=%proc.cmdline file=%fd.name | ||
priority: INFO | ||
)END"; | ||
|
||
std::unordered_map<std::string, std::string> extra_formatted_fields = {{"my_field", "hello %evt.num"}}; | ||
for (auto const& f : extra_formatted_fields) | ||
{ | ||
m_engine->add_extra_output_formatted_field(f.first, f.second, "", "", ""); | ||
} | ||
|
||
ASSERT_TRUE(load_rules(rules_content, "legit_rules.yaml")) << m_load_result_string; | ||
|
||
EXPECT_EQ(get_compiled_rule_formatted_fields("legit_rule"), extra_formatted_fields); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* | ||
Copyright (C) 2024 The Falco Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <falco/configuration.h> | ||
|
||
TEST(ConfigurationRuleOutputOptions, parse_yaml) | ||
{ | ||
falco_configuration falco_config; | ||
ASSERT_NO_THROW(falco_config.init_from_content(R"( | ||
append_output: | ||
- source: syscall | ||
tag: persistence | ||
rule: some rule name | ||
format: "gparent=%proc.aname[2] ggparent=%proc.aname[3] gggparent=%proc.aname[4]" | ||
- tag: persistence | ||
fields: | ||
- proc.aname[2]: "%proc.aname[2]" | ||
- proc.aname[3]: "%proc.aname[3]" | ||
- proc.aname[4]: "%proc.aname[4]" | ||
format: "gparent=%proc.aname[2] ggparent=%proc.aname[3] gggparent=%proc.aname[4]" | ||
- source: k8s_audit | ||
fields: | ||
- ka.verb | ||
- static_field: "static content" | ||
)", {})); | ||
|
||
EXPECT_EQ(falco_config.m_append_output.size(), 3); | ||
|
||
EXPECT_EQ(falco_config.m_append_output[0].m_source, "syscall"); | ||
EXPECT_EQ(falco_config.m_append_output[0].m_tag, "persistence"); | ||
EXPECT_EQ(falco_config.m_append_output[0].m_rule, "some rule name"); | ||
EXPECT_EQ(falco_config.m_append_output[0].m_formatted_fields.size(), 0); | ||
EXPECT_EQ(falco_config.m_append_output[0].m_format, "gparent=%proc.aname[2] ggparent=%proc.aname[3] gggparent=%proc.aname[4]"); | ||
|
||
EXPECT_EQ(falco_config.m_append_output[1].m_tag, "persistence"); | ||
EXPECT_EQ(falco_config.m_append_output[1].m_format, "gparent=%proc.aname[2] ggparent=%proc.aname[3] gggparent=%proc.aname[4]"); | ||
|
||
EXPECT_EQ(falco_config.m_append_output[1].m_formatted_fields.size(), 3); | ||
EXPECT_EQ(falco_config.m_append_output[1].m_formatted_fields["proc.aname[2]"], "%proc.aname[2]"); | ||
EXPECT_EQ(falco_config.m_append_output[1].m_formatted_fields["proc.aname[3]"], "%proc.aname[3]"); | ||
EXPECT_EQ(falco_config.m_append_output[1].m_formatted_fields["proc.aname[4]"], "%proc.aname[4]"); | ||
|
||
EXPECT_EQ(falco_config.m_append_output[2].m_source, "k8s_audit"); | ||
|
||
EXPECT_EQ(falco_config.m_append_output[2].m_formatted_fields.size(), 1); | ||
EXPECT_EQ(falco_config.m_append_output[2].m_formatted_fields["static_field"], "static content"); | ||
|
||
EXPECT_EQ(falco_config.m_append_output[2].m_raw_fields.size(), 1); | ||
EXPECT_EQ(falco_config.m_append_output[2].m_raw_fields.count("ka.verb"), 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.