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

feat: add hostname field in gRPC output #927

Merged
merged 5 commits into from Nov 27, 2019
Merged

feat: add hostname field in gRPC output #927

merged 5 commits into from Nov 27, 2019

Conversation

aarroyoc
Copy link
Contributor

@aarroyoc aarroyoc commented Nov 18, 2019

Signed-off-by: Adrián Arroyo Calle adrian.arroyocalle@gmail.com

What type of PR is this?

/kind feature

Any specific area of the project related to this PR?

/area integrations

What this PR does / why we need it:

This PR adds a new field (hostname) in gRPC event messages.

Which issue(s) this PR fixes:

Fixes #923

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

In theory, it adds a new field without causing trouble to old clients. It also passes hostname to other outputs but it does nothing. This was done to keep consistency between methods signatures. Maybe we want to move the field to outputFields

update: adds a hostname field to gRPC output

Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
@poiana
Copy link

poiana commented Nov 18, 2019

Welcome @aarroyoc! It looks like this is your first PR to falcosecurity/falco 🎉

Copy link
Contributor

@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.

@aarroyoc - this PR looks very good overall and this had also been a very needed feature in the community so thanks a lot for this!

I find this PR complete overall, I only want to see if we can do differently for the hostname, see my comment below.

@@ -146,6 +146,12 @@ void falco_outputs::handle_event(gen_event *ev, string &rule, string &source,

std::lock_guard<std::mutex> guard(m_ls_semaphore);
lua_getglobal(m_ls, m_lua_output_event.c_str());
char hostname[1024];
int err = gethostname(hostname, sizeof(hostname));
Copy link
Contributor

Choose a reason for hiding this comment

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

While this might be good for most use cases, imagine this scenario.

You run this as a Daemonset on Kubernetes.

Then you consume the outputs somewhere else and try to get the hostname.

You notice that you are getting the hostname of the container and not the one of the node.

My proposed solution, is to create a new environment variable for the hostname. Then we read that environment variable and if it's not present we get the system hostname.

In that way, when deploying in kubernetes we can just go and do something like this in the Pod spec:

...
      containers:
        - name: falco
          image: falcosecurity/falco:latest
          env:
            - name: FALCO_GRPC_HOSTNAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
...

Please note that FALCO_GRPC_HOSTNAME is just a filler idea I had for the variable name, I'm totally unsure what name to pick !

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 updated the PR to reflect that change

Copy link
Member

Choose a reason for hiding this comment

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

Let's merge the functionality then we can pick battle on names (I really like such battles Lorenzo knows ahaha).

Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
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.

Ok changes go in the correct direction. Nevertheless the env variable should be setup in another place. Also I would be prefer to use safer version of strcpy.

Finally there is a typo in your last commit message (253 rather than 256?) probably.

Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
@palmerabollo
Copy link
Contributor

Hi @leodido, thanks for your feedback. Could you please point us to a better place to setup the env var? Thanks!

int err = gethostname(c_hostname, 256);
if(err != 0){
string err = "Failed to get hostname";
throw falco_exception(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can pass the error string directly here

@fntlnz
Copy link
Contributor

fntlnz commented Nov 21, 2019

@palmerabollo @aarroyoc - the environment variable setup is all done in falco.cpp - see what we do with the k8s api env variable for example here: https://github.com/falcosecurity/falco/blob/dev/userspace/falco/falco.cpp#L1112-L1116

Once you have that, we have two options:

  • pass it as a member when creating falco_outputs
  • pass it to do_inspect so that when it comes to call handle_event we can give the information to the outputs.

Wdyt?

Signed-off-by: Adrián Arroyo Calle <adrian.arroyocalle@gmail.com>
@aarroyoc
Copy link
Contributor Author

I've added it in falco_outputs because I think it's more of an initialization value

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.

Thanks Adrian for applying the changes requested!

This seems pretty good to me! 🎉

There is only one nitpick: not sure we should throw falco_exception there. But to be fair I think that all the exceptions/errors should be reviewed and that's not the scope of this PR. So let's merge this! :)

@poiana
Copy link

poiana commented Nov 27, 2019

LGTM label has been added.

Git tree hash: 6289fbf7c0d289f6d42887c2638d88a32b13e12d

@palmerabollo
Copy link
Contributor

palmerabollo commented Nov 27, 2019

@fntlnz does it look good to you?

@poiana
Copy link

poiana commented Nov 27, 2019

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fntlnz, 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

@fntlnz
Copy link
Contributor

fntlnz commented Nov 27, 2019

Looks good! Thanks @aarroyoc for the pr and for makin the requested changes ! This is a very needed and cool improvement ! Merging !

@fntlnz fntlnz merged commit 1b05f0e into falcosecurity:dev Nov 27, 2019
@fntlnz
Copy link
Contributor

fntlnz commented Nov 27, 2019

/milestone 0.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the node metadata in the Falco outputs API
5 participants