Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC server and gRPC outputs service #822

Merged
merged 76 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
3d7553b
build: setup grpc and proto for falco outputs
fntlnz Sep 2, 2019
ec5f974
new(userspace/falco): falco output protocol definition
fntlnz Sep 2, 2019
0e00fe3
new(userspace/falco): initial grpc server implementation
fntlnz Sep 2, 2019
400c1be
update(userspace/falco): mvoing proto enum defs outside
leodido Sep 3, 2019
bbb3936
new(userspace/falco): grpc context and stream context
leodido Sep 3, 2019
413701e
update(userspace/falco): reorganize grpc server
leodido Sep 3, 2019
b454f49
update(userspace/falco): change the way the grpc server is started
leodido Sep 3, 2019
54906e8
build(userspace/falco): add grpc context impl to cmake
leodido Sep 3, 2019
81beee7
fix(userspace/falco): service name for the proto falco output svc
leodido Sep 3, 2019
092dd05
chore(userspace/falco): grpc context format
leodido Sep 3, 2019
8d0336a
chore(userspace/falco): rename grpc server into falco grpc server
leodido Sep 3, 2019
183e92c
new(userspace/falco): introduce request context base and request stre…
leodido Sep 3, 2019
d80ac96
new(usperspace/falco): request stream context specialization and proc…
leodido Sep 3, 2019
a563b1c
new(userspace/falco): request stream context process and end handling
leodido Sep 3, 2019
6d61ca5
new(userspace/falco): falco outputs grpc server stop
leodido Sep 3, 2019
3e1f48d
fix: grpc service must be registered and grpc context state must be h…
leodido Sep 3, 2019
cb5c5c5
chore(userspace/falco): gRPC server send rule and source
leodido Sep 4, 2019
7015b68
new(userspace/falco): grpc server event bus queue
fntlnz Sep 4, 2019
b601d14
new(userspace/falco): initial grpc queuing logic
fntlnz Sep 4, 2019
318b039
update(userspace/falco): keep the stream open
fntlnz Sep 5, 2019
440772c
new(userspace/falco): subscribe keepalive parameter
fntlnz Sep 5, 2019
b124b74
new(userspace/falco): handle subscribe events as streams based on kee…
fntlnz Sep 5, 2019
640bb3f
new(userspace/falco): specify that we can have multiple client consum…
fntlnz Sep 5, 2019
4898a1f
build(userspace/falco): prepare grpc server implementation to be moved
leodido Sep 6, 2019
e281d17
chore(usperspace/falco): move grpc server impl
leodido Sep 6, 2019
004fa3b
new: falco config for grpc server and outputs
leodido Sep 6, 2019
08c8aed
update(userspace/falco): grab grpc output configuration
leodido Sep 6, 2019
b531e0c
new(userspace/falco): introducing concurrent queue for falco outputs
leodido Sep 6, 2019
870f147
update(userspace/falco): remove format from grpc responses
leodido Sep 6, 2019
76757c5
update(userspace/falco/lua): separate events output from messages out…
leodido Sep 6, 2019
d2753bc
update(userspace/falco): use concurrent output queue in grpc server impl
leodido Sep 6, 2019
fcea8ff
update(userspace/falco): use concurrent output queue in grpc server
leodido Sep 6, 2019
ce29da5
chore(userspace/falco): cleanup boot logic for grpc server
leodido Sep 6, 2019
642ca7c
new(userspace/falco): falco output handler to send events via grpc
leodido Sep 6, 2019
54089cf
new(userspace/falco): implement the output queue methods directly
fntlnz Sep 6, 2019
29c3922
new(userspace/falco): send rule and message only for now
fntlnz Sep 6, 2019
14fe085
new(userspace/falco): context metadata
leodido Sep 11, 2019
ced2639
new(userspace/engine): expose resolve_tokens to lua
fntlnz Sep 12, 2019
de949aa
new(userspace/falco): read output_fields from a lua table
fntlnz Sep 12, 2019
fa7c639
update(userspace/falco/lua): passing format to resolve output fields
fntlnz Sep 12, 2019
2342dff
update(usersoace/falco): allow aliases for enum types
leodido Sep 13, 2019
c968aa4
update(userspace/falco): namespace the proto messages and types
leodido Sep 13, 2019
e1cf6b5
update(userspace/falco/lua): no need to pass priority num
leodido Sep 13, 2019
e5d4c37
chore(userspace/falco): use the falco grpc output namespace
leodido Sep 13, 2019
fd0c2b4
new(userspace/falco): transmit output priorities
leodido Sep 13, 2019
ac4ab6b
new(usespace/falco): transmit output sources
leodido Sep 13, 2019
b4d9cd3
new(userspace/falco): check lua data when handling gRPC
leodido Sep 13, 2019
0e022dc
update(userspace/falco): remove id from falco output proto
leodido Sep 13, 2019
87aeca5
new(userspace/falco): trasmit output event timestamp over gRPC
leodido Sep 13, 2019
28a77c7
build: use secure GRPC_LIB and GRPCPP_LIB
leodido Sep 13, 2019
285a8b9
new(userspace/falco): grpc ssl server credentials
leodido Sep 13, 2019
f276413
new(userspace/falco): handle SIGHUP and SIGINT in the main process no…
leodido Sep 16, 2019
47c8722
new(userspace/falco): store context metadata for future usage
leodido Sep 16, 2019
9b36aa6
new: grpc server threadiness config
leodido Sep 16, 2019
48419e2
new: grpc server certificates config
leodido Sep 16, 2019
90d9b3a
new(userspace/falco): read all the gRPC server configs
leodido Sep 16, 2019
8c06e87
new(userspace/falco): shutdown method for grpc server
leodido Sep 16, 2019
bb012af
fix(userspace/falco): correcly log SIGINT handling (fixes #791)
leodido Sep 16, 2019
ef460b8
fix(userspace/falco): handle grpc server thread stop gracefully
leodido Sep 16, 2019
c2cd57d
update: grpc server disabled by default
leodido Sep 16, 2019
f412a6b
new(userspace/falco): config certificates for the gRPC server
leodido Sep 16, 2019
5542b60
chore: typos and miscellanea
leodido Sep 16, 2019
57ae5f0
update(userspace/engine): resolve token
leodido Sep 17, 2019
a937484
fix(userspace/falco): grpc server implementation subscribe handle out…
fntlnz Sep 19, 2019
6f3698c
new(userspace/engine): json event to map type
leodido Sep 23, 2019
99bc5b4
fix(userspace/falco): distinguish between sinsp and json events when …
leodido Sep 23, 2019
356e143
fix(userspace/falco): pop output fields lua table and correctly check…
leodido Sep 23, 2019
8d50c80
new(userspace/falco): utils file definition with read function
fntlnz Sep 24, 2019
c446659
new(userspace/falco): namespace for falco grpc
fntlnz Sep 24, 2019
65fb36d
update(userspace/falco): falco_grpc_server is now just server
fntlnz Sep 24, 2019
92391f1
chore(userspace/falco): better organization of schema and grpc server
fntlnz Sep 24, 2019
dee2a2b
chore(userspace/falco): we don't support tags yet
fntlnz Sep 24, 2019
6e47f58
update(userspace/falco): specify go packages into protobuf
leodido Sep 24, 2019
f4f3556
docs(userspace/falco): document output proto messages and service
leodido Sep 25, 2019
f0e7a2f
chore(userspace): addressing review comments and typos
leodido Sep 25, 2019
e2bb1e4
docs: document gRPC server and gRPC output service config options
leodido Sep 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ else()
set(GRPC_SRC "${PROJECT_BINARY_DIR}/grpc-prefix/src/grpc")
message(STATUS "Using bundled grpc in '${GRPC_SRC}'")
set(GRPC_INCLUDE "${GRPC_SRC}/include")
set(GRPC_LIB "${GRPC_SRC}/libs/opt/libgrpc_unsecure.a")
set(GRPCPP_LIB "${GRPC_SRC}/libs/opt/libgrpc++_unsecure.a")
set(GRPC_LIB "${GRPC_SRC}/libs/opt/libgrpc.a")
set(GRPCPP_LIB "${GRPC_SRC}/libs/opt/libgrpc++.a")
set(GRPC_CPP_PLUGIN "${GRPC_SRC}/bins/opt/grpc_cpp_plugin")

get_filename_component(PROTOC_DIR ${PROTOC} DIRECTORY)
Expand Down
21 changes: 20 additions & 1 deletion falco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,23 @@ program_output:

http_output:
enabled: false
url: http://some.url
url: http://some.url

# gRPC server configuration.
# The gRPC server is secure by default (mutual TLS) so you need to generate certificates and update their paths here.
# By default the gRPC server is off.
# You can configure the address to bind and expose it.
# By modifying the threadiness configuration you can fine-tune the number of threads (and context) it will use.
grpc:
enabled: false
bind_address: "0.0.0.0:5060"
threadiness: 8
private_key: "/etc/falco/certs/server.key"
cert_chain: "/etc/falco/certs/server.crt"
root_certs: "/etc/falco/certs/ca.crt"

# gRPC output service.
# By default it is off.
# By enabling this all the output events will be kept in memory until you read them with a gRPC client.
grpc_output:
leodido marked this conversation as resolved.
Show resolved Hide resolved
enabled: false
2 changes: 1 addition & 1 deletion userspace/engine/falco_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class falco_common

void set_inspector(sinsp *inspector);

// Priority levels, as a vector of strings
// Priority levels, as a vector of strings
static std::vector<std::string> priority_names;

// Same as numbers/indices into the above vector
Expand Down
38 changes: 37 additions & 1 deletion userspace/engine/formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
#include <json/json.h>

#include "formats.h"
#include "logger.h"
#include "falco_engine.h"


Expand All @@ -36,6 +35,7 @@ const static struct luaL_reg ll_falco [] =
{"free_formatter", &falco_formats::free_formatter},
{"free_formatters", &falco_formats::free_formatters},
{"format_event", &falco_formats::format_event},
{"resolve_tokens", &falco_formats::resolve_tokens},
{NULL,NULL}
};

