Commit Graph

737 Commits

Author SHA1 Message Date
Mark Stemm
5382aa4e3b More shell spawners
Add additional shell spawning command lines.

Allow package management binaries in containers--lots of people seem to
do it. Also allow pycompile/py3compile.

I need to refactor the shell spawners to more clearly isolate shell
spawners that we don't want to occur in a container from ones that can
run both inside and outside of a container.
2017-10-09 09:16:24 -07:00
Mark Stemm
3a60caa9ed Merge pull request #285 from draios/add-unbuffered-output
Add ability to make outputs unbuffered
2017-10-06 21:51:53 -07:00
Mark Stemm
7a31c59fe4 Add ability to make outputs unbuffered
A new falco.yaml option buffered_outputs, also controlled by
-U/--unbuffered, sets unbuffered outputs for the output methods. This is
especially useful with keep_alive files/programs where you want the
output right away.

Also add cleanup methods for the output channels that ensure output to
the file/program is flushed and closed.
2017-10-06 21:03:59 -07:00
Mark Stemm
8167510694 Merge pull request #284 from draios/add-full-falco-share-dir
add an absolute-path version of FALCO_SHARE_DIR
2017-10-06 17:04:12 -07:00
Mark Stemm
e92ca7574e Merge pull request #283 from draios/long-lived-program-output
Long lived program output
2017-10-06 16:01:46 -07:00
Mark Stemm
ae73f75d81 add an absolute-path version of FALCO_SHARE_DIR
Needed when embedding in other products.
2017-10-06 15:58:30 -07:00
Mark Stemm
1635d08df0 Allow outputs to keep file/program open
Add the ability to keep file/program outputs open (i.e. writing to the
same open file/program for multiple notifications). A new option to the
file/program output "keep_alive", if true, keeps the file/program pipe
open across events.

This makes the need for unbuffered output aka
https://github.com/draios/falco/issues/211 more pressing. Will add that next.
2017-10-06 15:04:40 -07:00
Mark Stemm
5420d0e3a0 WIP on long-lived program outputs. 2017-10-06 15:03:23 -07:00
Mark Stemm
72014f3522 Merge pull request #282 from draios/fields-in-json-output
Add individual event fields to json output
2017-10-06 15:02:49 -07:00
Mark Stemm
aed1897cf1 Add individual event fields to json output
When json output is set, add a sub-object called output_fields to the
json output that contains the individual templated fields from the
output string. Makes it easier to parse those fields.

This fixes https://github.com/draios/falco/issues/261.
2017-10-06 13:16:41 -07:00
Mark Stemm
1e33358742 Merge pull request #278 from draios/handle-default-file
Rework config file handling
2017-10-06 09:08:45 -07:00
Mark Stemm
dca7686e47 Merge pull request #281 from draios/filter-by-severity
Run rules by priority
2017-10-06 09:08:26 -07:00
Mark Stemm
5c09ef2c3f Fully remove package. 2017-10-05 18:36:34 -07:00
Mark Stemm
8641f3c958 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.
2017-10-05 18:35:39 -07:00
Mark Stemm
283c6eea99 Fully remove falco package.
In case there are modified config files from a prior install.
2017-10-05 18:28:29 -07:00
Mark Stemm
aa073586f1 Add ability to filter events by priority/cleanups
Clean up the handling of priority levels within rules. It used to be a
mix of strings handled in various places. Now, in falco_common.h there's
a consistent type for priority-as-number as well as a list of
priority-as-string values. Priorities are passed around as numbers
instead of strings. It's still permissive about capitalization.

Also add the ability to load rules by severity. New falco
config option "priority=<val>"/-o priority=<val> specifies the minimum
priority level of rules that will be loaded.

Add unit tests for same. The test suppresses INFO notifications for a
rule/trace file combination that would otherwise generate them.
2017-10-05 18:07:54 -07:00
Mark Stemm
c41bcbd240 Merge pull request #277 from draios/append-macros-rules
Add ability to append to rules/macros
2017-09-25 10:56:23 -07:00
Mark Stemm
c7d61305cc Merge pull request #263 from draios/govt-cla
adding govt CLA
2017-09-22 17:27:01 -07:00
Mark Stemm
ab3da5dfcf Update govt cla links.
Use the falco file, and the govt file.
2017-09-22 17:25:16 -07:00
Mark Stemm
95bb96e6ec Merge pull request #269 from dkerwin/add_keepalived_to_run_shell_cmd
Add keepalived to list of shell spawning binaries
2017-09-22 17:19:54 -07:00
Mark Stemm
1666d03afc Merge pull request #270 from dkerwin/add_gitlab_ee
Add official gitlab EE docker image to list of known shell spawning images
2017-09-22 17:19:14 -07:00
Mark Stemm
a38f7f181b Add ability to append to rules/macros
Add the ability to append to rules/macros, like we already do with
lists. For rules/macros, if the object has an append: true key, the
condition value is appended to the condition of an existing rule/macro
with the same name.

Like lists, it's an error to specify append: true without there being an
existing rule/macro.

Also add tests that test the same kind of things we did for lists:
 - That append: true really does append
 - That append: false overwrites the rule/macro
 - That it's an error to append with a prior rule/macro existing.
