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

aws: Adding sts endpoint for CW and ES plugins #2501

Merged
merged 7 commits into from
Sep 28, 2020

Conversation

MeghnaPrabhu
Copy link

@MeghnaPrabhu MeghnaPrabhu commented Aug 25, 2020

  • Added STS endpoint support for CW and ES plugin.

  • Add sts_endpoint option in eks_provider and aws_sts_provider

  • Added support to specify endpoint and sts_endpoint with or without the protocol.

E.g. endpoint logs.us-west-2.amazonaws.com and endpoint https://logs.us-west-2.amazonaws.com will work.

[OUTPUT]
    Name cloudwatch_logs
    Match *
    log_stream_prefix fluent-bit-
    log_group_name fluent
    region us-west-2
    auto_create_group On
    role_arn arn:aws:iam::xxxxxxxxxxxx:role/test
    sts_endpoint https://sts.us-west-2.amazonaws.com
    endpoint logs.us-west-2.amazonaws.com
[OUTPUT]
    Name  es
    Match *
    Host vpc-test-domain-ke7thhzoo7jawrhmz6mb7ite7y.us-west-2.es.amazonaws.com
    Port  443
    Index my_index
    Type  my_type
    Aws_Auth On
    Aws_Region us-west-2
    aws_role_arn arn:aws:iam::xxxxxxxxxxxx:role/test
    aws_sts_endpoint https://sts.us-west-2.amazonaws.com
    tls On
    tls.verify On
    tls.debug 1

Debug Logs

image

image

Valgrind Logs
valgrind_aws_credentials.log
valgrind_aws_credentials_sts.log

Signed-off-by: Meghna Prabhu meghnapr@amazon.com


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

Documentation

  • Documentation required for this feature

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

{
FLB_CONFIG_MAP_STR, "aws_sts_endpoint", "",
0, FLB_TRUE, offsetof(struct flb_elasticsearch, aws_sts_endpoint),
"STS endpoint"
Copy link
Contributor

Choose a reason for hiding this comment

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

Description should be longer. Like: "Custom endpoint for the AWS STS API, used with the AWS_Role_ARN option"

Copy link
Contributor

@PettitWesley PettitWesley Aug 25, 2020

Choose a reason for hiding this comment

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

Also, since STS endpoint only makes sense if aws_role_arn is also specified, add a check for that. If aws_sts_endpoint is present without role_arn, print an error message

{
FLB_CONFIG_MAP_STR, "sts_endpoint", NULL,
0, FLB_FALSE, 0,
"Specify a custom sts endpoint for the CloudWatch Logs API"
Copy link
Contributor

Choose a reason for hiding this comment

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

"Specify a custom endpoint for the STS API, can be used with the role_arn parameter"

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, since STS endpoint only makes sense if role_arn is also specified, add a check for that. If sts_endpoint is present without role_arn, print and error message

@MeghnaPrabhu MeghnaPrabhu force-pushed the aws_sts_endpoint branch 3 times, most recently from 6378413 to 3636223 Compare August 26, 2020 01:18
}

if (ctx->sts_endpoint && !ctx->role_arn) {
flb_plg_error(ctx->ins, " 'aws_role_arn' is a required option to use "
Copy link
Contributor

Choose a reason for hiding this comment

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

In the CloudWatch plugin its just called role_arn

Copy link
Contributor

Choose a reason for hiding this comment

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

Also see my other comment, I just realized this error isn't true or needed since we use sts_endpoint in the EKS provider

Comment on lines 174 to 175
if (ctx->aws_sts_endpoint && !tmp) {
flb_plg_error(ctx->ins, " 'aws_role_arn' is a required option to use "
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry... I just realized... since we use sts_endpoint in the EKS Provider, this error message is no longer true. Role_arn is not required.

Copy link
Author

Choose a reason for hiding this comment

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

Does this mean that role_arn is not required even for the sts provider? I don't fully understand why the error message is not required. Can you explain.

Copy link
Contributor

@PettitWesley PettitWesley Aug 26, 2020

Choose a reason for hiding this comment

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

Basically there are two cases:

  1. role_arn is present, in which case we use the STS Provider which needs both the sts endpoint and the role as arguments
  2. role_arn is not present, in which case we use the standard chain provider. That can contain the EKS provider, so it needs the sts endpoint as an argument

Originally, I had forgotten about case #2, so I thought #1 was the only case.

In both cases, the custom sts endpoint can be used

Copy link
Author

Choose a reason for hiding this comment

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

ooh! This makes sense! Thank you

@@ -568,8 +576,11 @@ struct flb_aws_provider *flb_eks_provider_create(struct flb_config *config,
return NULL;
}

implementation->endpoint = flb_aws_endpoint("sts", region);
if (!implementation->endpoint) {
implementation->endpoint = removeProtocol(sts_endpoint, "https://");
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this line inside of the if block below; strstr behavior is undefined if any of the parameters are NULL, so this code might work for you on your compiler, but it might not work on others: https://stackoverflow.com/questions/19579574/what-is-behavior-of-null-parameters-to-strstr

if (implementation->endpoint) {
implementation->custom_endpoint = FLB_TRUE;
}else{
implementation->custom_endpoint = FLB_TRUE;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should set it to false in this case?

Comment on lines 84 to 217
char *removeProtocol (char *endpoint, char *protocol) {
if (strstr(endpoint, protocol)){
endpoint = endpoint + strlen(protocol);
}
return endpoint;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

strstr checks substring... we want to check prefix.

See here: https://stackoverflow.com/questions/4770985/how-to-check-if-a-string-starts-with-another-string-in-c

I like the second answer using strncmp

Copy link
Author

Choose a reason for hiding this comment

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

Oh yes! I see how using strstr is more error prone here. I will switch to strncmp.

Comment on lines 302 to 309
else {
implementation->custom_endpoint = FLB_FALSE;
goto error;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I reading this code wrong... because it looks like if there is no custom endpoint, then we goto error and fail initialization...

Comment on lines 585 to 595
else {
implementation->custom_endpoint = FLB_FALSE;
goto error;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question... looks like it will goto error if there is no custom endpoint

@edsiper
Copy link
Member

edsiper commented Sep 25, 2020

@MeghnaPrabhu thanks for this PR. Please resolve the conflicts on src/aws/flb_aws_util.c

@edsiper edsiper added the waiting-for-user Waiting for more information, tests or requested changes label Sep 25, 2020
meghnapr and others added 7 commits September 27, 2020 00:35
Signed-off-by: Meghna Prabhu <meghnapr@amazon.com>
Signed-off-by: Meghna Prabhu <meghnapr@amazon.com>
Signed-off-by: Meghna Prabhu <meghnapr@amazon.com>
Signed-off-by: Meghna Prabhu <meghnapr@amazon.com>
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
@PettitWesley
Copy link
Contributor

@meghnapr @edsiper Fixed the conflicts and added sts_endpoint to new plugins out_s3 and out_kinesis_firehose

@PettitWesley PettitWesley merged commit 8d412ed into fluent:master Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-user Waiting for more information, tests or requested changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants