Skip to content

Commit

Permalink
out_splunk: fix metadata hec_token bug that overrides default splunk_…
Browse files Browse the repository at this point in the history
…token behavior (fix fluent#8867)

In the previous Splunk metadata fix, I introduced an issue where the metadata auth header was
always set even if the metadata was not there, the code was generating an emptry string which
leads to skip the classic splunk_token auth mechanism.

This patch corrects the recent bug by validating first and returning a proper NULL when
metadata auth header (hec_token) is not there.

Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
Signed-off-by: Markus Bergholz <git@osuv.de>
  • Loading branch information
edsiper authored and markuman committed May 29, 2024
1 parent 2f9aa33 commit ffcdd21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plugins/out_splunk/splunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,11 @@ static flb_sds_t get_metadata_auth_header(struct flb_splunk *ctx)
flb_sds_t auth_header = NULL;

pthread_mutex_lock(&ctx->mutex_hec_token);
auth_header = flb_sds_create(ctx->metadata_auth_header);

if (ctx->metadata_auth_header) {
auth_header = flb_sds_create(ctx->metadata_auth_header);
}

pthread_mutex_unlock(&ctx->mutex_hec_token);

return auth_header;
Expand Down Expand Up @@ -717,7 +721,13 @@ static void cb_splunk_flush(struct flb_event_chunk *event_chunk,
/* HTTP Client */
flb_http_add_header(c, "User-Agent", 10, "Fluent-Bit", 10);

/* Try to use http_user and http_passwd if not, fallback to auth_header */
/*
* Authentication mechanism & order:
*
* 1. use the configure `http_user` and `http_passwd`
* 2. use metadata 'hec_token', if the records are generated by Splunk input plugin, this will be set.
* 3. use the configured `splunk_token` (if set).
*/
if (ctx->http_user && ctx->http_passwd) {
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
}
Expand Down
1 change: 1 addition & 0 deletions plugins/out_splunk/splunk_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ struct flb_splunk *flb_splunk_conf_create(struct flb_output_instance *ins,
}

ctx->metadata_auth_header = NULL;

/* No http_user is set, fallback to splunk_token, if splunk_token is unset, fail. */
if (!ctx->http_user) {
/* Splunk Auth Token */
Expand Down

0 comments on commit ffcdd21

Please sign in to comment.