Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 95cab34

Browse files
committedNov 21, 2024·
chore(userspace/falco): add new suggested_output option to append_output configuration.
Signed-off-by: Federico Di Pierro <[email protected]>
1 parent 7154365 commit 95cab34

File tree

5 files changed

+48
-31
lines changed

5 files changed

+48
-31
lines changed
 

‎falco.yaml

+8-6
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,6 @@ buffered_outputs: false
571571
# deploying it in production.
572572
rule_matching: first
573573

574-
# [Incubating] `suggested_formats`
575-
#
576-
# When enabled, Falco will honor requests by extractor plugins
577-
# that suggest certain fields to be part of outputs.
578-
suggested_formats: true
579-
580574
# [Stable] `outputs_queue`
581575
#
582576
# Falco utilizes tbb::concurrent_bounded_queue for handling outputs, and this parameter
@@ -624,6 +618,7 @@ outputs_queue:
624618
# affect the regular Falco message in any way. These can be specified as a
625619
# custom name with a custom format or as any supported field
626620
# (see: https://falco.org/docs/reference/rules/supported-fields/)
621+
# `suggested_output`: enable the use of extractor plugins suggested fields for the matching source output.
627622
#
628623
# Example:
629624
#
@@ -640,6 +635,13 @@ outputs_queue:
640635
# property you will find three new ones: "evt.cpu", "home_directory" which will contain the value of the
641636
# environment variable $HOME, and "evt.hostname" which will contain the hostname.
642637

638+
# By default, we enable suggested_output for any source.
639+
# This means that any extractor plugin that indicates some of its fields
640+
# as suggested output formats, will see these fields in the output
641+
# in the form "foo_bar=$foo.bar"
642+
append_output:
643+
- suggested_output: true
644+
643645

644646
##########################
645647
# Falco outputs channels #

‎userspace/falco/app/actions/init_falco_engine.cpp

+32-19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ static inline std::string format_suggested_field(const filter_check_info* info)
3535
return out.str();
3636
}
3737

38+
static void add_suggested_output(const falco::app::state& s,
39+
const std::string& src,
40+
const falco_configuration::append_output_config& eo) {
41+
auto src_info = s.source_infos.at(src);
42+
if(!src_info) {
43+
return;
44+
}
45+
auto& filterchecks = *src_info->filterchecks;
46+
std::vector<const filter_check_info*> fields;
47+
filterchecks.get_all_fields(fields);
48+
for(const auto& fld : fields) {
49+
if(fld->m_fields->is_format_suggested()) {
50+
s.engine->add_extra_output_format(format_suggested_field(fld),
51+
src,
52+
eo.m_tags,
53+
eo.m_rule,
54+
false);
55+
}
56+
}
57+
}
58+
3859
void configure_output_format(falco::app::state& s) {
3960
for(auto& eo : s.config->m_append_output) {
4061
if(eo.m_format != "") {
@@ -45,6 +66,17 @@ void configure_output_format(falco::app::state& s) {
4566
false);
4667
}
4768

69+
// Add suggested filtercheck formats to each source output
70+
if(eo.m_suggested_output) {
71+
if(eo.m_source.empty()) {
72+
for(auto& src : s.loaded_sources) {
73+
add_suggested_output(s, src, eo);
74+
}
75+
} else {
76+
add_suggested_output(s, eo.m_source, eo);
77+
}
78+
}
79+
4880
for(auto const& ff : eo.m_formatted_fields) {
4981
s.engine->add_extra_output_formatted_field(ff.first,
5082
ff.second,
@@ -58,25 +90,6 @@ void configure_output_format(falco::app::state& s) {
5890
}
5991
}
6092

61-
// Add suggested filtercheck formats to each source output
62-
if(s.config->m_suggested_formats) {
63-
for(auto& src : s.loaded_sources) {
64-
auto src_info = s.source_infos.at(src);
65-
auto& filterchecks = *src_info->filterchecks;
66-
std::vector<const filter_check_info*> fields;
67-
filterchecks.get_all_fields(fields);
68-
for(const auto& fld : fields) {
69-
if(fld->m_flags & EPF_FORMAT_SUGGESTED) {
70-
s.engine->add_extra_output_format(format_suggested_field(fld),
71-
src,
72-
{},
73-
"",
74-
false);
75-
}
76-
}
77-
}
78-
}
79-
8093
// See https://falco.org/docs/rules/style-guide/
8194
const std::string container_info =
8295
"container_id=%container.id container_image=%container.image.repository "

‎userspace/falco/config_json_schema.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ const char config_schema_string[] = LONG_STRING_CONST(
101101
"buffered_outputs": {
102102
"type": "boolean"
103103
},
104-
"suggested_formats": {
105-
"type": "boolean"
106-
},
107104
"rule_matching": {
108105
"type": "string"
109106
},
@@ -276,6 +273,9 @@ const char config_schema_string[] = LONG_STRING_CONST(
276273
}
277274
]
278275
}
276+
},
277+
"suggested_output": {
278+
"type": "boolean"
279279
}
280280
}
281281
},

‎userspace/falco/configuration.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ falco_configuration::falco_configuration():
7272
m_rule_matching(falco_common::rule_matching::FIRST),
7373
m_watch_config_files(true),
7474
m_buffered_outputs(false),
75-
m_suggested_formats(true),
7675
m_outputs_queue_capacity(DEFAULT_OUTPUTS_QUEUE_CAPACITY_UNBOUNDED_MAX_LONG_VALUE),
7776
m_time_format_iso_8601(false),
7877
m_buffer_format_base64(false),
@@ -484,7 +483,6 @@ void falco_configuration::load_yaml(const std::string &config_name) {
484483
}
485484

486485
m_buffered_outputs = m_config.get_scalar<bool>("buffered_outputs", false);
487-
m_suggested_formats = m_config.get_scalar<bool>("suggested_formats", true);
488486
m_outputs_queue_capacity =
489487
m_config.get_scalar<size_t>("outputs_queue.capacity",
490488
DEFAULT_OUTPUTS_QUEUE_CAPACITY_UNBOUNDED_MAX_LONG_VALUE);

‎userspace/falco/configuration.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class falco_configuration {
100100
std::set<std::string> m_tags;
101101
std::string m_rule;
102102
std::string m_format;
103+
bool m_suggested_output = false;
103104
std::unordered_map<std::string, std::string> m_formatted_fields;
104105
std::set<std::string> m_raw_fields;
105106
};
@@ -155,7 +156,6 @@ class falco_configuration {
155156
bool m_time_format_iso_8601;
156157
bool m_buffer_format_base64;
157158
uint32_t m_output_timeout;
158-
bool m_suggested_formats;
159159

160160
bool m_grpc_enabled;
161161
uint32_t m_grpc_threadiness;
@@ -291,6 +291,10 @@ struct convert<falco_configuration::append_output_config> {
291291
}
292292
}
293293

294+
if(node["suggested_output"]) {
295+
rhs.m_suggested_output = node["suggested_output"].as<bool>();
296+
}
297+
294298
return true;
295299
}
296300
};

0 commit comments

Comments
 (0)
Please sign in to comment.