2017-09-22 17:08:00 -07:00
Riccardo Schirone
2d0963e97c CMakeLists: add messages for lpeg, lyaml and libyaml 2017-09-21 11:47:01 -07:00
Mark Stemm
fbdeb26e99 Merge pull request #276 from draios/fix-readme
Fix readme.
2017-09-19 16:16:27 -07:00
Mark Stemm
7e4d9f5b51 Fix readme.
Fix slack url in README to one that allows self-signup.

This fixes https://github.com/draios/falco/issues/272.
2017-09-19 16:14:30 -07:00
Mark Stemm
5bb94c81ed Merge pull request #275 from draios/change-example-port
Switch port to 8181.
2017-09-18 13:55:22 -07:00
Mark Stemm
30ebfd4bcc Switch port to 8181.
Won't conflict with k8s api server port.
2017-09-18 08:46:50 -07:00
Daniel Kerwin
64145ba961
Add official gitlab EE docker image to list of known shell spawning images.
sysdig-CLA-1.0-signed-off-by: Daniel Kerwin <daniel@gini.net>
2017-09-05 13:41:05 +02:00
Daniel Kerwin
598cbbe5e7
Add keepalived to list oh shell spawning binaries.
sysdig-CLA-1.0-signed-off-by: Daniel Kerwin <daniel@gini.net>
2017-09-04 22:08:47 +02:00
Mark Stemm
240a8ffffa Merge pull request #264 from draios/mergable-lists
Mergable lists
2017-08-10 11:08:36 -07:00
Mark Stemm
d1265ff520 Merge pull request #265 from draios/remove-trailing-newline-output
Remove trailing newlines from output
2017-08-10 09:44:39 -07:00
Mark Stemm
0bc2d4f162 Automated tests for list append.
Test the case of appending to a list and appending to a nonexistent
list (should error).
2017-08-10 09:36:31 -07:00
Mark Stemm
2c189d6a60 Add ability to append to lists.
List nodes can now have an 'append' key. If present and true, any values
in this list will be appended to the end of any existing list with the
same name.

It is an error to have a list with 'append' true that has a name that is
not an existing list.
2017-08-09 18:07:34 -07:00
Mark Stemm
ebed9f8dfd Remove trailing newlines from output
If in yaml, the output field is folded-style aka:

output: <
   some multi-line
   output here

The unfolded string will have a trailing newline. Remove it.
2017-08-09 17:53:53 -07:00
Chris Crane
ed2586eafb adding govt CLA 2017-08-04 13:59:17 -07:00
Mark Stemm
9d6fe878e1 Merge pull request #262 from draios/allow-dots-in-paths
Allow dots in paths.
2017-08-04 11:56:15 -07:00
Mark Stemm
de520a60fb Allow dots in paths.
Add a dot to the set of characters that can be in a path string.
2017-08-04 11:06:51 -07:00
Mark Stemm
5c1aa8dc44 Merge pull request #260 from draios/fix-kernel-path
Use uname -r for kernel modules
2017-07-14 10:08:41 -07:00
Mark Stemm
8d57d18959 Use uname -r for kernel modules
This handles cases where multiple sets of kernel headers are installed.
2017-07-14 09:17:28 -07:00
Mark Stemm
3349decd22 Merge pull request #258 from draios/better-list-substitution
Better list substitution
2017-06-30 16:01:05 -07:00
Mark Stemm
eecc92736b Add unit tests for list substitution/order
Add new unit tests to check that list substitution is working as
expected, with test cases for the list substitution occurring at the
beginning, middle, and end of a condition.

Also add tests that verify that overrides on list/macro/rule names
always occur in order.
2017-06-30 15:12:43 -07:00
Mark Stemm
f1b44da90c Perform list substitution only on word boundaries
When performing list substitution, only replace a list name when it is
surrounded by whitespace or expected punctuation characters. Lua
patterns don't have a notion of this-or-that patterns e.g. (^|abc), so
we have 3 versions of the substitution depending on whether he list name
occurs in the beginning, middle, or end of a string.

This fixes #197.
2017-06-30 15:11:44 -07:00
Mark Stemm
42e50356cf Merge pull request #257 from draios/validate-macros
Also validate macros at parse time.
2017-06-27 17:18:13 -07:00
Mark Stemm
9e7ce4d36f Also validate macros at parse time.
Also validate macros when they are parsed. Macros are also validated as
a part of rules being parsed, but it's possible to have an individual
rules file containing only macros, or a macro not explicitly tied to any
rule. In this case, it's useful to be able to check the macro to see if
it contains dangling macro references.
2017-06-27 16:44:42 -07:00
Mark Stemm
2991ea423a Merge pull request #254 from draios/dont-trim-strings
Don't trim quoted strings
2017-06-20 13:48:31 -07:00
Mark Stemm
481582ca09 Don't trim quoted strings
When parsing condition expressions, if the type of an ast node is
String (aka quoted string), don't trim whitespace from the value. This
ensures that conditions that want to match exact strings e.g. command
lines with leading/trailing spaces will work properly.

