Commit Graph

1527 Commits

Author SHA1 Message Date
Mark Stemm
a41bb0dac0 Print stats when shutting down.
At shutdown, print stats on the number of rules triggered by severity
and rule name. This is done by a lua function print_stats and the
associated table rule_output_counts.

When passing rules to outputs, update the counts in rule_output_counts.
2016-05-24 13:56:48 -07:00
Mark Stemm
1a2719437f Add graceful shutdown on SIGINT/SIGTERM.
Add signal handlers for SIGINT/SIGTERM that set a shutdown
flag. Initialize the live inspector with a timeout so the main loop can
watch the flag set by the signal handlers.
2016-05-24 13:56:48 -07:00
Mark Stemm
18f4a20338 Merge pull request #84 from draios/cmake-cleanups
Quote path variables that may contain spaces.
2016-05-24 09:44:23 -07:00
Mark Stemm
66cedc89f2 Don't null-check inspector.
delete(NULL) is ok so don't bother protecting it.
2016-05-23 17:24:38 -07:00
Mark Stemm
2237532ff0 Quote path variables that may contain spaces.
Make sure that references to variables that may be paths (which in turn
may contain spaces) are quoted, so cmake won't break on the spaces.

This fixes https://github.com/draios/falco/issues/79.
2016-05-23 17:20:15 -07:00
Mark Stemm
7be0454f6f Add ability to print name/description of rules.
When run with -l <rule>, falco will print the name/description of the
single rule <rule> and exit. With -L, falco will print the
name/description of all rules.

All the work is done in lua in the rule loader. A new lua function
describe_rule calls the local function describe_single_rule once or
multiple times depending on -l/-L. describe_single_rule prints the rule
name and a wrapped version of the rule description.
2016-05-13 16:30:15 -07:00
Mark Stemm
e662d1eeeb Add name/description to rules.
Add name and description fields to all rules. The name field is actually
a field called 'rule', which corresponds to the 'macro' field for
macros.

Within the rule loader, the state changes slightly. There are two
indices into the set of rules 'rules_by_name' and
'rules_by_idx' (formerly 'outputs'). They both now contain the original
table from the yaml parse. One field 'level' is added which is the
priority mapped to a number.

Get rid of the notion of default priority or output. Every rule must now
provide both.

Go through all current rules and add names and descriptions.
2016-05-13 16:30:09 -07:00
Mark Stemm
92c4c8f622 Merge pull request #50 from draios/cmdline-opts-daemonize
Clean up handling cmdline options wrt config file.
2016-05-11 08:46:59 -07:00
Henri DF
f0263285c3 Merge pull request #53 from draios/fix-lua-install-path
Fix install path for Lua files
2016-05-10 22:12:24 -07:00
Henri DF
451b450869 Fix install path for Lua files 2016-05-10 20:54:20 -07:00
Mark Stemm
13fc4ca77a Fix remaining falco_rules.conf references.
Did a find looking for references to falco_rules.conf. Renamed to falco_rules.yaml.
2016-05-10 16:12:32 -07:00
Mark Stemm
79f9843256 Clean up handling cmdline options wrt config file.
Remove the old use of the '-o' command line option, it wasn't being
used.

Allow any config file option to be overridden on the command line, via
--option/-o. These options are applied to the configuration object after
reading the file, ensuring the command line options override anything in
the config file.

To support this, add some methods to yaml_configuration that allows you
to set the value for a top level key or key + subkey, and methods to
falco_configuration that allow providing a set of command line arguments
alongside the config file.

Ensure that any fatal error is always printed to stderr even if stderr
logging is not enabled. This makes sure that falco won't silently exit
on an error. This is especially important when daemonizing and when an
initial fatal error occurs first.

As a part of this, change all fatal errors to throw exceptions instead,
so all fatal errors get routed through the exception handler.

Improve daemonization by reopening stdin/stdout/stderr to /dev/null so
you don't have to worry about writing to a closed stderr on exit.
2016-05-10 15:52:59 -07:00
Mark Stemm
1d94d3aaed Merge pull request #43 from draios/package-as-service
Package as service
2016-05-09 17:29:24 -07:00
Mark Stemm
594d3d66d5 Allow missing output fields.
Add a leading * to the format string so output with missing fields is
just displayed with '<NA>' values instead of being aborted.

