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

[Elasticsearch] Add APIKey configuration for Elasticsearch output #980

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

aleksmaus
Copy link
Contributor

@aleksmaus aleksmaus commented Aug 29, 2024

What type of PR is this?

/kind feature

Any specific area of the project related to this PR?

/area outputs

What this PR does / why we need it:

Adds APIKey configuration for Elasticsearch output

APIKey is a preferred way to authenticated with Elasticsearch, since users can limit it's permissions, assign the expiration, revoke, etc.
Screenshot 2024-08-29 at 1 45 25 PM

Currently user can configure it with the customHeaders, for example:

customHeaders:
    Authorization: "APIKey U1Nfd041RUJKMGlDdzFGeld0anE6aHR2Z0kwbmNUcDZITxxxxxxxxxxxx=="

Exposing APIKey through a dedicated configuration option would hopefully encourage and make easier for users to use APIKey instead of basic auth.

Special notes for your reviewer:
Good convenience configuration option

Signed-off-by: Aleksandr Maus <aleksandr.maus@elastic.co>
@Issif Issif added this to the 2.30 milestone Aug 29, 2024
Comment on lines +108 to 114
if c.Config.Elasticsearch.ApiKey != "" {
req.Header.Set("Authorization", "APIKey "+c.Config.Elasticsearch.ApiKey)
}

if c.Config.Elasticsearch.Username != "" && c.Config.Elasticsearch.Password != "" {
req.SetBasicAuth(c.Config.Elasticsearch.Username, c.Config.Elasticsearch.Password)
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we not make them exclusive? APIKey or Username + Password but not both?

Copy link
Contributor Author

@aleksmaus aleksmaus Aug 30, 2024

Choose a reason for hiding this comment

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

I was thinking about this.

The original implementation of setting the headers
https://github.com/falcosecurity/falcosidekick/blob/2.29.0/outputs/elasticsearch.go#L62
allowed the custom headers to overwrite the basic auth header. Effectively users could set the username and password in the configuration and then add "Authorization" header to the customHeaders and overwrite that header. It is a subtle detail, but it is the current behavior.
So I decided to follow the same behavior here, the headers are just applied in order, and not trying to figure out if the header is already set or not.

What is going to happen in this case: if the user has both apikey and the username and password in the configuration, the username and password will overwrite the "Authorization" header here:
https://github.com/golang/go/blob/ffb3e574012ce9d3d5193d7b8df135189b8a6671/src/net/http/request.go#L1023
thus will end up using basic auth.

Let me know if you still want to change.
And if we change, should we apply the custom headers before auth or after? They were applied after authorization header before (and now still). If we continue to apply them after, should we check if the "Authorization" header was already set or let the user overwrite it if they want? If we let the user to overwrite, we might as well keep the implementation as already is.

Copy link
Member

Choose a reason for hiding this comment

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

It's ok to me to keep the behavior like it is. Thanks

@poiana
Copy link

poiana commented Aug 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aleksmaus, Issif

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
Copy link

poiana commented Aug 30, 2024

LGTM label has been added.

Git tree hash: f3e2dcc027e1d6315fbbcbae3c0b6fdf0ce48c99

@poiana poiana merged commit a9dfe9b into falcosecurity:master Aug 30, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants