Commit Graph

1555 Commits

Author SHA1 Message Date
Leonardo Di Donato
2a9c9bdc53 update(cmake/modules): module to detect Falco version from the git index
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
ae2eb8de8e fix(userspace): ensure threadiness is gt 0
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
c7aff2d4cb new(userspace/falco): register version gRPC service
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
bc297bdc8f build: better way to extract falco commit hash (also extract ref)
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
2a91289ee4 update(userspace/falco): request context and request stream context templatize the service too now
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
c224633454 new(userspace/falco): initial work for version gRPC svc registration
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
714a6619ad new(userspace/falco): gRPC unary version service impl
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
550ee0d8fc build: compile version proto
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
8d49e45d44 docs(userspace/falco): document version protobuf
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
5e8f98ea92 new(userspace/falco): protobuf for gRPC version service
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
e560056b92 update(userspace/falco): define version part variables
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Leonardo Di Donato
84261d2071 build: extract version pieces
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-07 11:28:57 +01:00
Lorenzo Fontana
af3d89b706 fix(userspace/engine): formatting and auto declarations
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2020-02-06 19:16:21 +01:00
Lorenzo Fontana
5b9001d1d5 fix(userspace/engine): make sure that m_uses_paths is always false by default
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2020-02-06 19:16:21 +01:00
Lorenzo Fontana
240f7e2057 fix(userspace/engine): base64 format fix
Signed-off-by: Lorenzo Fontana <lo@linux.com>
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com>
2020-02-04 21:00:00 +01:00
Vaibhav
22a95796c1 feat(userspace): Add banned.h which includes banned functions.
This defines certain functions as invalid tokens, i.e., when
compiled, the compiler throws an error.

Currently only `strcpy` is included as a banned function.

Fixes #788

Signed-off-by: Vaibhav <vrongmeal@gmail.com>
2020-02-04 17:47:56 +01:00
Leonardo Di Donato
739d79a1eb chore: double-quoting verify fields variables
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-01-21 12:51:50 +01:00
Leonardo Di Donato
76fbecf907 build: cmake falco target deps
Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-01-17 19:09:31 +01:00
Leonardo Di Donato
d6e246a26a build: use SYSDIG_SOURCE_DIR into falco CMakeLists.txt files
Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2020-01-17 19:09:31 +01:00
Lorenzo Fontana
b96e17fe5d new: fix lyaml dependencies
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2020-01-17 19:09:31 +01:00
Mark Stemm
c53df3af00 Don't rethrow exceptions in parse_k8s_audit_json
Callers aren't expected to catch execeptions and instead rely on the
bool return value to indicate whether or not the parsing was successful.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-12-16 17:00:50 -08:00
Mark Stemm
4c576f31f2 Also allow json arrays of k8s audit evts
Currently, the json object POSTed to the /k8s_audit endpoint is assumed
to be an obect, with a "type" of either "Event" or "EventList". When the
K8s API Server POSTs events, it aggregates them into an EventList,
ensuring that there is always a single object.

However, we're going to add some intermediate tools that tail log files
and send them to the endpoint, and the easiest way to send a batch of
events is to pass them as a json array instead of a single object.

To properly handle this, modify parse_k8s_audit_event_json to also
handle a json array. For arrays, it iterates over the objects, calling
parse_k8s_audit_json recursively. This only iterates an initial top
level array to avoid excessive recursion/attacks involving degenerate
json objects with excessively nested arrays.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-12-16 17:00:50 -08:00
Adrián Arroyo Calle
1b05f0e6a7 chore: read hostname in initialization
Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
2019-11-27 22:23:49 +01:00
Adrián Arroyo Calle
4d180cbc31 chore: use std::string to have safer copies
Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
2019-11-27 22:23:49 +01:00
Adrián Arroyo Calle
137e7fc0ec chore: hostname can be 253 characters maximum
Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
2019-11-27 22:23:49 +01:00
Adrián Arroyo Calle
52fbcefa1d chore: add environment variable FALCO_GRPC_HOSTNAME
Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
2019-11-27 22:23:49 +01:00
Adrián Arroyo Calle
a084f17493 feat: add hostname field in gRPC output
Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
2019-11-27 22:23:49 +01:00
Mark Stemm
4e39fee54e Always catch json type errors when extracting
In all extraction functions, always catch json type errors alongside
json out of range errors. Both cases result in not extracting any value
from the event.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-11-18 16:19:58 -08:00
Leonardo Di Donato
6ede7bd422 chore: removing sysdig references
Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-11-14 10:00:36 -08:00
Leonardo Di Donato
9e355e1a74 fix(userspace/falco): typo for consumer related methods
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-11-14 10:00:36 -08:00
Loris Degioanni
3b45e58217 chore: remove some more unnecessary, legacy references to falco in sysdig
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
Co-authored-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-11-14 10:00:36 -08:00
Kris Nova
ae7924cc41 Cleaning up some nomenclature
First of a handful of PRs to start clarifying the independence of Falco

