@@ -286,6 +286,8 @@ struct flb_aws_provider *flb_endpoint_provider_create(struct flb_config *config,
286286 flb_aws_client_generator
287287 * generator )
288288{
289+ size_t tls_host_len ;
290+ flb_sds_t tls_host ;
289291 struct flb_aws_provider_http * implementation = NULL ;
290292 struct flb_aws_provider * provider = NULL ;
291293 struct flb_upstream * upstream = NULL ;
@@ -297,6 +299,8 @@ struct flb_aws_provider *flb_endpoint_provider_create(struct flb_config *config,
297299 provider = flb_calloc (1 , sizeof (struct flb_aws_provider ));
298300 if (!provider ) {
299301 flb_errno ();
302+ flb_sds_destroy (host );
303+ flb_sds_destroy (path );
300304 return NULL ;
301305 }
302306
@@ -305,8 +309,10 @@ struct flb_aws_provider *flb_endpoint_provider_create(struct flb_config *config,
305309 implementation = flb_calloc (1 , sizeof (struct flb_aws_provider_http ));
306310
307311 if (!implementation ) {
308- flb_free (provider );
309312 flb_errno ();
313+ flb_aws_provider_destroy (provider );
314+ flb_sds_destroy (host );
315+ flb_sds_destroy (path );
310316 return NULL ;
311317 }
312318
@@ -316,7 +322,27 @@ struct flb_aws_provider *flb_endpoint_provider_create(struct flb_config *config,
316322 implementation -> host = host ;
317323 implementation -> path = path ;
318324
319- upstream = flb_upstream_create (config , host , port , io_flags , NULL );
325+ if (io_flags == FLB_IO_TLS ) {
326+ /* Bind verification to the credential host, including through a proxy. */
327+ tls_host_len = flb_sds_len (host );
328+ if (tls_host_len > 0 && host [tls_host_len - 1 ] == '.' ) {
329+ tls_host_len -- ;
330+ }
331+ tls_host = tls_host_len > 0 ? flb_sds_create_len (host , tls_host_len ) : NULL ;
332+ if (tls_host != NULL ) {
333+ provider -> cred_tls = flb_tls_create (FLB_TLS_CLIENT_MODE , FLB_TRUE , 0 ,
334+ tls_host , NULL , NULL , NULL , NULL , NULL );
335+ flb_sds_destroy (tls_host );
336+ }
337+
338+ if (!provider -> cred_tls ) {
339+ flb_error ("[aws_credentials] HTTP Provider: TLS initialization error" );
340+ flb_aws_provider_destroy (provider );
341+ return NULL ;
342+ }
343+ }
344+
345+ upstream = flb_upstream_create (config , host , port , io_flags , provider -> cred_tls );
320346
321347 if (!upstream ) {
322348 flb_aws_provider_destroy (provider );
@@ -329,8 +355,8 @@ struct flb_aws_provider *flb_endpoint_provider_create(struct flb_config *config,
329355
330356 implementation -> client = generator -> create ();
331357 if (!implementation -> client ) {
332- flb_aws_provider_destroy (provider );
333358 flb_upstream_destroy (upstream );
359+ flb_aws_provider_destroy (provider );
334360 flb_error ("[aws_credentials] HTTP Provider: client creation error" );
335361 return NULL ;
336362 }
0 commit comments