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

[feature] Ability to set user-agent variable for http_output #1850

Merged
merged 3 commits into from
Jan 18, 2022

Conversation

yoshi314
Copy link
Contributor

@yoshi314 yoshi314 commented Jan 12, 2022

/kind feature

/area engine

What this PR does / why we need it:

This allows to identify falco's datastream sent via http_output on the receiving end.

In my particular case that is logstash with its http listener.

Since I have multiple processes submitting via http from the same machine, I need a way to distinguish falco's events from other incoming data streams for further parsing and processing.

Which issue(s) this PR fixes:

Fixes #1831

Does this PR introduce a user-facing change?:

A config entry of user_agent: "some string" is now supported under http_output. If not provided, the value defaults to "falcosecurity/falco".

Setting it to "" ought to restore previous behaviour (that field appears to be present in http headers, but with blank value).

new: add ability to set User-Agent http header when sending http output. Provide default value of 'falcosecurit/falco'.

Signed-off-by: Marcin Kowalski <marcin.kowalski@assecobs.pl>
@poiana
Copy link
Contributor

poiana commented Jan 12, 2022

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

@@ -34,11 +34,14 @@ void falco::outputs::output_http::output(const message *msg)
} else {
slist1 = curl_slist_append(slist1, "Content-Type: text/plain");
}
slist1 = curl_slist_append(slist1, m_oc.options["user_agent"].c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

Spacing :)

@FedeDP
Copy link
Contributor

FedeDP commented Jan 12, 2022

Hi! Thank you for opening this PR!
This is very useful IMO!
Note that all your commits must be signed with dco, see https://github.com/falcosecurity/.github/blob/master/CONTRIBUTING.md#developer-certificate-of-origin.
Moreover, commits message must obey to conventional commits: https://github.com/falcosecurity/.github/blob/master/CONTRIBUTING.md#commit-convention

It would be great if you could force-push with these changes in place!

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

Apart from a single (small) comment, LGTM!
Thanks!

@jasondellaluce
Copy link
Contributor

On top of @FedeDP's comments, I would also add an http_output.user_agent in falco.yaml too for better visibility.

@yoshi314
Copy link
Contributor Author

ok, i'll see to it later today. Now trying to figure out how to sign the past commits.

@FedeDP
Copy link
Contributor

FedeDP commented Jan 12, 2022

Hi!
It is just as simple as rebasing interactively latest N commits (2 in your case) and add the "Signed-off-by ..." bit to each commit message :)
Then, force-push!

@yoshi314 yoshi314 force-pushed the useragent_variable_2 branch from 22418d2 to 14d11b9 Compare January 13, 2022 09:18
@yoshi314
Copy link
Contributor Author

I hope that fixed it. Also, what exactly is that remark with spacing about? A case of tabs/spaces or something else?

@jasondellaluce
Copy link
Contributor

Yeah, it looks like it worked (You can see your sign-off on the commit message).

The spacing issue seems to be that outputs_http.cpp uses tabs for indentation, whereas the new changes use spacing. If you can fix that, and also add an entry for the new config field in falco.yaml, I would proceed and approve!

@yoshi314
Copy link
Contributor Author

It appears vim can be deceiving with indentation. Should be fixed now.

add sample config entry for user-agent variable

Signed-off-by: Marcin Kowalski <marcin.kowalski@assecobs.pl>
@poiana poiana added size/S and removed size/XS labels Jan 13, 2022
@@ -34,11 +34,14 @@ void falco::outputs::output_http::output(const message *msg)
} else {
slist1 = curl_slist_append(slist1, "Content-Type: text/plain");
}
slist1 = curl_slist_append(slist1, m_oc.options["user_agent"].c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

By testing it locally, I was not able to get the user agent header (but maybe it was me). Either way, not setting the user-agent: prefix properly would result in an invalid header I think. Would it be better to use this instead?

curl_easy_setopt(curl, CURLOPT_USERAGENT, m_oc.options["user_agent"].c_str());

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'll have to retest this in my setup. I was pretty sure that worked on my case, when checking logs on remote end.

Copy link
Contributor Author

@yoshi314 yoshi314 Jan 13, 2022

Choose a reason for hiding this comment

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

Oh, i think i missd the "User-Agent:" string from the header, since i used a predefined string before.

So now it only passes the variable without that prefix.

yeah, your proposal looks better. I'll try to go with that. Somehow i missed this option.

@jasondellaluce
Copy link
Contributor

@yoshi314 new changes look good. Please sign-off the last commit and we should be good to go!

@yoshi314 yoshi314 force-pushed the useragent_variable_2 branch from 9491557 to 278defd Compare January 14, 2022 06:54
…itched to dedicated curl's method to do this

Signed-off-by: Marcin Kowalski <marcin.kowalski@assecobs.pl>
Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

/approve

Thanks for your contribution! 🥳

@poiana poiana added the lgtm label Jan 14, 2022
@poiana
Copy link
Contributor

poiana commented Jan 14, 2022

LGTM label has been added.

Git tree hash: c2fb4965c77ef5daef745b789eef6fb297c7e6ed

@leogr
Copy link
Member

leogr commented Jan 17, 2022

/milestone 0.31.0

@poiana poiana added this to the 0.31.0 milestone Jan 17, 2022
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

LGTM

@yoshi314 thank you for this PR!

/approve

@poiana
Copy link
Contributor

poiana commented Jan 18, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jasondellaluce, leogr, yoshi314

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:
  • OWNERS [jasondellaluce,leogr]

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 a9e7512 into falcosecurity:master Jan 18, 2022
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.

Ability to customize falco's http_output for logstash http input plugin.
5 participants