I don't see any breaking changes here, just cosmetic changes.

Signed-off-by: Kris Nova <kris@nivenly.com>
2019-11-05 16:40:56 +01:00
Mark Stemm
023f510a75 Don't pop excess values from stack
The call to rule_loader.load_rules only returns 2 values, so only pop
two values from the stack. This fixes #906.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-10-30 08:52:46 +01:00
Mark Stemm
ccb3cc13b4 Make engine v5 backward compatible w/ v4 rules
As a part of the changes in
https://github.com/falcosecurity/falco/pull/826/, we added several
breaking changes to rules files like renaming/removing some filter
fields. This isn't ideal for customers who are using their own rules
files.

We shouldn't break older rules files in this way, so add some minimal
backwards compatibility which adds back the fields that were
removed *and* actually used in k8s_audit_rules.yaml. They have the same
functionality as before. One exception is
ka.req.binding.subject.has_name, which was only used in a single output
field for debugging and shouldn't have been in the rules file in the
first place. This always returns the string "N/A".

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-10-21 08:09:28 -07:00
Mark Stemm
1c3bed135f Add improved field outputting
Support the notion of a message for all fields in a single class, and
making sure it's wrapped as well as the other fields.

This is used to display a single message about how indexing working for
ka.* filter fields and what IDX_ALLOWED/IDX_NUMERIC/IDX_KEY means,
rather than repeating the same text over and over in every field.

The wrapping is handled by a function falco::utils::wrap_text.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-10-15 19:45:31 +02:00
Mark Stemm
154dd18c8f JSON/K8s Audit Evts extract multiple typed values
Refactor how JSON event/k8s audit events extract values in two important
ways:

1. An event can now extract multiple values.
2. The extracted value is a class json_event_value instead of a simple
string.

The driver for 1. was that some filtercheck fields like
"ka.req.container.privileged" actually should extract multiple values,
as a pod can have multiple containers and it doesn't make sense to
summarize that down to a single value.

The driver for 2. is that by having an object represent a single
extracted value, you can also hold things like numbers e.g. ports, uids,
gids, etc. and ranges e.g. [0:3]. With an object, you can override
operators ==, <, etc. to do comparisons between the numbers and ranges,
or even set membership tests between extracted numbers and sets of
ranges.

This is really handy for a lot of new fields implemented as a part of
PSP support, where you end up having to check for overlaps between the
paths, images, ports, uids, etc in a K8s Audit Event and the acceptable
values, ranges, path prefixes enumerated in a PSP.

Implementing these changes also involve an overhaul of how aliases are
implemented. Instead of having an optional "formatting" function, where
arguments to the formatting function were expressed as text within the
index, define optional extraction and indexing functions. If an
extraction function is defined, it's responsible for taking the full
json object and calling add_extracted_value() to add values. There's a
default extraction function that uses a list of json_pointers with
automatic iteration over array values returned by a json pointer.

There's still a notion of filter fields supporting indexes--that's
simply handled within the default extraction or custom extraction
function. And for most fields, there won't be a need to write a custom
extraction function simply to implement indexing.

Within a json_event_filter_check object, instead of having a single
extracted value as a string, hold a vector of extracted json_event_value
objects (vector because order matters) and a set of json_event_value
objects (for set comparisons) as m_evalues. Values on the right hand
side of the expression are held as a set m_values.