Expand Down Expand Up @@ -265,3 +265,39 @@ int falco_formats::format_event (lua_State *ls)
return 1;
}

int falco_formats::resolve_tokens(lua_State *ls)
{
if(!lua_isstring(ls, -1) ||
!lua_isstring(ls, -2) ||
!lua_islightuserdata(ls, -3))
{
lua_pushstring(ls, "Invalid arguments passed to resolve_tokens()");
lua_error(ls);
}
gen_event *evt = (gen_event *)lua_topointer(ls, 1);
string source = luaL_checkstring(ls, 2);
const char *format = (char *)lua_tostring(ls, 3);
string sformat = format;

leodido marked this conversation as resolved.
Show resolved Hide resolved
map<string, string> values;
if(source == "syscall")
{
s_formatters->resolve_tokens((sinsp_evt *)evt, sformat, values);
}
// k8s_audit
else
{
json_event_formatter json_formatter(s_engine->json_factory(), sformat);
values = json_formatter.tomap((json_event*) evt);
}

lua_newtable(ls);
for(auto const& v : values)
{
lua_pushstring(ls, v.first.c_str());
lua_pushstring(ls, v.second.c_str());
lua_settable(ls, -3);
}

return 1;
}
3 changes: 3 additions & 0 deletions userspace/engine/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class falco_formats
// formatted_string = falco.format_event(evt, formatter)
static int format_event(lua_State *ls);

