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

feat(falco): Provide a parameter for loading lua files from an alternate path #1419

Merged
merged 1 commit into from
Sep 29, 2020
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
67 changes: 40 additions & 27 deletions userspace/falco/falco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static void usage()
" -h, --help Print this page\n"
" -c Configuration file (default " FALCO_SOURCE_CONF_FILE ", " FALCO_INSTALL_CONF_FILE ")\n"
" -A Monitor all events, including those with EF_DROP_SIMPLE_CONS flag.\n"
" --alternate-lua-dir <path> Specify an alternate path for loading Falco lua files\n"
" -b, --print-base64 Print data buffers in base64.\n"
" This is useful for encoding binary data that needs to be used over media designed to.\n"
" --cri <path> Path to CRI socket for container metadata.\n"
Expand Down Expand Up @@ -478,37 +479,38 @@ int falco_init(int argc, char **argv)
#endif

static struct option long_options[] =
{
{"cri", required_argument, 0},
{"daemon", no_argument, 0, 'd'},
{"disable-cri-async", no_argument, 0, 0},
{"disable-source", required_argument, 0},
{"help", no_argument, 0, 'h'},
{"ignored-events", no_argument, 0, 'i'},
{"k8s-api-cert", required_argument, 0, 'K'},
{"k8s-api", required_argument, 0, 'k'},
{"list", optional_argument, 0},
{"mesos-api", required_argument, 0, 'm'},
{"option", required_argument, 0, 'o'},
{"pidfile", required_argument, 0, 'P'},
{"print-base64", no_argument, 0, 'b'},
{"print", required_argument, 0, 'p'},
{"snaplen", required_argument, 0, 'S'},
{"stats-interval", required_argument, 0},
{"support", no_argument, 0},
{"unbuffered", no_argument, 0, 'U'},
{"userspace", no_argument, 0, 'u'},
{"validate", required_argument, 0, 'V'},
{"version", no_argument, 0, 0},
{"writefile", required_argument, 0, 'w'},
{0, 0, 0, 0}
};
{
{"alternate-lua-dir", required_argument, 0},
{"cri", required_argument, 0},
{"daemon", no_argument, 0, 'd'},
{"disable-cri-async", no_argument, 0, 0},
{"disable-source", required_argument, 0},
{"help", no_argument, 0, 'h'},
{"ignored-events", no_argument, 0, 'i'},
{"k8s-api-cert", required_argument, 0, 'K'},
{"k8s-api", required_argument, 0, 'k'},
{"list", optional_argument, 0},
{"mesos-api", required_argument, 0, 'm'},
{"option", required_argument, 0, 'o'},
{"pidfile", required_argument, 0, 'P'},
{"print-base64", no_argument, 0, 'b'},
{"print", required_argument, 0, 'p'},
{"snaplen", required_argument, 0, 'S'},
{"stats-interval", required_argument, 0},
{"support", no_argument, 0},
{"unbuffered", no_argument, 0, 'U'},
{"userspace", no_argument, 0, 'u'},
{"validate", required_argument, 0, 'V'},
{"version", no_argument, 0, 0},
{"writefile", required_argument, 0, 'w'},
{0, 0, 0, 0}};

try
{
set<string> disabled_rule_substrings;
string substring;
string all_rules = "";
string alternate_lua_dir = FALCO_ENGINE_SOURCE_LUA_DIR;
set<string> disabled_rule_tags;
set<string> enabled_rule_tags;

Expand Down Expand Up @@ -686,6 +688,16 @@ int falco_init(int argc, char **argv)
disable_sources.insert(optarg);
}
}
else if (string(long_options[long_index].name)== "alternate-lua-dir")
{
if(optarg != NULL)
{
alternate_lua_dir = optarg;
if (alternate_lua_dir.back() != '/') {
alternate_lua_dir += '/';
}
}
}
break;

default:
Expand Down Expand Up @@ -721,7 +733,7 @@ int falco_init(int argc, char **argv)
return EXIT_SUCCESS;
}

engine = new falco_engine();
engine = new falco_engine(true, alternate_lua_dir);
engine->set_inspector(inspector);
engine->set_extra(output_format, replace_container_info);

Expand Down Expand Up @@ -965,7 +977,8 @@ int falco_init(int argc, char **argv)
config.m_notifications_rate, config.m_notifications_max_burst,
config.m_buffered_outputs,
config.m_time_format_iso_8601,
hostname);
hostname,
alternate_lua_dir);

if(!all_events)
{
Expand Down
5 changes: 3 additions & 2 deletions userspace/falco/falco_outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ falco_outputs::~falco_outputs()
void falco_outputs::init(bool json_output,
bool json_include_output_property,
uint32_t rate, uint32_t max_burst, bool buffered,
bool time_format_iso_8601, string hostname)
bool time_format_iso_8601, string hostname,
const string& alternate_lua_dir)
{
// The engine must have been given an inspector by now.
if(!m_inspector)
Expand All @@ -88,7 +89,7 @@ void falco_outputs::init(bool json_output,

m_json_output = json_output;

falco_common::init(m_lua_main_filename.c_str(), FALCO_SOURCE_LUA_DIR);
falco_common::init(m_lua_main_filename.c_str(), alternate_lua_dir.c_str());

// Note that falco_formats is added to both the lua state used
// by the falco engine as well as the separate lua state used
Expand Down
3 changes: 2 additions & 1 deletion userspace/falco/falco_outputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class falco_outputs : public falco_common
void init(bool json_output,
bool json_include_output_property,
uint32_t rate, uint32_t max_burst, bool buffered,
bool time_format_iso_8601, std::string hostname);
bool time_format_iso_8601, std::string hostname,
const std::string& alternate_lua_dir);

void add_output(output_config oc);

Expand Down