mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-15 06:19:12 +00:00
Rework config file handling
These changes allow for a local rules file that will be preserved across upgrades and allows the main rules file to be overwritten across upgrades. - Move all config/rules files below /etc/falco/ - Add a "local rules" file /etc/falco/falco_rules.local.yaml. The intent is that it contains modifications/deltas to the main rules file /etc/falco/falco_rules.yaml. The main falco_rules.yaml should be treated as immutable. - All config files are flagged so they are not overwritten on upgrade. - Change the handling of the config item "rules_file" in falco.yaml to allow a list of files. By default, this list contains: [/etc/falco/falco_rules.yaml, /etc/falco/falco_rules.local.yaml]. Also change rpm/debian packaging to ensure that the above files are preserved across upgrades: - Use relative paths for share/bin dirs. This ensures that when packaged as rpms they won't be flagged as config files. - Add CMAKE_INSTALL_PREFIX to FALCO_ENGINE_LUA_DIR now that it's relative. - In debian packaging, flag /etc/falco/{falco.yaml,falco_rules.yaml,falco_rules.local.yaml} as conffiles. That way they are preserved across upgrades if modified. - In rpm packaging when using cmake, any files installed with an absolute path are automatically flagged as %config. The only files directly installed are now the config files, so that addresses the problem. Add CMAKE_INSTALL_PREFIX to lua dir.
This commit is contained in:
@@ -18,5 +18,5 @@ along with falco. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#define FALCO_ENGINE_LUA_DIR "${FALCO_SHARE_DIR}/lua/"
|
||||
#define FALCO_ENGINE_LUA_DIR "${CMAKE_INSTALL_PREFIX}/${FALCO_SHARE_DIR}/lua/"
|
||||
#define FALCO_ENGINE_SOURCE_LUA_DIR "${PROJECT_SOURCE_DIR}/../falco/userspace/engine/lua/"
|
||||
|
@@ -51,7 +51,20 @@ void falco_configuration::init(string conf_filename, list<string> &cmdline_optio
|
||||
|
||||
init_cmdline_options(cmdline_options);
|
||||
|
||||
m_rules_filenames.push_back(m_config->get_scalar<string>("rules_file", "/etc/falco_rules.yaml"));
|
||||
list<string> rules_files;
|
||||
|
||||
m_config->get_sequence<list<string>>(rules_files, string("rules_file"));
|
||||
|
||||
for(auto &file : rules_files)
|
||||
{
|
||||
// Here, we only include files that exist
|
||||
struct stat buffer;
|
||||
if(stat(file.c_str(), &buffer) == 0)
|
||||
{
|
||||
m_rules_filenames.push_back(file);
|
||||
}
|
||||
}
|
||||
|
||||
m_json_output = m_config->get_scalar<bool>("json_output", false);
|
||||
|
||||
falco_outputs::output_config file_output;
|
||||
|
@@ -18,6 +18,9 @@ along with falco. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -127,6 +130,27 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// called with the last variadic arg (where the sequence is expected to be found)
|
||||
template <typename T>
|
||||
void get_sequence(T& ret, const std::string& name)
|
||||
{
|
||||
YAML::Node child_node = m_root[name];
|
||||
if(child_node.IsDefined())
|
||||
{
|
||||
if(child_node.IsSequence())
|
||||
{
|
||||
for(const YAML::Node& item : child_node)
|
||||
{
|
||||
ret.insert(ret.end(), item.as<typename T::value_type>());
|
||||
}
|
||||
}
|
||||
else if(child_node.IsScalar())
|
||||
{
|
||||
ret.insert(ret.end(), child_node.as<typename T::value_type>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
YAML::Node m_root;
|
||||
};
|
||||
|
Reference in New Issue
Block a user