// resolve_tokens = falco.resolve_tokens(evt, formatter)
static int resolve_tokens(lua_State *ls);

static sinsp* s_inspector;
static falco_engine *s_engine;
static sinsp_evt_formatter_cache *s_formatters;
Expand Down
25 changes: 25 additions & 0 deletions userspace/engine/json_evt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ std::string json_event_formatter::tostring(json_event *ev)
std::string json_event_formatter::tojson(json_event *ev)
{
nlohmann::json ret;
// todo(leodido, fntlnz) > assign tomap() result to ret (implicit conversion using = operator)

std::list<std::pair<std::string, std::string>> resolved;

Expand All @@ -806,13 +807,37 @@ std::string json_event_formatter::tojson(json_event *ev)
// Only include the fields and not the raw text blocks.
if(!res.first.empty())
{
// todo(leodido, fntlnz) > do we want "<NA>" rather than empty res.second values?
ret[res.first] = res.second;
}
}

return ret.dump();
}

std::map<std::string, std::string> json_event_formatter::tomap(json_event *ev)
{
std::map<std::string, std::string> ret;
std::list<std::pair<std::string, std::string>> res;

resolve_tokens(ev, res);

for(auto &r : res)
{
// Only include the fields and not the raw text blocks.
if(!r.first.empty())
{
if(r.second.empty())
{
r.second = "<NA>";
}
ret.insert(r);
}
}

return ret;
}

