Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Update grpc #36

Merged
merged 8 commits into from
Aug 19, 2020
Merged

Update grpc #36

merged 8 commits into from
Aug 19, 2020

Conversation

nibalizer
Copy link
Contributor

@nibalizer nibalizer commented Jul 7, 2020

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind documentation

/kind tests

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area api

/area client
/area grpc

/area examples

/area build

What this PR does / why we need it:

A few things in here:

  • Cleanup build/package so it can pip install .
  • Add unix socket grpc support
  • Update protos for existing protos
  • Add proto for version proto

Which issue(s) this PR fixes:

Fixes #35
Fixes #34
Fixes #25

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

The bi-directional api is different from the single direction api and uses different verbs.
client.subscribe is removed and replaced with client.sub. 
There is no need to pass keepalive=True anywhere.
client.get() will pull any events in-memory up to the point when the function is called.
client.version() will get the falco version from the server.

Also futz with build system

Signed-off-by: Spencer Krum <nibz@spencerkrum.com>
Signed-off-by: Spencer Krum <nibz@spencerkrum.com>
Signed-off-by: Spencer Krum <nibz@spencerkrum.com>
Signed-off-by: Spencer Krum <nibz@spencerkrum.com>
@nibalizer
Copy link
Contributor Author

nibalizer commented Jul 7, 2020

I'm still working on this

/hold

@nibalizer nibalizer marked this pull request as draft July 7, 2020 17:54
falco/client.py Outdated Show resolved Hide resolved
falco/client.py Show resolved Hide resolved
@nibalizer
Copy link
Contributor Author

/hold cancel

@nibalizer
Copy link
Contributor Author

@leodido @mmat11 I believe this is ready for review now. Thanks in advance!

@nibalizer nibalizer marked this pull request as ready for review July 28, 2020 19:51
pass

def EmptyRequests(self):
while True:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen examples where they put a sleep here.

After code review from  @mmatt11

Also other misc fixes and an example.

Signed-off-by: Spencer Krum <nibz@spencerkrum.com>
Signed-off-by: Spencer Krum <nibz@spencerkrum.com>
class TLSConfigError(Exception):
pass

class RequestGenerator:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be a function (and should belong to the outputs domain model)

falco/client.py Outdated Show resolved Hide resolved
from falco.domain import Response, Request
from falco.svc.outputs_pb2_grpc import serviceStub
from falco.svc.version_pb2_grpc import serviceStub as versionServiceStub
from falco.schema.version_pb2 import request as versionRequest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion the Client should only use domain models

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a stab at the refactor you're suggesting and got pretty confused. Would you be willing to throw a patch together to move the code into the domain model?

falco/client.py Outdated Show resolved Hide resolved
falco/client.py Outdated Show resolved Hide resolved

def __repr__(self):
return f"{self.__class__.__name__}(keepalive={self.keepalive})"
__slots__ = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably it's the same but maybe we should use a tuple here

@@ -1,27 +1,12 @@
import pytest

from falco import Request
from output_pb2 import request
from outputs_pb2 import request


class TestRequest:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test doesn't have a purpose anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this doesn't have a purpose anymore.

Anyway, I'd leave it here for now for when we'll have fields into the request messages (eg., rule/alerts tags)

@mmat11
Copy link
Contributor

mmat11 commented Aug 5, 2020

We don't have a release process yet but probably we should still bump the version number here -> https://github.com/falcosecurity/client-py/blob/master/falco/__version__.py#L4

@nibalizer
Copy link
Contributor Author

Thanks @mmat11 ! I'll get to these.

fntlnz
fntlnz previously approved these changes Aug 18, 2020
Copy link

@fntlnz fntlnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this and works like a charm.
I don't have merge powers on this repo so just take my approve as a sign of appreciation for this work!

@poiana
Copy link

poiana commented Aug 18, 2020

LGTM label has been added.

Git tree hash: 089d3800857f2a9e8044eb1c93f6529d8727b657

Makefile Show resolved Hide resolved
Copy link
Member

@leodido leodido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

Congrats for this awesome work @nibalizer 🤗

Left a comment about max_receive_message_length grpc option.

Could you update the release-note block to match the conventions, please?

if endpoint.startswith("unix:///"):
channel = grpc.insecure_channel(
endpoint,
options=[("grpc.max_receive_message_length", 1024 * 1024 * 512)],
Copy link
Member

@leodido leodido Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this value for receiving messages exact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copy and pasted from the tls connection below. I didn't find us setting a maximum size in the falco source code to match this with.

@@ -1,27 +1,12 @@
import pytest

from falco import Request
from output_pb2 import request
from outputs_pb2 import request


class TestRequest:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this doesn't have a purpose anymore.

Anyway, I'd leave it here for now for when we'll have fields into the request messages (eg., rule/alerts tags)

nibalizer and others added 2 commits August 18, 2020 20:00
BREAKING CHANGE: removes subscribe method from client and changes all
examples

This normalizes get/sub accross our examples

Signed-off-by: Spencer Krum <nibz@spencerkrum.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>

Co-authored-by: Mattia <mattia@airmail.cc>
@nibalizer
Copy link
Contributor Author

Thanks team for the reviews! I changed what I could. I don't think I can move the code into the domain model that you're asking for @mmat11, I just don't understand it well enough.

Copy link
Member

@leodido leodido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this awesome PR by @nibalizer 🎉

Further refinements can be done in follow-up PRs, imho.

Having this merged in now helps all the people from KubeCon that want to try out the gRPC alerts.

@poiana
Copy link

poiana commented Aug 19, 2020

LGTM label has been added.

Git tree hash: 66ce6ca20405f5c5e9ca38312ebdd816995ae65b

@poiana
Copy link

poiana commented Aug 19, 2020

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: leodido

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit eccdecd into falcosecurity:master Aug 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watch the bidirectional Falco Outputs Support gRPC via unix socket Support the new Falco version API
5 participants