Skip to content

Commit ae44712

Browse files
cosmo0920edsiper
authored andcommitted
aws: verify TLS for container credential endpoints
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent b41cff3 commit ae44712

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎src/aws/flb_aws_credentials.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ static struct flb_aws_provider *standard_chain_create(struct flb_config
588588

589589
sub_provider = flb_http_provider_create(config, generator);
590590
if (sub_provider) {
591+
/* Apply the hostname policy to the container endpoint's own TLS context. */
592+
if (sub_provider->cred_tls && tls && tls->verify_hostname == FLB_TRUE) {
593+
flb_tls_set_verify_hostname(sub_provider->cred_tls, FLB_TRUE);
594+
}
595+
591596
/* ECS Provider will fail creation if we are not running in ECS */
592597
mk_list_add(&sub_provider->_head, &implementation->sub_providers);
593598
flb_debug("[aws_credentials] Initialized ECS Provider in standard chain");

‎src/aws/flb_aws_credentials_http.c‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)