Commit Graph

955 Commits

Author SHA1 Message Date
Néstor Salceda
f7c17bb1a5 This apiGroup is not needed on the CNCF flavor
I remove it for avoiding breaking stuff.
2018-11-27 17:02:02 +01:00
Jorge Salamero Sanz
21f16f0cb0
Merge pull request #465 from nestorsalceda/falco-aws-permissions-fix
Fix AWS permissions for Kubernetes Response Engine
2018-11-20 10:11:00 +01:00
Mark Stemm
d1329af3bd
Avoid going past end of ruleset/etag arrays (#468)
It's possible to call event_tags_for_ruleset/evttypes_for_ruleset for a
ruleset that hasn't been loaded. In this case, it's possible to go past
the end of the m_rulesets array.

After fixing that, it's also possible to go past the end of the
event_tags array in event_tags_for_ruleset().

So in both cases, check the index against the array size before
indexing.
2018-11-15 16:42:14 -08:00
Néstor Salceda
1308d7fc35 Put RBAC configuration together
Although it duplicates some code, we prefer duplicate some code and
place this files together.
2018-11-12 17:34:21 +01:00
Néstor Salceda
c24fa324d2 Use a newly created system account instead of my personal one
This restricts attack surface, and work better in term of automation.
2018-11-12 11:49:07 +01:00
Néstor Salceda
e15ee1d28d Use deploy as target instead of name
Maintain consistency between deployments
2018-11-12 11:49:07 +01:00
Néstor Salceda
1da02bf3ff Honor the principle of least privilege for CNCF deployment
Instead of giving a lot of permissions set only the needed ones
2018-11-12 11:49:07 +01:00
Néstor Salceda
4696519deb Honor the principle of least privilege for AWS deployment
Configure needed permisssions instead of using one too permissive.
2018-11-12 11:49:07 +01:00
Néstor Salceda
e321d7c8de Fix script documentation and parameters 2018-11-12 11:49:07 +01:00
Mark Stemm
3fd573e432
Update CHANGELOG, README for 0.13.0 (#463)
Noting new features and bumping version.
2018-11-09 13:30:51 -08:00
Mark Stemm
cd53c58808
Make k8s-audit rules and main rules compatible (#464)
Add k8s audit rules to falco's config so they are read by default.

Rename some generic macros like modify, create, delete in the k8s audit
rules so they don't overlap with macros in the main rules file.
2018-11-09 12:56:05 -08:00
Mark Stemm
c6169e1aaa
Rule updates 2018 11.v1 (#455)
* Add sensitive mount of mouting to /var/lib/kubelet*

* Fix GKE/Istio false positives

- Allow kubectl to write below /root/.kube
- Allow loopback/bridge (e.g. /home/kubernetes/bin/) to setns.
- Let istio pilot-agent write to /etc/istio.
- Let google_accounts(_daemon) write user .ssh files.
- Add /health as an allowed file below /.

This fixes https://github.com/falcosecurity/falco/issues/439.

* Improve ufw/cloud-init exceptions

Tie them to both the program and the file being written.

Also move the cloud-init exception to monitored_directory.
2018-11-09 11:51:15 -08:00
Julien
b79670a79a adding few executables in corresponding groups (#445)
* merge with testing environment

* extra valid executables

* cleaning unused code or duplicate
2018-11-09 10:25:55 -08:00
Mark Stemm
1f28f85bdf
K8s audit evts (#450)
* Add new json/webserver libs, embedded webserver

Add two new external libraries:

 - nlohmann-json is a better json library that has stronger use of c++
   features like type deduction, better conversion from stl structures,
   etc. We'll use it to hold generic json objects instead of jsoncpp.

 - civetweb is an embeddable webserver that will allow us to accept
   posted json data.

New files webserver.{cpp,h} start an embedded webserver that listens for
POSTS on a configurable url and passes the json data to the falco
engine.

New falco config items are under webserver:
  - enabled: true|false. Whether to start the embedded webserver or not.
  - listen_port. Port that webserver listens on
  - k8s_audit_endpoint: uri on which to accept POSTed k8s audit events.

(This commit doesn't compile entirely on its own, but we're grouping
these related changes into one commit for clarity).

* Don't use relative paths to find lua code

You can look directly below PROJECT_SOURCE_DIR.

* Reorganize compiler lua code

The lua compiler code is generic enough to work on more than just
sinsp-based rules, so move the parts of the compiler related to event
types and filterchecks out into a standalone lua file
sinsp_rule_utils.lua.

The checks for event types/filterchecks are now done from rule_loader,
and are dependent on a "source" attribute of the rule being
"sinsp". We'll be adding additional types of events next that come from
sources other than system calls.

* Manage separate syscall/k8s audit rulesets

Add the ability to manage separate sets of rules (syscall and
k8s_audit). Stop using the sinsp_evttype_filter object from the sysdig
repo, replacing it with falco_ruleset/falco_sinsp_ruleset from
ruleset.{cpp,h}. It has the same methods to add rules, associate them
with rulesets, and (for syscall) quickly find the relevant rules for a
given syscall/event type.

At the falco engine level, there are new parallel interfaces for both
types of rules (syscall and k8s_audit) to:
  - add a rule: add_k8s_audit_filter/add_sinsp_filter
  - match an event against rules, possibly returning a result:
    process_sinsp_event/process_k8s_audit_event

At the rule loading level, the mechanics of creating filterchecks
objects is handled two factories (sinsp_filter_factory and
json_event_filter_factory), both of which are held by the engine.

* Handle multiple rule types when parsing rules

Modify the steps of parsing a rule's filter expression to handle
multiple types of rules. Notable changes:

 - In the rule loader/ast traversal, pass a filter api object down,
   which is passed back up in the lua parser api calls like nest(),
   bool_op(), rel_expr(), etc.
 - The filter api object is either the sinsp factory or k8s audit
   factory, depending on the rule type.
 - When the rule is complete, the complete filter is passed to the
   engine using either add_sinsp_filter()/add_k8s_audit_filter().

* Add multiple output formatting types

Add support for multiple output formatters. Notable changes:

 - The falco engine is passed along to falco_formats to gain access to
   the engine's factories.
 - When creating a formatter, the source of the rule is passed along
   with the format string, which controls which kind of output formatter
   is created.

Also clean up exception handling a bit so all lua callbacks catch all
exceptions and convert them into lua errors.

* Add support for json, k8s audit filter fields

With some corresponding changes in sysdig, you can now create general
purpose filter fields and events, which can be tied together with
nesting, expressions, and relational operators. The classes here
represent an instance of these fields devoted to generic json objects as
well as k8s audit events. Notable changes:

 - json_event: holds a json object, used by all of the below

 - json_event_filter_check: Has the ability to extract values out of a
   json_event object and has the ability to define macros that associate
   a field like "group.field" with a json pointer expression that
   extracts a single property's value out of the json object. The basic
   field definition also allows creating an index
   e.g. group.field[index], where a std::function is responsible for
   performing the indexing. This class has virtual void methods so it
   must be overridden.

 - jevt_filter_check: subclass of json_event_filter_check and defines
   the following fields:
     - jevt.time/jevt.rawtime: extracts the time from the underlying json object.
     - jevt.value[<json pointer>]: general purpose way to extract any
       json value out of the underlying object. <json pointer> is a json
       pointer expression
     - jevt.obj: Return the entire object, stringified.

 - k8s_audit_filter_check: implements fields that extract values from
   k8s audit events. Most of the implementation is in the form of macros
   like ka.user.name, ka.uri, ka.target.name, etc. that just use json
   pointers to extact the appropriate value from a k8s audit event. More
   advanced fields like ka.uri.param, ka.req.container.image use
   indexing to extract individual values out of maps or arrays.

 - json_event_filter_factory: used by things like the lua parser api,
   output formatter, etc to create the necessary objects and return
   them.

  - json_event_formatter: given a format string, create the necessary
    fields that will be used to create a resolved string when given a
    json_event object.

* Add ability to list fields

Similar to sysdig's -l option, add --list (<source>) to list the fields
supported by falco. With no source specified, will print all
fields. Source can be "syscall" for inspector fields e.g. what is
supported by sysdig, or "k8s_audit" to list fields supported only by the
k8s audit support in falco.

* Initial set of k8s audit rules

Add an initial set of k8s audit rules. They're broken into 3 classes of
rules:

 - Suspicious activity: this includes things like:
    - A disallowed k8s user performing an operation
    - A disallowed container being used in a pod.
    - A pod created with a privileged pod.
    - A pod created with a sensitive mount.
    - A pod using host networking
    - Creating a NodePort Service
    - A configmap containing private credentials
    - A request being made by an unauthenticated user.
    - Attach/exec to a pod. (We eventually want to also do privileged
      pods, but that will require some state management that we don't
      currently have).
    - Creating a new namespace outside of an allowed set
    - Creating a pod in either of the kube-system/kube-public namespaces
    - Creating a serviceaccount in either of the kube-system/kube-public
      namespaces
    - Modifying any role starting with "system:"
    - Creating a clusterrolebinding to the cluster-admin role
    - Creating a role that wildcards verbs or resources
    - Creating a role with writable permissions/pod exec permissions.
 - Resource tracking. This includes noting when a deployment, service,
    - configmap, cluster role, service account, etc are created or destroyed.
 - Audit tracking: This tracks all audit events.

To support these rules, add macros/new indexing functions as needed to
support the required fields and ways to index the results.

* Add ability to read trace files of k8s audit evts

Expand the use of the -e flag to cover both .scap files containing
system calls as well as jsonl files containing k8s audit events:

If a trace file is specified, first try to read it using the
inspector. If that throws an exception, try to read the first line as
json. If both fail, return an error.

Based on the results of the open, the main loop either calls
do_inspect(), looping over system events, or
read_k8s_audit_trace_file(), reading each line as json and passing it to
the engine and outputs.

* Example showing how to enable k8s audit logs.

An example of how to enable k8s audit logging for minikube.

* Add unit tests for k8s audit support

Initial unit test support for k8s audit events. A new multiplex file
falco_k8s_audit_tests.yaml defines the tests. Traces (jsonl files) are
in trace_files/k8s_audit and new rules files are in
test/rules/k8s_audit.

Current test cases include:

- User outside allowed set
- Creating disallowed pod.
- Creating a pod explicitly on the allowed list
- Creating a pod w/ a privileged container (or second container), or a
  pod with no privileged container.
- Creating a pod w/ a sensitive mount container (or second container), or a
  pod with no sensitive mount.
- Cases for a trace w/o the relevant property + the container being
  trusted, and hostnetwork tests.
- Tests that create a Service w/ and w/o a NodePort type.
- Tests for configmaps: tries each disallowed string, ensuring each is
  detected, and the other has a configmap with no disallowed string,
  ensuring it is not detected.
- The anonymous user creating a namespace.
- Tests for all kactivity rules e.g. those that create/delete
  resources as compared to suspicious activity.
- Exec/Attach to Pod
- Creating a namespace outside of an allowed set
- Creating a pod/serviceaccount in kube-system/kube-public namespaces
- Deleting/modifying a system cluster role
- Creating a binding to the cluster-admin role
- Creating a cluster role binding that wildcards verbs or resources
- Creating a cluster role with write/pod exec privileges

* Don't manually install gcc 4.8

gcc 4.8 should already be installed by default on the vm we use for
travis.
2018-11-09 10:15:39 -08:00
TaoBeier
ff4f7ca13b Update repo links. (#447)
falco-CLA-1.0-signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
2018-11-07 08:35:10 -08:00
Néstor Salceda
071e8de075 Port Kubernetes Response Engine to AWS Technology (#460)
* Add a falco-sns utility which publishes to an AWS SNS topic

* Add an script for deploying function in AWS Lambda

* Bump dependencies

* Use an empty topic and pass AWS_DEFAULT_REGION environment variable

* Add gitignore

* Install ca-certificates.

Are used when we publish to a SNS topic.

* Add myself as a maintainer

* Decode events from SNS based messages

* Add Terraform manifests for getting an EKS up and running

Please, take attention to setup kubectl  and how to join workers:

https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#obtaining-kubectl-configuration-from-terraform
https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#required-kubernetes-configuration-to-join-worker-nodes

* Ignore terraform generated files

* Remove autogenerated files

* Also publish MessageAttributes which allows to use Filter Policies

This allows to subscribe only to errors, or warnings or several
priorities or by rule names.

It covers same funcionality than NATS publishe does.

* Add kubeconfig and aws-iam-authenticator from heptio to Lambda environment

* Add role trust from cluster creator to lambda role

* Enable CloudWatch for Lambda stuff

* Generate kubeconfig, kubeconfig for lambdas and the lambda arn

This is used by deployment script

* Just a cosmetic change

* Add a Makefile which creates the cluster and configures it

* Use terraform and artifacts which belongs to this repository for deploying

* Move CNCF related deployment to its own directory

* Create only SNS and Lambda stuff.

Assume that the EKS cluster will be created outside

* Bridge IAM with RBAC

This allows to use the role for lambdas for authenticating against
Kubernetes

* Do not rely on terraform for deploying a playbook in lambda

* Clean whitespace

* Move rebased playbooks to functions

* Fix rebase issues with deployment and rbac stuff

* Add a clean target to Makefile

* Inject sys.path modification to Kubeless function deployment

* Add documentation and instructions
2018-11-07 08:34:13 -08:00
Mark Stemm
32f8e304eb
Load/unload kernel module on start/stop (#459)
* Load/unload kernel module on start/stop

When falco is started, load the kernel module. (The falco binary also
will do a modprobe if it can't open the inspector, as a backup).

When falco is stopped, unload the kernel module.

This fixes https://github.com/falcosecurity/falco/issues/418.

* Put script execute line in right place.
2018-11-06 13:07:50 -08:00
Mark Stemm
6eac49e5ae
Restart falco on SIGHUP. (#457)
Add a signal handler for SIGHUP that sets a global variable g_restart.

All the real execution of falco was already centralized in a standalone
function falco_init(), so simply exit on g_restart=true and call
falco_init() in a loop that restarts if g_restart is set to true.

Take care to not daemonize more than once and to reset the getopt index
to 1 on restart.

This fixes https://github.com/falcosecurity/falco/issues/432.
2018-11-06 11:14:10 -08:00
Mark Stemm
53c7e101fe
Add netcat to docker images (#456)
It may be useful as a way to enable generic event forwarding.

This fixes https://github.com/falcosecurity/falco/issues/433.
2018-11-05 17:50:53 -08:00
Jorge Salamero Sanz
774046d57e
Merge pull request #448 from nestorsalceda/capturer-use-volumes
Allow that sysdig/capturer used in Kubernetes Response Engine uses volumes
2018-11-05 10:19:29 +01:00
Kaizhe Huang
438f647984 fix deply_playbook option issue (#452) 2018-11-02 17:20:24 -07:00
Mark Stemm
8c6ebd586d
Update nodejs example (#449)
Update the express version to mitigate some security vulnerabilities.

Update the port to match the one used by demo.yml.

Change to /usr/src/app so npm install works as expected.
2018-10-26 05:51:33 -07:00
Néstor Salceda
c531d91493 Only upload file to S3 if we have credentials and target bucket 2018-10-26 12:49:23 +02:00
Néstor Salceda
48d01203ef Add a makefile for automating docker image building and pushing 2018-10-25 18:07:21 +02:00
Néstor Salceda
43126362c3 Use /captures and allow to be mounted as a volume for placing files on host 2018-10-25 18:07:21 +02:00
Jorge Salamero Sanz
ef9c4ee6ab
Merge pull request #442 from nestorsalceda/falco-new-organization
Pull image from falcosecurity
2018-10-22 15:56:31 +02:00
Jorge Salamero Sanz
38771923ca
Merge pull request #444 from nestorsalceda/kre-training
Fix issues found for training session
2018-10-19 13:47:43 +02:00
Néstor Salceda
5b060d2c0f Remove the description fields
These can cause conflict with kubeadm k8s clusters
2018-10-19 13:08:20 +02:00
Néstor Salceda
47828f259f Revert "Update Kubeless version"
This reverts commit e614e64331.
2018-10-19 13:06:40 +02:00
Néstor Salceda
e614e64331 Update Kubeless version
We had to remove a couple of lines in the YAML's in order to make it
work.
2018-10-19 12:57:14 +02:00
Néstor Salceda
a3e336f782 Add permissions for functions run in Kubeless 2018-10-19 12:38:02 +02:00
Néstor Salceda
7d24eba1b6 Make playbooks compatible with Python 2.7 2018-10-19 12:36:31 +02:00
Mark Stemm
7dbdb00109
Also add endswith to lua parser (#443)
* Also add endswith to lua parser

Add endswith as a symbol so it can be parsed in filter expressions.

* Unit test for endswith support

Add a test case for endswith support, based on the filename ending with null.
2018-10-18 09:59:13 -07:00
Néstor Salceda
a2319d2b8a Pull image from falcosecurity 2018-10-17 18:10:33 +02:00
Néstor Salceda
8d60d374f7 Add an integration with Phantom (#411)
* Add a Phantom Client which creates containers in Phantom server

* Add a playbook for creating events in Phantom using a Falco alert

* Add a flag for configuring SSL checking

* Add a deployable playbook with Kubeless for integrating with Phantom

* Add a README for Phantom integration

* Use named argument as real parameters.

Just cosmetic for clarification

* Call to lower() before checking for case insensitive comparison

* Add the playbook which creates a container in Phantom

I lose it when rebase the branch :P
2018-10-15 13:37:37 -07:00
Mark Stemm
6ca316a7cc
Rule updates 2018 08.v1 (#398)
* Add additional rpm writing programs

rhn_check, yumdb.

* Add 11-dhclient as a dhcp binary

* Let runuser read below pam

It reads those files to check permissions.

* Let chef write to /root/.chef*

Some deployments write directly below /root.

* Refactor openshift privileged images

Rework how openshift images are handled:

Many customers deploy to a private registry, which would normally
involve duplicating the image list for the new registry. Now, split the
image prefix search (e.g. <host>/openshift3) from the check of the image
name. The prefix search is in allowed_openshift_registry_root, and can
be easily overridden to add a new private registry hostname. The image
list check is in openshift_image, is conditioned on
allowed_openshift_registry_root, and does a contains search instead of a
prefix match.

Also try to get a more comprehensive set of possible openshift3 images,
using online docs as a guide.

* Also let sdchecks directly setns

A new macro python_running_sdchecks is similar to
parent_python_running_sdchecks but works on the process itself.

Add this as an exception to Change thread namespace.
2018-10-12 19:44:24 -07:00
TaoBeier
bc34e438ce fix deprecated statement. (#429)
falco-CLA-1.0-signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
2018-10-12 19:43:57 -07:00
Guido García
7fa6fc1b70 fix: use succeeded instead of completed to filter cronjob pods (#441)
Signed-off-by: Guido García <guido.garciabernardo@telefonica.com>
2018-10-12 19:43:27 -07:00
Néstor Salceda
e4ffa55d58 Add a playbook which starts to capturing data using Sysdig and uploads capture to a s3 bucket (#414)
* Fix spec name

* Add a playbook for capturing stuff using sysdig in a container

* Add event-name to job name for avoid collisions among captures

* Implement job for starting container in Pod in Kubernetes Client

We are going to pick data for all Pod, not limited to one container

* Use sysdig/capturer image for capture and upload to s3 the capture

* There is a bug with environment string splitting in kubeless

https://github.com/kubeless/kubeless/issues/824

So here is a workaround which uses multiple --env flags, one for each
environment.

* Use shorter job name. Kubernetes limit is 64 characters.

* Add a deployable playbook with Kubeless for capturing stuff with Sysdig

* Document the integration with Sysdig capture

* Add Dockerfile for creating sysdig-capturer
2018-10-11 16:55:40 -07:00
Néstor Salceda
f746c4cd57 Add a integration with Demisto (#408)
* Create a DemistoClient for publishing Falco alerts to Demisto

* Extract a function for extracting description from Falco output

* Add a playbook which creates a Falco alert as a Demisto incident

* Add a Kubeless Demisto Handler for Demisto integration

* Document the integration with Demisto

* Allow changing SSL certificate verification

* Fix naming for playbook specs

* Call to lower() before checking value of VERIFY_SSL. Allow case insensitive.
2018-10-10 10:28:35 -07:00
Michael Ducy
0499811762
Clean up Readme, Add CNCF requested files for project. (#440)
* clean up readme, add cncf requested files

* emails for maintainers
2018-10-10 01:50:17 -05:00
Mark Stemm
6445cdb950
Better copyright notices (#426)
* Use correct copyright years.

Also include the start year.

* Improve copyright notices.

Use the proper start year instead of just 2018.

Add the right owner Draios dba Sysdig.

Add copyright notices to some files that were missing them.
2018-09-26 19:49:19 -07:00
ztz
6b82ecfa79 Add base64 encoding and snap length support (#410)
sysdig-CLA-1.0-signed-off-by: Yue Feng <ztz5651483@gmail.com>
falco-CLA-1.0-signed-off-by: Yue Feng <ztz5651483@gmail.com>
2018-09-25 12:44:09 -07:00
Brett Bertocci
fc70c635d1 Add dkms+xz dependencies to falco container 2018-09-25 12:06:19 -07:00
Mark Stemm
2352b96d6b
Change license to Apache 2.0 (#419)
Replace references to GNU Public License to Apache license in:

 - COPYING file
 - README
 - all source code below falco
 - rules files
 - rules and code below test directory
 - code below falco directory
 - entrypoint for docker containers (but not the Dockerfiles)

I didn't generally add copyright notices to all the examples files, as
they aren't core falco. If they did refer to the gpl I changed them to
apache.
2018-09-20 11:47:10 -07:00
Mark Stemm
fb3f2178ba
Prepare for 0.12.1 (#417)
Updating readme/changelog.
2018-09-11 13:33:14 -07:00
Mark Stemm
a5ef1c4f4f
Upgrade to curl 7.61.0 (#416)
The configure script in 7.60.0 has a regression.
2018-09-11 13:26:57 -07:00
Mark Stemm
eaaff5a773
Prepare for 0.12.0 (#415)
Add to CHANGELOG and updating version in README.md.
2018-09-11 10:25:10 -07:00
Mattia Pagnozzi
81e2e672f0
Add TBB dependency (#412)
* Add tbb dependency

* Change TBB library URL
2018-09-11 11:59:58 +02:00
Grzegorz Nosek
071e7dff17 Allow Lua sample_dir to be passed to falco_engine constructor
FALCO_ENGINE_SOURCE_LUA_DIR is still the default but can be
overridden now.
2018-08-16 21:36:08 +02:00