3131
3232#include "azure_kusto.h"
3333#include "azure_kusto_conf.h"
34- #include "azure_msiauth.h"
3534
3635/* Constants for PCG random number generator */
3736#define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL
@@ -724,7 +723,7 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
724723
725724 /* Auth method validation and setup */
726725 if (strcasecmp (ctx -> auth_type_str , "service_principal" ) == 0 ) {
727- ctx -> auth_type = FLB_AZURE_KUSTO_AUTH_SERVICE_PRINCIPAL ;
726+ ctx -> auth_type = FLB_AZURE_AUTH_SERVICE_PRINCIPAL ;
728727
729728 /* Verify required parameters for Service Principal auth */
730729 if (!ctx -> tenant_id || !ctx -> client_id || !ctx -> client_secret ) {
@@ -742,13 +741,13 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
742741 }
743742
744743 if (strcasecmp (ctx -> client_id , "system" ) == 0 ) {
745- ctx -> auth_type = FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_SYSTEM ;
744+ ctx -> auth_type = FLB_AZURE_AUTH_MANAGED_IDENTITY_SYSTEM ;
746745 } else {
747- ctx -> auth_type = FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_USER ;
746+ ctx -> auth_type = FLB_AZURE_AUTH_MANAGED_IDENTITY_USER ;
748747 }
749748 }
750749 else if (strcasecmp (ctx -> auth_type_str , "workload_identity" ) == 0 ) {
751- ctx -> auth_type = FLB_AZURE_KUSTO_AUTH_WORKLOAD_IDENTITY ;
750+ ctx -> auth_type = FLB_AZURE_AUTH_WORKLOAD_IDENTITY ;
752751
753752 /* Verify required parameters for Workload Identity auth */
754753 if (!ctx -> tenant_id || !ctx -> client_id ) {
@@ -759,7 +758,7 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
759758
760759 /* Set default token file path if not specified */
761760 if (!ctx -> workload_identity_token_file ) {
762- ctx -> workload_identity_token_file = flb_strdup ("/var/run/secrets/azure/tokens/azure-identity-token" );
761+ ctx -> workload_identity_token_file = flb_strdup (FLB_AZURE_WORKLOAD_IDENTITY_TOKEN_FILE );
763762 if (!ctx -> workload_identity_token_file ) {
764763 flb_errno ();
765764 flb_plg_error (ins , "Could not allocate default workload identity token path" );
@@ -796,44 +795,15 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
796795 return NULL ;
797796 }
798797
799- /* Create oauth2 context */
800- if (ctx -> auth_type == FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_SYSTEM ||
801- ctx -> auth_type == FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_USER ) {
802- /* MSI auth */
803- /* Construct the URL template with or without client_id for managed identity */
804- 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 );
806- if (!ctx -> oauth_url ) {
807- flb_errno ();
808- flb_azure_kusto_conf_destroy (ctx );
809- return NULL ;
810- }
811- flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
812- FLB_AZURE_MSIAUTH_URL_TEMPLATE , "" , "" );
813- } else {
814- /* User-assigned managed identity */
815- ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_AZURE_MSIAUTH_URL_TEMPLATE ) - 1 +
816- sizeof ("&client_id=" ) - 1 +
817- flb_sds_len (ctx -> client_id ));
818- if (!ctx -> oauth_url ) {
819- flb_errno ();
820- flb_azure_kusto_conf_destroy (ctx );
821- return NULL ;
822- }
823- flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
824- FLB_AZURE_MSIAUTH_URL_TEMPLATE , "&client_id=" , ctx -> client_id );
825- }
826- } else {
827- /* Standard OAuth2 for service principal or workload identity */
828- ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_MSAL_AUTH_URL_TEMPLATE ) - 1 +
829- flb_sds_len (ctx -> tenant_id ));
830- if (!ctx -> oauth_url ) {
831- flb_errno ();
832- flb_azure_kusto_conf_destroy (ctx );
833- return NULL ;
834- }
835- flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
836- FLB_MSAL_AUTH_URL_TEMPLATE , ctx -> tenant_id );
798+ /* Create oauth2 context using common auth URL builder */
799+ ctx -> oauth_url = flb_azure_auth_build_oauth_url (ctx -> auth_type ,
800+ ctx -> tenant_id ,
801+ ctx -> client_id ,
802+ FLB_AZURE_KUSTO_RESOURCE_SCOPE );
803+ if (!ctx -> oauth_url ) {
804+ flb_plg_error (ctx -> ins , "failed to create OAuth URL" );
805+ flb_azure_kusto_conf_destroy (ctx );
806+ return NULL ;
837807 }
838808
839809 ctx -> resources = flb_calloc (1 , sizeof (struct flb_azure_kusto_resources ));
@@ -862,6 +832,11 @@ int flb_azure_kusto_conf_destroy(struct flb_azure_kusto *ctx)
862832 ctx -> oauth_url = NULL ;
863833 }
864834
835+ if (ctx -> workload_identity_token_file ) {
836+ flb_free (ctx -> workload_identity_token_file );
837+ ctx -> workload_identity_token_file = NULL ;
838+ }
839+
865840 if (ctx -> o ) {
866841 flb_oauth2_destroy (ctx -> o );
867842 ctx -> o = NULL ;
0 commit comments