This fixes #42.
2016-05-08 14:27:08 -07:00
Mark Stemm
7389e05852 Handle both ignored events and syscalls.
Henri pointed out that events may also be flagged as ignored. So
populate a second table with the set of ignored events, rename
check_for_ignored_syscalls to check_for_ignored_syscalls_events, and
separately check each table based on whether the LHS of the expression
is evt.type or syscall.type.
2016-05-06 18:12:46 -07:00
Mark Stemm
a787dc84d5 Add daemonization, fix any bugs found.
Add support for daemonizing via the --daemon flag. If daemonized, the
pid is written to the file provided via the --pidfile flag. When
daemonized, falco immediately returns an error if stderr output or
logging was chosen on the command line.

Clean up handling of outputs to match the expected use case (daemon):

 - syslog output is enabled by default
 - stdout output is disabled by default
 - If not configured at all, both outputs are enabled.

Also fix some bugs I found while running via packages:

 - There were still some references to the old rules filename
   falco_rules.conf.
 - The redhat package mistakenly defined some system directories like
   /etc, /etc/init.d. Add them to the exclusion list (See
   https://cmake.org/Bug/view.php?id=13609 for context).
 - Clean up some of the error messages to be more consistent.

After this I was able to build and install debian and rpm
packages. Starting the falco service ran falco as a daemon with syslog
output.
2016-05-06 17:25:54 -07:00
Mark Stemm
4f63461b59 Return errors for ignored syscalls.
Create a table containing the filtered syscalls and set it as the lua
global m_lua_ignored_syscalls == ignored_syscalls.

In the parser, add a general purpose ast traversal function
traverse_ast that calls a callback for all nodes of a specific type.

In the compiler, add a new function check_for_ignored_syscalls that uses
the traversal function to be called back for all "BinaryRelOp"
nodes (i.e. X = Y, X in [a, b, c], etc). For those nodes, if the lhs is
a field 'evt.type' or 'syscall.type' and the rhs contains one of the
ignored syscalls, throw an error.

Call check_for_ignored_syscalls after parsing any macro or rule
filter. The thrown error will contain the macro or rule that had the
ignored syscall.

In the next commit I'll change the rules to skip the ignored syscalls.
2016-05-05 22:52:04 -07:00
Henri DF
fc04ddfe40 Move output code into output.lua 2016-05-06 03:37:23 +00:00
Henri DF
f6c8c4cb84 Fix (and rename) parser smoke test 2016-05-06 03:37:16 +00:00
Henri DF
9dd4e799cb Split out parsing into parser.lua 2016-05-06 03:37:16 +00:00
Henri DF
e1b9b047d0 Support new yaml format for rules
Uses yaml parsing lib to parse a yaml file comprising of a list of
macros and rules, like:

- macro: bin_dir
  condition: fd.directory in (/bin, /sbin, /usr/bin, /usr/sbin)

- macro: core_binaries
  condition: proc.name in (ls, mkdir, cat, less, ps)

- condition: (fd.typechar = 4 or fd.typechar=6) and core_binaries
  output: "%evt.time: %proc.name network with %fd.l4proto"

- condition: evt.type = write and bin_dir
  output: "%evt.time: System binary modified (file '%fd.filename' written by process %proc.name)"

- condition: container.id != host and proc.name = bash
  output: "%evt.time: Shell running in container (%proc.name, %container.id)"
2016-05-06 03:37:16 +00:00
Henri DF
fdafc7da77 Remove dead macro-checking code
The `check_macros` function wasn't doing anything, and checking is done as
part of expansion.
2016-05-06 03:36:59 +00:00
Henri DF
0ec141385d Remove outputs and macros from grammar
These will no longer need to be parsed with the move to yaml
2016-05-06 03:36:59 +00:00
Henri DF
480c964075 Remove traces of in-expr expansion
In-expr expansion has moved to libsinsp (https://github.com/draios/sysdig/pull/565)
2016-05-06 03:36:59 +00:00
Henri DF
77a3e3b110 Load statically-linked lyaml lib and lua bindings 2016-05-06 03:36:59 +00:00
Henri DF
1703d048c3 Add libyaml (c lib) and lyaml (lua bindings) to build 2016-05-06 03:36:59 +00:00
Henri DF
a9f9454d26 Remove unneeded include dir 2016-05-06 03:36:59 +00:00
Mark Stemm
ba80367116 Remove remaining digwatch references (really).
Try harder looking for remaining digwatch references, replacing with
falco.
2016-05-04 15:44:11 -07:00
Mark Stemm
738f555bae Remove remaining Digwatch references.
Remove remaining Digwatch references I noticed while getting up to
speed.
2016-05-02 11:32:33 -07:00
Henri DF
bde9631cd4 More falco->digwatch renaming 2016-05-01 23:13:28 +00:00
Henri DF
5052039ee1 More falco->digwatch renaming 2016-05-01 16:09:49 +00:00
Henri DF
e207bc5f3a Drop high-volume events 2016-04-28 20:58:28 +00:00
Henri DF
abe6220651 Renaming 2016-04-28 03:28:19 +00:00
Henri DF
6d72619968 rename digwatch_syslog -> digwatch_logger 2016-04-22 16:01:00 -07:00
Henri DF
4c64295adc Digwatch logging
Log digwatch messages to syslog and/or stderr
2016-04-22 15:56:18 -07:00
Henri DF
5413935f15 Small tweak to usage message 2016-04-22 15:33:43 -07:00
Henri DF
fad88ee4b7 Remove signal handling
Not currently serving any purpose
2016-04-22 14:59:58 -07:00
Henri DF
45f8096dd3 Add support for json-formatted output 2016-04-21 16:30:51 -07:00
Henri DF
8ad7679f7f Remove priority_level from yaml file
It is not currently used for anything, will revert when that time comes.
2016-04-12 21:49:54 -07:00
Henri DF
6e008a2ff5 Improve error message when rules file not found 2016-04-13 03:43:31 +00:00
Henri DF
a529b11e0d Clean up usage message and choice of flags 2016-04-13 03:43:31 +00:00
Henri DF
86e2e17c33 Change rules file command-line setting
Now is optional, and uses -u rather than passed as a positional arg.
2016-04-13 03:43:31 +00:00
Henri DF
ef93844234 Rename digwatch.conf -> digwatch_rules.conf 2016-04-13 03:43:30 +00:00
Henri DF
357276b787 Fix opt def for scap input file
(was 'R', should be 'r')
2016-04-12 18:36:24 -07:00
Henri DF
b4bc2d52be rename infile -> scap_filename 2016-04-12 18:34:49 -07:00
Henri DF
d0e489b5c2 Remove unneccessary HAS_FILTERING conditional 2016-04-12 18:29:48 -07:00
Henri DF
89b1a55d9e Add file output 2016-04-13 01:19:27 +00:00
Henri DF
b2698f9d20 Set up outputs listed in configuration object 2016-04-13 01:19:21 +00:00
Henri DF
179e5519ce Small refactoring of output config
This is a step towards being able to support multiple outputs of
different types (including file outputs which require their own config).
2016-04-12 23:21:14 +00:00
Henri DF
42de0507fa search for yaml config file
In order:
1) cmdline opt
2) in-tree path
3) /etc/digwatch.yaml
2016-04-12 23:14:44 +00:00
Henri DF
73ec593931 Add a configuration::init() that just sets up defaults
(For when no config file is being used)
2016-04-12 23:13:18 +00:00
Henri DF
dc099bfb91 Add configuration object and Yaml parser
These aren't wired up yet.
2016-04-12 23:13:15 +00:00
Henri DF
af4089dac3 Build and link yaml-cpp lib 2016-04-12 23:13:12 +00:00
Henri DF
b4859015ea Add support for reading .scap files 2016-04-08 16:51:16 -07:00
Henri DF
709568b578 Command-line options simplification
Remove -N and always turn resolution off. Given the possible performance
impact, there shouldn't even be a way to have it on.
2016-04-07 15:12:15 -07:00
Henri DF
dcbae750c8 Remove the need for DIGWATCH_LUA_DIR env var 2016-04-06 23:05:41 +00:00
Henri DF
c7d0c7dbd9 Remove unneeded -m <lua_main_filename> param 2016-04-06 23:05:41 +00:00
Henri DF
f7ba825023 Remove dep on nixio by adding simple syslog lua function 2016-04-06 11:44:00 -07:00
Henri DF
77440750e6 Load probe 2016-04-04 18:39:42 -07:00
Henri DF
86e1eeffb2 Statically link in lpeg lua library 2016-04-04 15:07:16 -07:00
Henri DF
39b1f64510 Packaging: Bundle lua files 2016-03-31 21:18:23 -07:00
Henri DF
37d0f7d3e0 Build .deb, .rpm, and .tgz 2016-03-31 18:54:52 -07:00
Henri DF
8ae908fe85 Rework cmake files
Rather than do include_directory() on the whole sysdig repo, just do it
for driver, libscap, and libsinp.