void json_event_formatter::parse_format()
{
string tformat = m_format;
Expand Down
1 change: 1 addition & 0 deletions userspace/engine/json_evt.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class json_event_formatter

std::string tostring(json_event *ev);
std::string tojson(json_event *ev);
std::map<std::string, std::string> tomap(json_event *ev);

void resolve_tokens(json_event *ev, std::list<std::pair<std::string,std::string>> &resolved);

Expand Down
29 changes: 28 additions & 1 deletion userspace/falco/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ endif()

configure_file("${SYSDIG_DIR}/userspace/sysdig/config_sysdig.h.in" config_sysdig.h)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/output.grpc.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/output.grpc.pb.h
${CMAKE_CURRENT_BINARY_DIR}/output.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/output.pb.h
${CMAKE_CURRENT_BINARY_DIR}/schema.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/schema.pb.h
COMMENT "Generate gRPC code"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/output.proto
COMMAND ${PROTOC} -I ${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=. ${CMAKE_CURRENT_SOURCE_DIR}/output.proto ${CMAKE_CURRENT_SOURCE_DIR}/schema.proto
COMMAND ${PROTOC} -I ${CMAKE_CURRENT_SOURCE_DIR} --grpc_out=. --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} ${CMAKE_CURRENT_SOURCE_DIR}/output.proto
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

add_executable(falco
configuration.cpp
logger.cpp
Expand All @@ -29,7 +41,14 @@ add_executable(falco
statsfilewriter.cpp
falco.cpp
"${SYSDIG_DIR}/userspace/sysdig/fields_info.cpp"
webserver.cpp)
webserver.cpp
grpc_context.cpp
grpc_server_impl.cpp
grpc_server.cpp
utils.cpp
${CMAKE_CURRENT_BINARY_DIR}/output.grpc.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/output.pb.cc
${CMAKE_CURRENT_BINARY_DIR}/schema.pb.cc)

target_include_directories(falco PUBLIC
"${SYSDIG_DIR}/userspace/sysdig"
Expand All @@ -38,10 +57,18 @@ target_include_directories(falco PUBLIC
"${PROJECT_BINARY_DIR}/driver/src"
"${YAMLCPP_INCLUDE_DIR}"
"${CIVETWEB_INCLUDE_DIR}"
"${GRPC_INCLUDE}"
"${PROTOBUF_INCLUDE}"
"${CMAKE_CURRENT_BINARY_DIR}"
"${DRAIOS_DEPENDENCIES_DIR}/yaml-${DRAIOS_YAML_VERSION}/target/include")



target_link_libraries(falco falco_engine sinsp)
target_link_libraries(falco
"${GRPCPP_LIB}"
"${GRPC_LIB}"
"${PROTOBUF_LIB}"
"${LIBYAML_LIB}"
"${YAMLCPP_LIB}"
"${CIVETWEB_LIB}")
Expand Down
Loading