diff --git a/userspace/falco/CMakeLists.txt b/userspace/falco/CMakeLists.txt index ca211866..c5f8b366 100644 --- a/userspace/falco/CMakeLists.txt +++ b/userspace/falco/CMakeLists.txt @@ -49,6 +49,7 @@ add_library(falco_application STATIC app/actions/validate_rules_files.cpp app/actions/create_requested_paths.cpp app/actions/close_inspectors.cpp + app/actions/print_config_schema.cpp configuration.cpp falco_outputs.cpp outputs_file.cpp diff --git a/userspace/falco/app/actions/actions.h b/userspace/falco/app/actions/actions.h index f9292259..564bffba 100644 --- a/userspace/falco/app/actions/actions.h +++ b/userspace/falco/app/actions/actions.h @@ -38,6 +38,7 @@ falco::app::run_result list_plugins(const falco::app::state& s); falco::app::run_result load_config(const falco::app::state& s); falco::app::run_result load_plugins(falco::app::state& s); falco::app::run_result load_rules_files(falco::app::state& s); +falco::app::run_result print_config_schema(falco::app::state& s); falco::app::run_result print_generated_gvisor_config(falco::app::state& s); falco::app::run_result print_help(falco::app::state& s); falco::app::run_result print_ignored_events(const falco::app::state& s); diff --git a/userspace/falco/app/actions/print_config_schema.cpp b/userspace/falco/app/actions/print_config_schema.cpp new file mode 100644 index 00000000..1eb2b235 --- /dev/null +++ b/userspace/falco/app/actions/print_config_schema.cpp @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Apache-2.0 +/* +Copyright (C) 2024 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. +*/ + +#include "actions.h" + +using namespace falco::app; +using namespace falco::app::actions; + +falco::app::run_result falco::app::actions::print_config_schema(falco::app::state &s) +{ + if(s.options.print_config_schema) + { + printf("%s", s.config->m_config_schema.dump(2).c_str()); + return run_result::exit(); + } + return run_result::ok(); +} diff --git a/userspace/falco/app/app.cpp b/userspace/falco/app/app.cpp index 8b022182..4d1dfae3 100644 --- a/userspace/falco/app/app.cpp +++ b/userspace/falco/app/app.cpp @@ -60,6 +60,7 @@ bool falco::app::run(falco::app::state& s, bool& restart, std::string& errstr) // dependencies are honored (e.g. don't process events before // loading plugins, opening inspector, etc.). std::list run_steps = { + falco::app::actions::print_config_schema, falco::app::actions::load_config, falco::app::actions::print_help, falco::app::actions::print_kernel_version, diff --git a/userspace/falco/app/options.cpp b/userspace/falco/app/options.cpp index 31240cbd..52439b3b 100644 --- a/userspace/falco/app/options.cpp +++ b/userspace/falco/app/options.cpp @@ -110,10 +110,11 @@ void options::define(cxxopts::Options& opts) opts.add_options() ("h,help", "Print this help list and exit.", cxxopts::value(help)->default_value("false")) #ifdef BUILD_TYPE_RELEASE - ("c", "Configuration file. If not specified uses " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "") + ("c", "Configuration file. If not specified uses " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "") #else ("c", "Configuration file. If not specified tries " FALCO_SOURCE_CONF_FILE ", " FALCO_INSTALL_CONF_FILE ".", cxxopts::value(conf_filename), "") #endif + ("config-schema", "Print the config json schema and exit.", cxxopts::value(print_config_schema)->default_value("false")) ("A", "Monitor all events supported by Falco and defined in rules and configs. Some events are ignored by default when -A is not specified (the -i option lists these events ignored). Using -A can impact performance. This option has no effect when reproducing events from a capture file.", cxxopts::value(all_events)->default_value("false")) ("b,print-base64", "Print data buffers in base64. This is useful for encoding binary data that needs to be used over media designed to consume this format.") #if !defined(_WIN32) && !defined(__EMSCRIPTEN__) && !defined(MINIMAL_BUILD) diff --git a/userspace/falco/app/options.h b/userspace/falco/app/options.h index 86d7f143..5e8d0c33 100644 --- a/userspace/falco/app/options.h +++ b/userspace/falco/app/options.h @@ -40,6 +40,7 @@ public: // Each of these maps directly to a command line option. bool help = false; + bool print_config_schema = false; std::string conf_filename; bool all_events = false; sinsp_evt::param_fmt event_buffer_format = sinsp_evt::PF_NORMAL;