-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
out_http: Add AWS SigV4 Authentication Option to out_http #5165
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,13 @@ | |
#include <fluent-bit/flb_gzip.h> | ||
#include <msgpack.h> | ||
|
||
#ifdef FLB_HAVE_SIGNV4 | ||
#ifdef FLB_HAVE_AWS | ||
#include <fluent-bit/flb_aws_credentials.h> | ||
#include <fluent-bit/flb_signv4.h> | ||
#endif | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
|
@@ -79,6 +86,7 @@ static int http_post(struct flb_out_http *ctx, | |
struct flb_config_map_val *mv; | ||
struct flb_slist_entry *key = NULL; | ||
struct flb_slist_entry *val = NULL; | ||
flb_sds_t signature = NULL; | ||
|
||
/* Get upstream context and connection */ | ||
u = ctx->u; | ||
|
@@ -174,6 +182,30 @@ static int http_post(struct flb_out_http *ctx, | |
val->str, flb_sds_len(val->str)); | ||
} | ||
|
||
#ifdef FLB_HAVE_SIGNV4 | ||
#ifdef FLB_HAVE_AWS | ||
/* AWS SigV4 headers */ | ||
if (ctx->has_aws_auth == FLB_TRUE) { | ||
flb_plg_debug(ctx->ins, "signing request with AWS Sigv4"); | ||
signature = flb_signv4_do(c, | ||
FLB_TRUE, /* normalize URI ? */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are the question mark for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a boolean |
||
FLB_TRUE, /* add x-amz-date header ? */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Booleans. Actually copied this comment from other plugins |
||
time(NULL), | ||
(char *) ctx->aws_region, | ||
(char *) ctx->aws_service, | ||
0, | ||
ctx->aws_provider); | ||
|
||
if (!signature) { | ||
flb_plg_error(ctx->ins, "could not sign request with sigv4"); | ||
out_ret = FLB_RETRY; | ||
goto cleanup; | ||
} | ||
flb_sds_destroy(signature); | ||
} | ||
#endif | ||
#endif | ||
|
||
ret = flb_http_do(c, &b_sent); | ||
if (ret == 0) { | ||
/* | ||
|
@@ -220,6 +252,7 @@ static int http_post(struct flb_out_http *ctx, | |
out_ret = FLB_RETRY; | ||
} | ||
|
||
cleanup: | ||
/* | ||
* If the payload buffer is different than incoming records in body, means | ||
* we generated a different payload and must be freed. | ||
|
@@ -377,6 +410,21 @@ static struct flb_config_map config_map[] = { | |
0, FLB_TRUE, offsetof(struct flb_out_http, http_passwd), | ||
"Set HTTP auth password" | ||
}, | ||
#ifdef FLB_HAVE_SIGNV4 | ||
#ifdef FLB_HAVE_AWS | ||
{ | ||
FLB_CONFIG_MAP_BOOL, "aws_auth", "false", | ||
0, FLB_TRUE, offsetof(struct flb_out_http, has_aws_auth), | ||
"Enable AWS SigV4 authentication" | ||
}, | ||
{ | ||
FLB_CONFIG_MAP_STR, "aws_service", NULL, | ||
0, FLB_TRUE, offsetof(struct flb_out_http, aws_service), | ||
"AWS destination service code, used by SigV4 authentication" | ||
}, | ||
FLB_AWS_CREDENTIAL_BASE_CONFIG_MAP(FLB_HTTP_AWS_CREDENTIAL_PREFIX), | ||
#endif | ||
#endif | ||
{ | ||
FLB_CONFIG_MAP_STR, "header_tag", NULL, | ||
0, FLB_TRUE, offsetof(struct flb_out_http, header_tag), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm this is only used by the new
flb_managed_chain_provider_create
function to use? the other providers don't use these new fields I guess?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. It's just if we want aws_provider_destroy to handle clean up operations. If null (due to calloc) clean up will not occur