This is a step on the way to building a digwatch package.
2016-03-31 18:39:49 -07:00
Henri DF
c9806407e8 Priority level internal handling
Handle internally as ints, then translate as appropriate in outputs
2016-03-30 14:38:18 -07:00
Henri DF
d6dee28bbe Output simplification
The Output is now chosen globally (for all rules), on the command line.
2016-03-30 14:27:19 -07:00
Henri DF
f44bd06f1d Remove unused/unimplemented options 2016-03-30 13:20:31 -07:00
Henri DF
5f0123317a Remove function outputs from grammar 2016-03-30 13:00:51 -07:00
Henri DF
6158168a97 Grammar support for priorities 2016-03-29 21:35:07 -07:00
Henri DF
38957d3b14 Add timestamp in function outputs 2016-03-29 19:54:15 -07:00
Henri DF
97d7b125ba Implicit time in output formats
As pointed out by Loris, timestamping output messages should be a
responsibility of the output/collection system.

So as a first step towards this, add timestamps automatically for output
formats, and remove them from rules.
2016-03-29 19:47:57 -07:00
Henri DF
aea9b0054b Minor error handling improvements 2016-03-29 19:31:34 -07:00
Henri DF
faf36cd8d7 Use new sysdig support for fast processing of in-exprs 2016-03-24 14:25:48 -07:00
Henri DF
aa31d0a0fb Optimization: don't nest at every boolean op 2016-03-18 13:10:07 -07:00
Henri DF
9043c89a9b Nice formatting when printing ASTs 2016-03-16 13:00:03 -07:00
Henri DF
7104d52466 minor cmakefile cleanup 2016-03-07 17:27:20 -08:00
Henri DF
8c6bb8a236 Set Lua cpath along with path 2016-03-04 17:54:18 -08:00
Henri DF
331042858f Initial version of outputs.lua 2016-03-03 16:13:08 -08:00
Henri DF
5f681b1bd8 Signal handlers and clean(er) exit 2016-03-04 00:11:09 +00:00
Henri DF
ea158baa8d Fix error string 2016-03-02 22:24:12 +00:00
Henri DF
33ad92e98b Fix typo-bug in lua code 2016-03-01 22:01:45 -08:00
Henri DF
f0da1c724b formats.cpp: print lua error string (like elsewherE) 2016-03-01 22:01:14 -08:00
Henri DF
8343d23c3f remove debugging print from rules_loader.lua 2016-03-01 20:10:34 -08:00
Henri DF
26fcf3415d Add digwatch.fields() to Lua API 2016-03-01 21:54:20 +00:00
Henri DF
3195c8abea formats.{cpp,h}: Get rid of global vars 2016-03-01 21:54:18 +00:00
Henri DF
0cdbdf9215 minor include cleanups 2016-03-01 10:49:19 -08:00
Henri DF
6a99c1a978 Basic support for function calls in outputs 2016-02-29 20:15:50 -08:00
Henri DF
1b7a5bd119 compiler: keep source in FunctionCall ASTs 2016-02-29 13:37:16 -08:00
Henri DF
55b2490314 coding convention 2016-02-28 21:14:46 -08:00
Henri DF
1c04ed7874 rework digwatch event output handling
the high-level change is that events matching a rule are now send into a
lua "on_event" function for handling, rather than doing the handling
down in c++.

