Commit Graph

2711 Commits

Author SHA1 Message Date
Mark Stemm
98bc8703c9 Falco test changes (small output matches) for actions
With the advent of actions, there is a more concrete line between
runtime errors (e.g. things that throw exceptions) and errors returned
by actions.

Some of the plugins tests were expecting errors to be returned by
exceptions (e.g. with a leading "Runtime error: and a trailing "
Exiting.").

With actions changes, the errors are just returned directly in
application::run(), so drop the leading and trailing bits in expected
test outputs.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:52:13 -07:00
Mark Stemm
b7a92cc154 Convert direct pointer refs to shared_ptr
Some objects used by actions (falco outputs, falco_formats, etc) were
using raw pointer references, which isn't great.

So convert use of raw pointers (originally passed from falco_init or
functions it called) with shared_ptr, as they are now held in actions
state.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:52:13 -07:00
Mark Stemm
9e4f0888e8 Application changes to support actions
Changes to the falco::app::application object to support actions:

- State that needs to be shared between applications is in a
  falco::app::application::action_state object, accessible via the
  method state().
- The application now has an action manager which adds all the action
  objects defined in defined_app_actions.h.
- application now has a run() method which simply uses the action
  manager to run all the actions. run() returns the result from the
  action manager.
- In a few rare cases (signal handlers, etc.) it wasn't possible to
  pass around an application reference, so create a singleton
  accessible via application::get().

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:52:13 -07:00
Mark Stemm
db2e2b19b3 Move falco_init() code to individual app actions
Move the bulk of the code from falco_init() to individual app action
objects.

To avoid duplicate code for groups, actions derive from one of:
- easyopts_action: returns a group of "easyopts". Includes actions
  like options like --version and --help that don't need
  anything else.
- init_action: returns a group of "init". Most actions in this group.
- run_action: returns a group of "run". daemonize/inspector open/
  event processing are in this group.

Any state that needs to be shared betweeen actions resides in
app::state(), so the moved code stays pretty much as-is, other than
replacing stack variables with member variables in app_state.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:52:13 -07:00
Mark Stemm
481d25f8ee Falco main changes for app actions
This involves moving the code in falco_init() into individual app
actions. falco_init() simply calls app.run() now. The return value
from the action manager is returned from run() and any error is
printed as-is.

app.run() is still inside a catch block to catch any uncaught
exception.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:37:48 -07:00
Mark Stemm
c07c327d87 Initial framework for unit tests of action manager.
Has a set of test actions that simply record when they were run, and a
set of tests that run various sets of actions in known orders and
compare the expected run order to the actual run order.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:25:06 -07:00
Mark Stemm
149fc1e237 Initial action manager object
Add an action manager object that ensures that actions run, honoring
prerequsite order, grouping and run_result.

The bulk of the work is in the "sorting" of actions to preserve
prerequsite order. The comparison function checks to see if one is a
prerequsite of another, either directly or recursively.

The actions are run via a run() method, which iterates over groups,
finds the actions for each group, sorts the actions by prerequsites,
and calls each action's run() method.

Based on the run_result, the manager will:
- proceed with no errors
- stop with no errors
- print any returned error string.

The run result from the last action is returned from run().

After all groups have run, all groups are deinit()ed using each
action's deinit() method.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:25:06 -07:00
Mark Stemm
f9a9ed984c Initial skeleton of "action" object.
An "action" is a piece of code that has a name (e.g. "load plugins")
and can name dependencies (depends on "init inspector").

A run() method is called to do the work of the action, and a deinit()
method is called after all actions are complete to tear down any state
outside the object.

actions can be segregated into groups (e.g. "init" vs "run"). All
actions in a given group are run before actions in the next group. The
action manager is configured with the group order.

Actions have access to to command line options via options() and can
share state with other actions via state().

This will help distribute all the many things falco does in falco_init
into smaller components, while retaining a notion of dependencies and
order.

To make testing easier, most of the functionality is in a base class
::runnable_action, which defines the interface. A derived class
::action additionally brings in an application object and the
state()/options() methods.

This makes it easier to write unit tests for the action manager
without bringing in all of application, falco engine, outputs,
inspector, etc.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 12:25:06 -07:00
Mark Stemm
df219b5e1d New tests for rule + exception, macro with unknown source
Add new test cases for a rule with an unknown source *and* an
exception, and a macro with an unknown source.

The first results in a rule warning (and no error), and the second
prints an error and skips.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 13:54:47 +01:00
Mark Stemm
3fbc90e99e Skip macros with unknown sources
Also skip macros with unknown sources. This matters primarily for
macros related to plugins that have a distinct event source.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 13:54:47 +01:00
Mark Stemm
ad42baed7a Check for unknown sources earlier (to handle exceptions)
If a rule has an unknown source, *and* has exceptions, loading the
rule will result in an error and not skipping the rule. This is
because exceptions are also validated for unknown fields, and that
occurs before the current check for unknown sources.

The fix is to move the check for unknown sources as soon as the rules
object is read.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2022-03-18 13:54:47 +01:00
Leonardo Grasso
31111ab87b docs(README.md): update slack channel URLs
Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
2022-03-17 17:10:30 +01:00
Leonardo Grasso
7d6b46218f docs(brand): add plugin definition
Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
2022-03-17 17:10:30 +01:00
Leonardo Grasso
fded42c203 docs(README.md): adding plugins
Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
2022-03-17 17:10:30 +01:00
Leonardo Grasso
5ff9101b95 docs(README.md): moving section on top
I am co-authoring original authors to keep their credits.

Co-Authored-by: Kris Nova <kris@nivenly.com>
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com>
Co-Authored-By: Massimiliano Giovagnoli <massimiliano.giovagnoli.1992@gmail.com>
Co-Authored-By: Jonah Jones <jonahjones094@gmail.com>
Co-Authored-By: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
2022-03-17 17:10:30 +01:00
Matt Moyer
36acd6dfbf Add user_known_mount_in_privileged_containers
This adds a new macro `user_known_mount_in_privileged_containers` which
allows the easier user-defined exclusions for the "Mount Launched in
Privileged Container" rule.

This would be cleaner with the exclusions feature, but this feature
is not used in the default ruleset yet, if I understand correctly.

Signed-off-by: Matt Moyer <mmoyer@figma.com>
2022-03-17 10:50:56 +01:00
Luca Guerra
4819748ab0 fix(cli): update markdown description
Signed-off-by: Luca Guerra <luca@guerra.sh>

Co-authored-by: Leonardo Grasso <me@leonardograsso.com>
2022-03-17 10:41:56 +01:00
Luca Guerra
f7a5dd0d5b new(falco): add CLI option to print docs in markdown format
Signed-off-by: Luca Guerra <luca@guerra.sh>
2022-03-17 10:41:56 +01:00
Claudio Vellage
4705a92c49 Allow to whitelist config modifiers
Signed-off-by: Claudio Vellage <claudio.vellage@pm.me>
2022-03-15 22:32:59 +01:00
Luca Guerra
a5d3663c75 update(changelog): add link to security fix for 0.31.1
Signed-off-by: Luca Guerra <luca@guerra.sh>
2022-03-11 18:59:56 +01:00
Luca Guerra
58b6496f51 docs(CHANGELOG.md): Changelog for 0.31.1
Signed-off-by: Luca Guerra <luca@guerra.sh>
0.31.1
2022-03-09 17:52:02 +01:00
Luca Guerra
9dd85bf9db fix(cli): restore behavior of -pc -pm -pk CLI options
Signed-off-by: Luca Guerra <luca@guerra.sh>
2022-03-08 09:00:10 +01:00
Luca Guerra
6c4b267109 chore(build): update falco libs to b7eb0dd
Signed-off-by: Luca Guerra <luca@guerra.sh>
2022-03-04 10:48:49 +01:00
Josh Soref
7c005aa9dc spelling: workaround
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
2f2c5c4a9b spelling: whether
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
aadb76f2e9 spelling: validating
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
23f4f0eee0 spelling: unusual
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
97373a8b6e spelling: unknown
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
4ecb907223 spelling: unambiguously
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
db30d0e1c7 spelling: triggered
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
d173ab7a9e spelling: trailing
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
e4e8dcf06b spelling: third
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
e8aac31890 spelling: themselves
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
073339eff1 spelling: the
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
001e7557e6 spelling: the extraction
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
73f98de005 spelling: that
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
3760155ec8 spelling: temporarily
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
d8cfaee242 spelling: syntactic
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
e173bf89a3 spelling: suspicious
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
f12149dc87 spelling: superseded
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
19a6cf74f8 spelling: successfully
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
c62cc5e8c0 spelling: substituted
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
ead40f898a spelling: separate
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
8eef71b801 spelling: rules
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
97883e7535 spelling: resolutions
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
4f897e0dc0 spelling: readability
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
d0ee656dac spelling: provided
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
49b88c14b2 spelling: processing
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
9a314d9443 spelling: privileged
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00
Josh Soref
2b8a88c335 spelling: priorities
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-03-01 16:30:24 +01:00