Skip to content
Open
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
20 changes: 16 additions & 4 deletions plugins/k8smeta/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ falcosecurity::init_schema my_plugin::get_init_schema()
"description": "The port used by the plugin to contact the collector (e.g. '45000')."
},
"nodeName": {
"type": "string",
"type": ["string", "integer"],
"title": "The node on which Falco is deployed",
"description": "The plugin collects k8s metadata only for the node on which Falco is deployed so the node name must be specified."
"description": "The plugin collects k8s metadata only for the node on which Falco is deployed so the node name must be specified. A purely numeric node name may be substituted as a JSON integer rather than a string, so both types are accepted here."
},
"caPEMBundle": {
"type": "string",
Expand Down Expand Up @@ -187,8 +187,20 @@ void my_plugin::parse_init_config(nlohmann::json& config_json)
if(config_json.contains(nlohmann::json::json_pointer(NODENAME_PATH)))
{
std::string nodename_string = "";
config_json.at(nlohmann::json::json_pointer(NODENAME_PATH))
.get_to(nodename_string);
const auto& nodename_json =
config_json.at(nlohmann::json::json_pointer(NODENAME_PATH));
if(nodename_json.is_number_integer())
{
// A purely numeric node name (e.g. "123456") is inferred as a
// JSON integer by Falco's downward API env var substitution,
// even though the schema now also accepts it here. Convert it
// back to a string instead of rejecting it.
nodename_string = std::to_string(nodename_json.get<int64_t>());
}
else
{
nodename_json.get_to(nodename_string);
}

// todo!: Solved in Falco 0.37.0 wait until Falco 0.36.2 is barely used
// This is just a simple workaround until we solve the Falco issue
Expand Down
16 changes: 16 additions & 0 deletions plugins/k8smeta/test/src/init_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ TEST_F(sinsp_with_test_input, plugin_k8s_env_variable)
ASSERT_EQ(err, "");
}

TEST_F(sinsp_with_test_input, plugin_k8s_with_numeric_node_name)
{
auto plugin_owner = m_inspector.register_plugin(PLUGIN_PATH);
ASSERT_TRUE(plugin_owner.get());
std::string err;

// A purely numeric Kubernetes node name (e.g. "123456") is inferred as a
// JSON integer rather than a string by Falco's downward API env var
// substitution. The schema and parser must accept it rather than
// rejecting it with a schema validation error.
ASSERT_NO_THROW(plugin_owner->init(R"(
{"collectorHostname":"localhost","collectorPort":45000,"nodeName":123456})",
err));
ASSERT_EQ(err, "");
}

TEST_F(sinsp_with_test_input, plugin_k8s_with_host_proc)
{
auto plugin_owner = m_inspector.register_plugin(PLUGIN_PATH);
Expand Down