Skip to content

Commit 96ef333

Browse files
cosmo0920edsiper
authored andcommitted
tests: internal: cover container credential TLS verification
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent ae44712 commit 96ef333

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

‎tests/internal/aws_credentials_http.c‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <fluent-bit/flb_mem.h>
66
#include <fluent-bit/flb_info.h>
77
#include <fluent-bit/flb_http_client.h>
8+
#include <fluent-bit/tls/flb_tls.h>
89

910
#include <monkey/mk_core.h>
1011
#include <string.h>
@@ -602,8 +603,10 @@ static void test_http_provider_eks_with_token_file()
602603
static void test_http_provider_https_endpoint()
603604
{
604605
struct flb_aws_provider *provider;
606+
struct flb_aws_provider_http *implementation;
605607
struct flb_aws_credentials *creds;
606608
struct flb_config *config;
609+
struct flb_stream *stream;
607610
int ret;
608611

609612
flb_test_setenv("AWS_CONTAINER_CREDENTIALS_FULL_URI", "https://customers-vpc-credential-vending-server/iam_credentials/pod1", 1);
@@ -634,6 +637,18 @@ static void test_http_provider_https_endpoint()
634637
)
635638
), &provider, &config);
636639

640+
implementation = provider->implementation;
641+
stream = &implementation->client->upstream->base;
642+
TEST_CHECK(flb_stream_is_secure(stream) == FLB_TRUE);
643+
TEST_CHECK(stream->tls_context != NULL);
644+
if (stream->tls_context != NULL) {
645+
TEST_CHECK(stream->tls_context->verify == FLB_TRUE);
646+
TEST_CHECK(stream->tls_context->verify_hostname == FLB_FALSE);
647+
TEST_CHECK(stream->tls_context->vhost != NULL &&
648+
strcmp(stream->tls_context->vhost,
649+
"customers-vpc-credential-vending-server") == 0);
650+
}
651+
637652
flb_time_msleep(1000);
638653

639654
/* Repeated calls to get credentials should return the same set */
@@ -673,6 +688,56 @@ static void test_http_provider_https_endpoint()
673688
cleanup_test(provider, config);
674689
}
675690

691+
static void test_http_provider_chain_hostname_verification(void)
692+
{
693+
size_t index;
694+
int found;
695+
int verify_hostname[] = {FLB_FALSE, FLB_TRUE};
696+
struct flb_config *config;
697+
struct flb_aws_provider *provider;
698+
struct flb_upstream *upstream;
699+
struct mk_list *head;
700+
struct flb_tls *endpoint_tls;
701+
struct flb_tls tls = {0};
702+
const char *host = "container-credentials.example";
703+
704+
flb_test_setenv("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "", 1);
705+
flb_test_setenv("AWS_CONTAINER_CREDENTIALS_FULL_URI",
706+
"https://container-credentials.example/credentials", 1);
707+
708+
config = flb_config_init();
709+
TEST_ASSERT(config != NULL);
710+
711+
for (index = 0; index < sizeof(verify_hostname) / sizeof(verify_hostname[0]); index++) {
712+
tls.verify_hostname = verify_hostname[index];
713+
provider = flb_standard_chain_provider_create(config, &tls, "us-west-2", NULL,
714+
NULL, flb_aws_client_generator(), NULL);
715+
TEST_CHECK(provider != NULL);
716+
if (provider == NULL) {
717+
break;
718+
}
719+
720+
found = FLB_FALSE;
721+
mk_list_foreach(head, &config->upstreams) {
722+
upstream = mk_list_entry(head, struct flb_upstream, base._head);
723+
endpoint_tls = upstream->base.tls_context;
724+
if (endpoint_tls != NULL && endpoint_tls->vhost != NULL &&
725+
strcmp(endpoint_tls->vhost, host) == 0) {
726+
found = FLB_TRUE;
727+
TEST_CHECK(flb_stream_is_secure(&upstream->base) == FLB_TRUE);
728+
TEST_CHECK(endpoint_tls->verify == FLB_TRUE);
729+
TEST_CHECK(endpoint_tls->verify_hostname == verify_hostname[index]);
730+
break;
731+
}
732+
}
733+
TEST_CHECK(found == FLB_TRUE);
734+
flb_aws_provider_destroy(provider);
735+
}
736+
737+
flb_test_setenv("AWS_CONTAINER_CREDENTIALS_FULL_URI", "", 1);
738+
flb_config_exit(config);
739+
}
740+
676741
static void test_http_provider_server_failure()
677742
{
678743
struct flb_aws_provider *provider;
@@ -976,6 +1041,8 @@ TEST_LIST = {
9761041
{ "test_http_provider_eks_with_token", test_http_provider_eks_with_token},
9771042
{ "test_http_provider_eks_with_token_file", test_http_provider_eks_with_token_file},
9781043
{ "test_http_provider_https_endpoint", test_http_provider_https_endpoint},
1044+
{ "test_http_provider_chain_hostname_verification",
1045+
test_http_provider_chain_hostname_verification},
9791046
{ "test_http_provider_server_failure", test_http_provider_server_failure},
9801047
{ "test_http_validator_invalid_host", test_http_validator_invalid_host},
9811048
{ "test_http_validator_rejects_host_lookalikes", test_http_validator_rejects_host_lookalikes},

0 commit comments

Comments
 (0)