|
5 | 5 | #include <fluent-bit/flb_mem.h> |
6 | 6 | #include <fluent-bit/flb_info.h> |
7 | 7 | #include <fluent-bit/flb_http_client.h> |
| 8 | +#include <fluent-bit/tls/flb_tls.h> |
8 | 9 |
|
9 | 10 | #include <monkey/mk_core.h> |
10 | 11 | #include <string.h> |
@@ -602,8 +603,10 @@ static void test_http_provider_eks_with_token_file() |
602 | 603 | static void test_http_provider_https_endpoint() |
603 | 604 | { |
604 | 605 | struct flb_aws_provider *provider; |
| 606 | + struct flb_aws_provider_http *implementation; |
605 | 607 | struct flb_aws_credentials *creds; |
606 | 608 | struct flb_config *config; |
| 609 | + struct flb_stream *stream; |
607 | 610 | int ret; |
608 | 611 |
|
609 | 612 | 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() |
634 | 637 | ) |
635 | 638 | ), &provider, &config); |
636 | 639 |
|
| 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 | + |
637 | 652 | flb_time_msleep(1000); |
638 | 653 |
|
639 | 654 | /* Repeated calls to get credentials should return the same set */ |
@@ -673,6 +688,56 @@ static void test_http_provider_https_endpoint() |
673 | 688 | cleanup_test(provider, config); |
674 | 689 | } |
675 | 690 |
|
| 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 | + |
676 | 741 | static void test_http_provider_server_failure() |
677 | 742 | { |
678 | 743 | struct flb_aws_provider *provider; |
@@ -976,6 +1041,8 @@ TEST_LIST = { |
976 | 1041 | { "test_http_provider_eks_with_token", test_http_provider_eks_with_token}, |
977 | 1042 | { "test_http_provider_eks_with_token_file", test_http_provider_eks_with_token_file}, |
978 | 1043 | { "test_http_provider_https_endpoint", test_http_provider_https_endpoint}, |
| 1044 | + { "test_http_provider_chain_hostname_verification", |
| 1045 | + test_http_provider_chain_hostname_verification}, |
979 | 1046 | { "test_http_provider_server_failure", test_http_provider_server_failure}, |
980 | 1047 | { "test_http_validator_invalid_host", test_http_validator_invalid_host}, |
981 | 1048 | { "test_http_validator_rejects_host_lookalikes", test_http_validator_rejects_host_lookalikes}, |
|
0 commit comments