Skip to content

Commit 155eb7e

Browse files
committed
aws: restore IMDS timeouts after upstream_set in EC2 provider
flb_output_upstream_set() overwrites IMDS client timeouts with output plugin values, causing credential refresh failures. Restore the correct IMDS timeouts after the upstream is configured. This patch fixes the timeout issue when output plugins have custom network settings. Signed-off-by: Eduardo Silva <[email protected]>
1 parent 2b9010a commit 155eb7e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/aws/flb_aws_credentials_ec2.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct flb_aws_provider_ec2 {
4949

5050
/* upstream connection to IMDS */
5151
struct flb_aws_client *client;
52-
52+
5353
/* IMDS interface */
5454
struct flb_aws_imds *imds_interface;
5555
};
@@ -171,13 +171,24 @@ void async_fn_ec2(struct flb_aws_provider *provider) {
171171

172172
void upstream_set_fn_ec2(struct flb_aws_provider *provider,
173173
struct flb_output_instance *ins) {
174+
174175
struct flb_aws_provider_ec2 *implementation = provider->implementation;
175176

176177
flb_debug("[aws_credentials] upstream_set called on the EC2 provider");
178+
177179
/* Make sure TLS is set to false before setting upstream, then reset it */
178180
ins->use_tls = FLB_FALSE;
179181
flb_output_upstream_set(implementation->client->upstream, ins);
180182
ins->use_tls = FLB_TRUE;
183+
184+
/*
185+
* flb_output_upstream_set() overwrites u->base.net with the instance
186+
* network configuration, since EC2 IMDS upstreams require a finite timeout, we need
187+
* to restore the values configured during provider creation.
188+
*/
189+
implementation->client->upstream->base.net.connect_timeout = FLB_AWS_IMDS_TIMEOUT;
190+
implementation->client->upstream->base.net.io_timeout = FLB_AWS_IMDS_TIMEOUT;
191+
implementation->client->upstream->base.net.keepalive = FLB_FALSE;
181192
}
182193

183194
void destroy_fn_ec2(struct flb_aws_provider *provider) {

0 commit comments

Comments
 (0)