more specifics:

before, the lua "load_rule" function registered formatters with
associated IDs with the c++ side, which later used this state to
reconcile events with formats and print output accordingly.

now, no such state is kept on the c++ side. the lua "load_rule" function
maintains the id->formatters map, and uses it to print outputs when it
receives events.

this change simplifies the existing flow and will also make the forthcoming
implementation of function outputs far simpler than it would have been
in the current setup.
2016-02-28 21:06:29 -08:00
Henri DF
f71de57a90 fix unused vars warning in digwatch.cpp 2016-02-28 20:28:47 -08:00
Henri DF
c695051990 rule_loader.lua: comments cleanups 2016-02-28 23:50:10 +00:00
Henri DF
6569f0372d Grammar: support function-call syntax in outputs
This change adds syntax support for function call outputs. For example:

... | syslog(evt, WARN)

Regular outputs are still allowed and parsed in the same way.
2016-02-28 14:28:00 -08:00
Henri DF
733548b80b Grammar: fix commas in lists
commas were (unintentionally) optional in lists. so a list like (a b c)
was a valid three-element list.
2016-02-28 14:24:54 -08:00
Henri DF
96942f8034 Grammar: parse array lookup in fields 2016-02-28 13:20:35 -08:00
Henri DF
4053b7241e Fix 'in' clause expansion 2016-02-25 10:54:42 -08:00
Henri DF
eaeb360b31 Fix macro expansion 2016-02-25 10:54:28 -08:00
Henri DF
d62ea1df24 Support for comments in rules files 2016-02-24 15:47:19 -08:00
Henri DF
2428231c7a Remove unneeded code from digwatch main 2016-02-24 10:32:14 -08:00
Henri DF
1a70d12525 whitespace 2016-02-24 09:17:26 -08:00
Henri DF
5f43446bfa compiler.lua: Move macro checking into own file 2016-02-24 09:03:55 -08:00
Henri DF
a2ec9870de compiler.lua: consistently use 'ast' instead of 'node' 2016-02-24 08:46:33 -08:00
Henri DF
e725be968e rule_loader.lua: add/improve comments 2016-02-24 08:46:12 -08:00
Henri DF
a9d0268390 Move format handling into own class 2016-02-23 18:55:20 -08:00
Henri DF
636429c674 Move lua_State creation to digwatch main 2016-02-23 18:43:41 -08:00
Henri DF
3e73f01472 Always print events
Before this change, events were only printed if they had all the
fields (same behavior as with sysdig when the output format doesn't have
a leading "*"). With this change, all events are printed; those that
don't have all fields are prefixed with a notification.
2016-02-23 18:15:43 -08:00
Henri DF
2f105932fa parser-smoke.sh: add a test 2016-02-23 11:35:11 -08:00
Henri DF
87186df85a digwatch: use appropriate formatter for each event 2016-02-23 10:21:25 -08:00
Henri DF
a3976281a8 Pass rule indices down into filters
This allows to match events back up with the display output they are
associated with.
2016-02-23 18:09:52 +00:00
Henri DF
406f079621 Deep copy macro ASTs when expanding
So that we can individually tag expressions that originate from the same macro (see next commit).
2016-02-23 18:09:52 +00:00
Henri DF
3a56c1a0e4 AST: Rule node always has an Output child node 2016-02-23 18:09:52 +00:00
Henri DF
a7d0132154 Add 'sysdig.set_formatter' and use it in compiler
This allows the compiler to define per-rule formats. They are currently
instantiated and stored on the c++ side, but not being made use of yet.
2016-02-23 18:09:51 +00:00
Henri DF
426097241d Move compiler state and AST grafting to rule_loader.lua
This is needed so that rule_loader (which should be renamed in a later pass..) can tag
filters with their index.
2016-02-22 18:07:54 -08:00
Henri DF
5ba821aaef Fix handling of nested ASTs 2016-02-22 16:26:15 -08:00
Henri DF
d759e3b942 Fix macro expansion bug introduced with Rules 2016-02-22 16:01:40 -08:00
Henri DF
bba5aa6974 Add support for output formats 2016-02-22 21:31:21 +00:00
Henri DF
05362e2c68 compiler: don't fail on empty lines 2016-02-22 21:31:21 +00:00
Henri DF
7853260f38 fix test script 2016-02-22 21:31:21 +00:00
Henri DF
e5637d0cee specify lua5.1 in test.lua 2016-02-22 21:31:21 +00:00
Henri DF
c7bafc9a49 Move lua/ to userspace/digwatch 2016-02-21 13:43:08 -08:00
Henri DF
3d58c3c9ae Compile and load digwatch rules! 2016-02-20 21:25:41 -08:00
Henri DF
9fef5a7b29 Rework loading of Lua and rules files 2016-02-20 16:21:56 -08:00
Henri DF
9b89116a26 Add config_digwatch.h.in 2016-02-20 13:38:57 -08:00
Henri DF
9899680064 Lua parser refactoring
Move compiler loading out of libsinsp/lua_parser.cpp and into a new
class in digwatch/rules.cpp.

This way the libsinsp support is strictly about providing a lua API for
scripts to setup filters. Loading the actual parser and rules is logic
that belongs in the app (digwatch in this case, maybe sysdig down the
line) rather than there.
2016-02-19 20:30:23 -08:00
Henri DF
208930fd55 Simplify error handling in digwatch main 2016-02-19 14:50:51 -08:00
Henri DF
32ad5673c6 Pass filter object into sinsp::set_filter() 2016-02-18 21:09:26 -08:00
Henri DF
4c371e5b1d Add curl dependency 2016-02-19 01:58:17 +00:00
Henri DF
0a294cd5e5 digwatch scaffolding
basic cmake setup and digwatch binary, mostly pulled from sysdig
2016-02-19 01:58:17 +00:00