@@ -700,6 +700,121 @@ static int flb_azure_kusto_resources_destroy(struct flb_azure_kusto_resources *r
700700 return 0 ;
701701}
702702
703+ /**
704+ * Resolves cloud-specific endpoints based on the cloud_name configuration.
705+ * Sets kusto_scope, kusto_resource, and login_host in the context.
706+ *
707+ * @param ctx Pointer to the plugin's context
708+ * @return int 0 on success, -1 on failure
709+ */
710+ static int azure_kusto_resolve_cloud_endpoints (struct flb_azure_kusto * ctx )
711+ {
712+ const char * scope = NULL ;
713+ const char * resource = NULL ;
714+ const char * login_host = NULL ;
715+ int has_custom_login_host ;
716+ int has_custom_scope ;
717+ int has_custom_resource ;
718+
719+ /* Check if custom overrides are provided */
720+ has_custom_login_host = (ctx -> custom_login_host && flb_sds_len (ctx -> custom_login_host ) > 0 );
721+ has_custom_scope = (ctx -> custom_kusto_scope && flb_sds_len (ctx -> custom_kusto_scope ) > 0 );
722+ has_custom_resource = (ctx -> custom_kusto_resource && flb_sds_len (ctx -> custom_kusto_resource ) > 0 );
723+
724+ /* If all three custom properties are provided, use them directly */
725+ if (has_custom_login_host && has_custom_scope && has_custom_resource ) {
726+ ctx -> login_host = flb_sds_create (ctx -> custom_login_host );
727+ if (!ctx -> login_host ) {
728+ flb_errno ();
729+ return -1 ;
730+ }
731+
732+ ctx -> kusto_scope = flb_sds_create (ctx -> custom_kusto_scope );
733+ if (!ctx -> kusto_scope ) {
734+ flb_errno ();
735+ return -1 ;
736+ }
737+
738+ ctx -> kusto_resource = flb_sds_create (ctx -> custom_kusto_resource );
739+ if (!ctx -> kusto_resource ) {
740+ flb_errno ();
741+ return -1 ;
742+ }
743+
744+ flb_plg_info (ctx -> ins ,
745+ "using custom cloud endpoints: login_host='%s', scope='%s', resource='%s'" ,
746+ ctx -> login_host , ctx -> kusto_scope , ctx -> kusto_resource );
747+ return 0 ;
748+ }
749+
750+ /* If some but not all custom properties are set, error out */
751+ if (has_custom_login_host || has_custom_scope || has_custom_resource ) {
752+ flb_plg_error (ctx -> ins ,
753+ "When using custom cloud endpoints, all three properties must be set: "
754+ "cloud_login_host, cloud_kusto_scope, cloud_kusto_resource" );
755+ return -1 ;
756+ }
757+
758+ /* Resolve from well-known cloud names */
759+ if (!ctx -> cloud_name || strcasecmp (ctx -> cloud_name , "AzureCloud" ) == 0 ) {
760+ ctx -> cloud_type = FLB_AZURE_CLOUD_PUBLIC ;
761+ scope = FLB_AZURE_KUSTO_SCOPE_PUBLIC ;
762+ resource = FLB_AZURE_KUSTO_RESOURCE_PUBLIC ;
763+ login_host = FLB_AZURE_LOGIN_HOST_PUBLIC ;
764+ }
765+ else if (strcasecmp (ctx -> cloud_name , "AzureChinaCloud" ) == 0 ) {
766+ ctx -> cloud_type = FLB_AZURE_CLOUD_CHINA ;
767+ scope = FLB_AZURE_KUSTO_SCOPE_CHINA ;
768+ resource = FLB_AZURE_KUSTO_RESOURCE_CHINA ;
769+ login_host = FLB_AZURE_LOGIN_HOST_CHINA ;
770+ }
771+ else if (strcasecmp (ctx -> cloud_name , "AzureUSGovernmentCloud" ) == 0 ) {
772+ ctx -> cloud_type = FLB_AZURE_CLOUD_US_GOVERNMENT ;
773+ scope = FLB_AZURE_KUSTO_SCOPE_US_GOVERNMENT ;
774+ resource = FLB_AZURE_KUSTO_RESOURCE_US_GOVERNMENT ;
775+ login_host = FLB_AZURE_LOGIN_HOST_US_GOVERNMENT ;
776+ }
777+ else if (strcasecmp (ctx -> cloud_name , "AzureGermanCloud" ) == 0 ) {
778+ ctx -> cloud_type = FLB_AZURE_CLOUD_GERMAN ;
779+ scope = FLB_AZURE_KUSTO_SCOPE_GERMAN ;
780+ resource = FLB_AZURE_KUSTO_RESOURCE_GERMAN ;
781+ login_host = FLB_AZURE_LOGIN_HOST_GERMAN ;
782+ }
783+ else {
784+ flb_plg_error (ctx -> ins ,
785+ "Unknown cloud_name '%s'. Use a well-known cloud name "
786+ "('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernmentCloud', "
787+ "'AzureGermanCloud') or specify custom endpoints via "
788+ "cloud_login_host, cloud_kusto_scope, and cloud_kusto_resource" ,
789+ ctx -> cloud_name );
790+ return -1 ;
791+ }
792+
793+ ctx -> kusto_scope = flb_sds_create (scope );
794+ if (!ctx -> kusto_scope ) {
795+ flb_errno ();
796+ return -1 ;
797+ }
798+
799+ ctx -> kusto_resource = flb_sds_create (resource );
800+ if (!ctx -> kusto_resource ) {
801+ flb_errno ();
802+ return -1 ;
803+ }
804+
805+ ctx -> login_host = flb_sds_create (login_host );
806+ if (!ctx -> login_host ) {
807+ flb_errno ();
808+ return -1 ;
809+ }
810+
811+ flb_plg_info (ctx -> ins , "cloud environment='%s', login_host='%s', scope='%s'" ,
812+ ctx -> cloud_name ? ctx -> cloud_name : "AzureCloud" ,
813+ ctx -> login_host , ctx -> kusto_scope );
814+
815+ return 0 ;
816+ }
817+
703818struct flb_azure_kusto * flb_azure_kusto_conf_create (struct flb_output_instance * ins ,
704819 struct flb_config * config )
705820{
@@ -722,6 +837,14 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
722837 return NULL ;
723838 }
724839
840+ /* Resolve cloud-specific endpoints */
841+ ret = azure_kusto_resolve_cloud_endpoints (ctx );
842+ if (ret == -1 ) {
843+ flb_plg_error (ins , "failed to resolve cloud endpoints" );
844+ flb_azure_kusto_conf_destroy (ctx );
845+ return NULL ;
846+ }
847+
725848 /* Auth method validation and setup */
726849 if (strcasecmp (ctx -> auth_type_str , "service_principal" ) == 0 ) {
727850 ctx -> auth_type = FLB_AZURE_KUSTO_AUTH_SERVICE_PRINCIPAL ;
@@ -802,38 +925,44 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
802925 /* MSI auth */
803926 /* Construct the URL template with or without client_id for managed identity */
804927 if (ctx -> auth_type == FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_SYSTEM ) {
805- ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_AZURE_MSIAUTH_URL_TEMPLATE ) - 1 );
928+ ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_AZURE_MSIAUTH_URL_TEMPLATE ) - 1 +
929+ flb_sds_len (ctx -> kusto_resource ));
806930 if (!ctx -> oauth_url ) {
807931 flb_errno ();
808932 flb_azure_kusto_conf_destroy (ctx );
809933 return NULL ;
810934 }
811935 flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
812- FLB_AZURE_MSIAUTH_URL_TEMPLATE , "" , "" );
936+ FLB_AZURE_MSIAUTH_URL_TEMPLATE , "" , "" ,
937+ ctx -> kusto_resource );
813938 } else {
814939 /* User-assigned managed identity */
815940 ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_AZURE_MSIAUTH_URL_TEMPLATE ) - 1 +
816941 sizeof ("&client_id=" ) - 1 +
817- flb_sds_len (ctx -> client_id ));
942+ flb_sds_len (ctx -> client_id ) +
943+ flb_sds_len (ctx -> kusto_resource ));
818944 if (!ctx -> oauth_url ) {
819945 flb_errno ();
820946 flb_azure_kusto_conf_destroy (ctx );
821947 return NULL ;
822948 }
823949 flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
824- FLB_AZURE_MSIAUTH_URL_TEMPLATE , "&client_id=" , ctx -> client_id );
950+ FLB_AZURE_MSIAUTH_URL_TEMPLATE , "&client_id=" ,
951+ ctx -> client_id , ctx -> kusto_resource );
825952 }
826953 } else {
827954 /* Standard OAuth2 for service principal or workload identity */
828955 ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_MSAL_AUTH_URL_TEMPLATE ) - 1 +
956+ flb_sds_len (ctx -> login_host ) +
829957 flb_sds_len (ctx -> tenant_id ));
830958 if (!ctx -> oauth_url ) {
831959 flb_errno ();
832960 flb_azure_kusto_conf_destroy (ctx );
833961 return NULL ;
834962 }
835963 flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
836- FLB_MSAL_AUTH_URL_TEMPLATE , ctx -> tenant_id );
964+ FLB_MSAL_AUTH_URL_TEMPLATE , ctx -> login_host ,
965+ ctx -> tenant_id );
837966 }
838967
839968 ctx -> resources = flb_calloc (1 , sizeof (struct flb_azure_kusto_resources ));
@@ -857,6 +986,21 @@ int flb_azure_kusto_conf_destroy(struct flb_azure_kusto *ctx)
857986
858987 flb_plg_info (ctx -> ins , "before exiting the plugin kusto conf destroy called" );
859988
989+ if (ctx -> kusto_scope ) {
990+ flb_sds_destroy (ctx -> kusto_scope );
991+ ctx -> kusto_scope = NULL ;
992+ }
993+
994+ if (ctx -> kusto_resource ) {
995+ flb_sds_destroy (ctx -> kusto_resource );
996+ ctx -> kusto_resource = NULL ;
997+ }
998+
999+ if (ctx -> login_host ) {
1000+ flb_sds_destroy (ctx -> login_host );
1001+ ctx -> login_host = NULL ;
1002+ }
1003+
8601004 if (ctx -> oauth_url ) {
8611005 flb_sds_destroy (ctx -> oauth_url );
8621006 ctx -> oauth_url = NULL ;
0 commit comments