json_event_filter_check::compare now supports IN/INTERSECTS as set
comparisons. It also supports PMATCH using path_prefix_search objects,
which simplifies checks like ka.req.pod.volumes.hostpath--now they can
be expressed as "ka.req.pod.volumes.hostpath intersects (/proc,
/var/run/docker.sock, /, /etc, /root)" instead of
"ka.req.volume.hostpath[/proc]=true or
ka.req.volume.hostpath[/root]=true or ...".

Define ~10 new filtercheck fields that extract pod properties like
hostIpc, readOnlyRootFilesystem, etc. that are relevant for PSP validation.

As a part of these changes, also clarify the names of filter fields
related to pods to always have a .pod in the name. Furthermore, fields
dealing with containers in a pod always have a .pod.containers prefix in
the name.

Finally, change the comparisons for existing k8s audit rules to use
"intersects" and/or "in" when appropriate instead of a single equality
comparison.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-10-15 19:45:31 +02:00
Mark Stemm
b6fec781b7 Add support for parsing "intersects" operator
Related to the changes in https://github.com/draios/sysdig/pull/1501,
add support for an "intersects" operator that verifies if any of the
values in the rhs of an expression are found in the set of extracted
values.

For example:

  (a,b,c) in (a,b) is false, but (a,b,c) intersects (a,b) is true.

The code that implements CO_INTERSECTS is in a different commit.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-10-15 19:45:31 +02:00
Lorenzo Fontana
c76518c681 update: license headers
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com>
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2019-10-08 16:02:26 +02:00
Mark Stemm
2bc4bfd7fb Specify namespace compat w/ gcc 5
I wasn't able to compile the dev branch with gcc 5.4 (e.g. not using the
builder), getting this error:

```
.../falco/userspace/falco/grpc_server.cpp:40:109: error: specialization of ‘template<class Request, class Response> void falco::grpc::request_stream_context<Request, Response>::start(falco::grpc::server*)’ in different namespace [-fpermissive]
 void falco::grpc::request_stream_context<falco::output::request, falco::output::response>::start(server* srv)
                                                                                                             ^
In file included from .../falco/userspace/falco/grpc_server.cpp:26:0:
.../falco/userspace/falco/grpc_server.h:102:7: error:   from definition of ‘template<class Request, class Response> void falco::grpc::request_stream_context<Request, Response>::start(falco::grpc::server*)’ [-fpermissive]
  void start(server* srv);
```

It looks like gcc 5.4 doesn't handle a declaration with namespace blocks
but a definition with namespaces in the
function. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 has more
detail.

A workaround is to add `namespace falco {` and `namespace grpc {` around
the declarations.

Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
2019-10-04 11:43:28 +02:00
Leonardo Di Donato
db3383180c docs(userspace/falco): documenting the keepalive field of the outputs request
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-10-03 11:55:04 +02:00
Leonardo Di Donato
8a6c0b796c fix(userspace/engine): guard lua state into falco engine
Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-09-30 18:07:19 +02:00
Leonardo Di Donato
f0cd3344a2 fix(userspace/falco): guard lua state for falco outputs
Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-09-30 18:07:19 +02:00
Lorenzo Fontana
3d8b7231f3 fix(userspace/falco): meta request should use the request field
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2019-09-30 16:55:24 +03:00
Lorenzo Fontana
221e1b53aa fix(userspace/falco): remove redundant check for grpc outputs
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2019-09-30 16:55:24 +03:00
Leonardo Di Donato
98cdc30aa3 chore(userspace): addressing review comments and typos
Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-09-25 16:43:32 +03:00
Leonardo Di Donato
732965f973 docs(userspace/falco): document output proto messages and service
Co-authored-by: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-09-25 16:43:32 +03:00
Leonardo Di Donato
905379c6da update(userspace/falco): specify go packages into protobuf
Co-authored-by: Lorenzo Fontana <lo@linux.com>

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
2019-09-25 16:43:32 +03:00
Lorenzo Fontana
e6deb59e3d chore(userspace/falco): we don't support tags yet
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com>
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2019-09-25 16:43:32 +03:00
Lorenzo Fontana
eb8248fe04 chore(userspace/falco): better organization of schema and grpc server
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com>
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2019-09-25 16:43:32 +03:00
Lorenzo Fontana
6cf2ccf857 update(userspace/falco): falco_grpc_server is now just server
Co-Authored-By: Leonardo Di Donato <leodidonato@gmail.com>
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2019-09-25 16:43:32 +03:00