-
Notifications
You must be signed in to change notification settings - Fork 926
new(falco): add json_container support and http_output authorization support #3591
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,14 @@ falco_formats::falco_formats(std::shared_ptr<const falco_engine> engine, | |
bool json_include_tags_property, | ||
bool json_include_message_property, | ||
bool json_include_output_fields_property, | ||
const std::string &json_container, | ||
bool time_format_iso_8601): | ||
m_falco_engine(engine), | ||
m_json_include_output_property(json_include_output_property), | ||
m_json_include_tags_property(json_include_tags_property), | ||
m_json_include_message_property(json_include_message_property), | ||
m_json_include_output_fields_property(json_include_output_fields_property), | ||
m_json_container(json_container), | ||
m_time_format_iso_8601(time_format_iso_8601) {} | ||
|
||
falco_formats::~falco_formats() {} | ||
|
@@ -157,7 +159,7 @@ std::string falco_formats::format_event(sinsp_evt *evt, | |
} | ||
} | ||
|
||
return event.dump(); | ||
return format_json_container(event, evttime); | ||
} | ||
|
||
// should never get here until we only have OF_NORMAL and OF_JSON | ||
|
@@ -197,3 +199,32 @@ std::map<std::string, std::string> falco_formats::get_field_values( | |
|
||
return ret; | ||
} | ||
|
||
/// @brief Helper function for encoding a json event into a parent container, described by | ||
/// configuration. | ||
/// @param json the json object to encode | ||
/// @param evttime the event time | ||
/// @return returns a std::string encoded json object according to the configured json_container | ||
std::string falco_formats::format_json_container(nlohmann::json &json, time_t evttime) const { | ||
if(m_json_container == std::string("splunk_hec")) { | ||
nlohmann::json omsg; | ||
omsg["time"] = evttime; | ||
omsg["host"] = json["hostname"]; | ||
omsg["source"] = "falco"; | ||
omsg["event"] = json; | ||
return omsg.dump(); | ||
} else if(m_json_container == std::string("slack_webhook")) { | ||
nlohmann::json omsg; | ||
omsg["text"] = json.dump(); | ||
return omsg.dump(); | ||
} else if(m_json_container == std::string("generic_event_encoded")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that this is a highly custom format. Perhaps a better approach would be to allow users to supply a formal schema via the configuration, supporting only officially recognized schema formats as templates. I'm curious to hear the perspective of other Falco maintainers on this. There seem to be multiple possibilities. For instance, if you check out the I believe this is the main discussion point for this feature. |
||
nlohmann::json omsg; | ||
omsg["event"] = json.dump(); | ||
omsg["host"] = json["hostname"]; | ||
omsg["time"] = evttime; | ||
const std::map<std::string, std::string> &const_labels = {{"evt_type", "falco"}}; | ||
omsg["fields"] = const_labels; | ||
return omsg.dump(); | ||
} | ||
return json.dump(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ falco_configuration::falco_configuration(): | |
m_json_include_tags_property(true), | ||
m_json_include_message_property(false), | ||
m_json_include_output_fields_property(true), | ||
m_json_container(""), | ||
m_rule_matching(falco_common::rule_matching::FIRST), | ||
m_watch_config_files(true), | ||
m_buffered_outputs(false), | ||
|
@@ -347,6 +348,7 @@ void falco_configuration::load_yaml(const std::string &config_name) { | |
m_config.get_scalar<bool>("json_include_message_property", false); | ||
m_json_include_output_fields_property = | ||
m_config.get_scalar<bool>("json_include_output_fields_property", true); | ||
m_json_container = m_config.get_scalar<std::string>("json_container", ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my perspective, in such scenarios, we typically support direct boolean configurations in the config, which later translate into direct boolean checks. Alternatively, string inputs could be converted into flags (typically preferred) — for instance, check out the Adding validity checks on user input while loading the config may be beneficial for free-form string inputs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good callout - I'll migrate this to a flags var so the runtime check is minimal for the default path and shouldn't impact performance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would wait until we have discussed the user input. Maybe some sort of |
||
|
||
m_outputs.clear(); | ||
falco::outputs::config file_output; | ||
|
@@ -461,6 +463,9 @@ void falco_configuration::load_yaml(const std::string &config_name) { | |
m_config.get_scalar<uint8_t>("http_output.max_consecutive_timeouts", 5); | ||
http_output.options["max_consecutive_timeouts"] = std::to_string(max_consecutive_timeouts); | ||
|
||
std::string authorization; | ||
authorization = m_config.get_scalar<std::string>("http_output.authorization", ""); | ||
http_output.options["authorization"] = authorization; | ||
m_outputs.push_back(http_output); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ falco_outputs::falco_outputs(std::shared_ptr<falco_engine> engine, | |
bool json_include_tags_property, | ||
bool json_include_message_property, | ||
bool json_include_output_fields_property, | ||
const std::string &json_container, | ||
uint32_t timeout, | ||
bool buffered, | ||
size_t outputs_queue_capacity, | ||
|
@@ -56,6 +57,7 @@ falco_outputs::falco_outputs(std::shared_ptr<falco_engine> engine, | |
json_include_tags_property, | ||
json_include_message_property, | ||
json_include_output_fields_property, | ||
json_container, | ||
time_format_iso_8601)), | ||
m_buffered(buffered), | ||
m_json_output(json_output), | ||
|
@@ -201,7 +203,7 @@ void falco_outputs::handle_msg(uint64_t ts, | |
jmsg["hostname"] = m_hostname; | ||
jmsg["source"] = s_internal_source; | ||
|
||
cmsg.msg = jmsg.dump(); | ||
cmsg.msg = m_formats->format_json_container(jmsg, evttime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One consideration is that, with these changes, even users who do not actively utilize this new feature may experience the new overhead of these checks for each event. It might be valuable to gather additional feedback. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's double-check whether this formatting also applies to the internal metrics output rules or other internal messages. I recall it involving slightly separate message handling, but I might be mistaken. |
||
} else { | ||
std::string timestr; | ||
bool first = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move these changes to a separate small PR that may be merged more quickly.