This fixes #253.
2017-06-20 11:47:00 -07:00
Mark Stemm
38f488bfda Beta rule updates (#247)
* Updates from beta customers.

- add anacron as a cron program

* Reorganize package management binaries

Split package_management_binaries into two separate lists rpm_binaries
and deb_binaries. unattended-upgr is common to both worlds so it's still
in package_management_binaries.

Also change Write below rpm database to use rpm_binaries instead of its
own list.

Also add 75-system-updat (truncated) as a shell spawner.

* Add rules for jenkins

Add rules that allow jenkins to spawn shells, both in containers and
directly on the host.

Also handle jenkins slaves that run /tmp/slave.jar.

* Allow npm to run shells.

Not yet allowing node to run shells itself, although we want to add
something to reduce node-related FPs.

* Allow urlgrabber/git-remote to access /etc

urlgrabber and git-remote both try to access the RHEL nss database,
containing shared certificates. I may change this in a more general way
by changing open_read/open_write to only look for successful opens.

* Only look for successful open_read/open_writes

Change the macros open_read/open_write to only trigger on successful
opens (when fd.num > 0). This is a pretty big change to behavior, but
is more intuitive.

This required a small update to the open counts for a couple of unit
tests, but otherwise they still all passed with this change.

* Allow rename_device to write below /dev

Part of udev.

* Allow cloud-init to spawn shells.

Part of https://cloud-init.io/

* Allow python to run a shell that runs sdchecks

sdchecks is a part of the sysdig monitor agent.

* Allow dev creation binaries to write below etc.

Specifically this includes blkid and /etc/blkid/blkid.tab.

* Allow git binaries to spawn shells.

They were already allowed to run shells in a container.

* Add /dev/kmsg as an allowed /dev file

Allows userspace programs to write to kernel log.

* Allow other make programs to spawn shells.

Also allow gmake/cmake to spawn shells and put them in their own list
make_binaries.

* Add better mesos support.

Mesos slaves appear to be in a container due to their cgroup and can run
programs mesos-health-check/mesos-docker-exec to monitor the containers
on the slave, so allow them to run shells.

Add mesos-agent, mesos-logrotate, mesos-fetch as shell spawners both in
and out of containers.

Add gen_resolvconf. (short for gen_resolvconf.py) as a program that can
write to /etc.

Add toybox (used by mesos, part of http://landley.net/toybox/about.html)
as a shell spawner.

* systemd can listen on network ports.

Systemd can listen on network ports to launch daemons on demand, so
allow it to perform network activity.

* Let docker binaries setuid.

Let docker binaries setuid and add docker-entrypoi (truncation
intentional) to the set of docker binaries.

* Change cis-related rules to be less noisy

Change the two cis-related falco rules "File Open by Privileged
Container" and "Sensitive Mount by Container" to be less noisy. We found
in practice that tracking every open still results in too many falco
notifications.

For now, change the rules to only track the initial process start in the
container by looking for vpid=1. This should result in only triggering
when a privileged/sensitive mount container is started. This is slightly
less coverage but is far less noisy.

* Add quay.io/sysdig as trusted containers

These are used for sysdig cloud onpremise deployments.

* Add gitlab-runner-b(uild) as a gitlab binary.

Add gitlab-runner-b (truncated gitlab-runner-build) as a gitlab binary.

* Add ceph as a shell spawner.

Also allow ceph to spawn shells in a container.

* Allow some shells by command line.

For some mesos containers, where the container doesn't have an image and
is just a tarball in a cgroup/namespace, we don't have any image to work
with. In those cases, allow specific command lines.

* Allow user 'nobody' to setuid.

Allow the user nobody to setuid. This depends on the user nobody being
set up in the first place to have no access, but that should be an ok
assumption.

* Additional allowed shell commandlines

* Add additional shells.

* Allow multiple users to become themself.

Add rule somebody_becoming_themself that handles cases of nobody and
www-data trying to setuid to themself. The sysdig filter language
doesn't support template/variable values to allow "user.name=X and
evt.arg.uid=X for a given X", so we have to enumerate the users.

* More known spawn command lines

* Let make binaries be run in containers.

Some CI/CD pipelines build in containers.

* Add additional shell spawning command lines

* Add additional apt program apt-listchanges.

* Add gitlab-ce as shell spawning container.

* Allow PM2 to spawn shells in containers.

Was already in the general list, seen in some customers, so adding to
the in containers list.

* Clean up pass to fix long lines.

Take a pass through the rules making sure each line is < 120 characters.

* Change tests for privileged container rules.

Change unit tests to reflect the new privileged/sensitive mount
container rules that only detect container launch.
2017-06-19 11:28:15 -07:00
Riccardo Schirone
42a3dd1ea3 Merge branch 'osx-install' into dev 2017-06-19 10:08:59 +02:00
Riccardo Schirone
b8743385e8 Fix installation of falco on OS X (no driver, /usr not writable) 2017-06-16 22:36:13 +02:00
Mark Stemm
87caa55b17 Merge pull request #248 from draios/fix-nodejs-example
Explicitly spawn program via shell.
2017-06-14 16:12:59 -07:00