Skip to content

Commit 69b7f26

Browse files
committed
out_splunk: fix metadata hec_token bug that overrides default splunk_token behavior (fix #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 <[email protected]>
1 parent c4d6803 commit 69b7f26

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

plugins/out_splunk/splunk.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,11 @@ static flb_sds_t get_metadata_auth_header(struct flb_splunk *ctx)
400400
flb_sds_t auth_header = NULL;
401401

402402
pthread_mutex_lock(&ctx->mutex_hec_token);
403-
auth_header = flb_sds_create(ctx->metadata_auth_header);
403+
404+
if (ctx->metadata_auth_header) {
405+
auth_header = flb_sds_create(ctx->metadata_auth_header);
406+
}
407+
404408
pthread_mutex_unlock(&ctx->mutex_hec_token);
405409

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

720-
/* Try to use http_user and http_passwd if not, fallback to auth_header */
724+
/*
725+
* Authentication mechanism & order:
726+
*
727+
* 1. use the configure `http_user` and `http_passwd`
728+
* 2. use metadata 'hec_token', if the records are generated by Splunk input plugin, this will be set.
729+
* 3. use the configured `splunk_token` (if set).
730+
*/
721731
if (ctx->http_user && ctx->http_passwd) {
722732
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
723733
}

plugins/out_splunk/splunk_conf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ struct flb_splunk *flb_splunk_conf_create(struct flb_output_instance *ins,
241241
}
242242

243243
ctx->metadata_auth_header = NULL;
244+
244245
/* No http_user is set, fallback to splunk_token, if splunk_token is unset, fail. */
245246
if (!ctx->http_user) {
246247
/* Splunk Auth Token */

0 commit comments

Comments
 (0)