mirror of
https://github.com/falcosecurity/falco.git
synced 2026-05-12 17:52:56 +00:00
Instead of having hard-coded support for syscall/k8s_audit events, use the notions of filter factories/formatter factories to provide generic support for events having a given source: - Within the engine, maps m_filter_factories / m_rulesets / m_format_factories map from a given source to something that can create filters, hold filters, and create formatters for a given source. The hard-coded sinsp_factory/json_factory objects are removed. - The specific add_xxx_filter/process_xxx_event are general purpose and take an event source. - A new method create_formatter() takes a source/output format and provides a shared_ptr to a formatter than can resolve format strings. This is used by the falco outputs code. - In falco main, create the syscall/k8s_audit filter and formatter factories and pass them to the engine. Later, we might make this configurable/selective. With all of the above changes, the falco engine doesn't need a direct inspector any longer, so remove it. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
98 lines
2.0 KiB
C++
98 lines
2.0 KiB
C++
/*
|
|
Copyright (C) 2019 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <exception>
|
|
#include <mutex>
|
|
|
|
extern "C" {
|
|
#include "lua.h"
|
|
#include "lualib.h"
|
|
#include "lauxlib.h"
|
|
}
|
|
|
|
#include <sinsp.h>
|
|
|
|
//
|
|
// Most falco_* classes can throw exceptions. Unless directly related
|
|
// to low-level failures like inability to open file, etc, they will
|
|
// be of this type.
|
|
//
|
|
|
|
struct falco_exception : std::exception
|
|
{
|
|
falco_exception()
|
|
{
|
|
}
|
|
|
|
virtual ~falco_exception() throw()
|
|
{
|
|
}
|
|
|
|
falco_exception(std::string error_str)
|
|
{
|
|
m_error_str = error_str;
|
|
}
|
|
|
|
char const* what() const throw()
|
|
{
|
|
return m_error_str.c_str();
|
|
}
|
|
|
|
std::string m_error_str;
|
|
};
|
|
|
|
//
|
|
// This is the base class of falco_engine/falco_output. It is
|
|
// responsible for managing a lua state and associated inspector and
|
|
// loading a single "main" lua file into that state.
|
|
//
|
|
|
|
class falco_common
|
|
{
|
|
public:
|
|
falco_common();
|
|
virtual ~falco_common();
|
|
|
|
void init(const char *lua_main_filename, const char *alternate_lua_dir);
|
|
|
|
// Priority levels, as a vector of strings
|
|
static std::vector<std::string> priority_names;
|
|
|
|
// Same as numbers/indices into the above vector
|
|
enum priority_type
|
|
{
|
|
PRIORITY_EMERGENCY = 0,
|
|
PRIORITY_ALERT = 1,
|
|
PRIORITY_CRITICAL = 2,
|
|
PRIORITY_ERROR = 3,
|
|
PRIORITY_WARNING = 4,
|
|
PRIORITY_NOTICE = 5,
|
|
PRIORITY_INFORMATIONAL = 6,
|
|
PRIORITY_DEBUG = 7
|
|
};
|
|
|
|
protected:
|
|
lua_State *m_ls;
|
|
|
|
std::mutex m_ls_semaphore;
|
|
|
|
private:
|
|
void add_lua_path(std::string &path);
|
|
};
|