@@ -213,7 +213,7 @@ static int flb_azure_blob_process_remote_configuration_payload(
213213
214214 context -> endpoint_overriden_flag = FLB_TRUE ;
215215
216- if (context -> atype == AZURE_BLOB_AUTH_KEY ) {
216+ if (context -> atype == FLB_AZURE_AUTH_KEY ) {
217217 value_backup = context -> shared_key ;
218218 context -> shared_key = NULL ;
219219
@@ -233,7 +233,7 @@ static int flb_azure_blob_process_remote_configuration_payload(
233233
234234 context -> shared_key_overriden_flag = FLB_TRUE ;
235235 }
236- else if (context -> atype == AZURE_BLOB_AUTH_SAS ) {
236+ else if (context -> atype == FLB_AZURE_AUTH_SAS ) {
237237 value_backup = context -> sas_token ;
238238 context -> sas_token = NULL ;
239239
@@ -590,27 +590,80 @@ struct flb_azure_blob *flb_azure_blob_conf_create(struct flb_output_instance *in
590590 /* Set Auth type */
591591 tmp = (char * ) flb_output_get_property ("auth_type" , ins );
592592 if (!tmp ) {
593- ctx -> atype = AZURE_BLOB_AUTH_KEY ;
593+ ctx -> atype = FLB_AZURE_AUTH_KEY ; /* Default to legacy key auth */
594594 }
595595 else {
596596 if (strcasecmp (tmp , "key" ) == 0 ) {
597- ctx -> atype = AZURE_BLOB_AUTH_KEY ;
597+ ctx -> atype = FLB_AZURE_AUTH_KEY ;
598598 }
599599 else if (strcasecmp (tmp , "sas" ) == 0 ) {
600- ctx -> atype = AZURE_BLOB_AUTH_SAS ;
600+ ctx -> atype = FLB_AZURE_AUTH_SAS ;
601+ }
602+ #ifdef FLB_HAVE_TLS
603+ else if (strcasecmp (tmp , "service_principal ") == 0 ) {
604+ ctx -> atype = FLB_AZURE_AUTH_SERVICE_PRINCIPAL ;
605+
606+ /* Verify required parameters for Service Principal auth */
607+ if (!ctx -> tenant_id || !ctx -> client_id || !ctx -> client_secret ) {
608+ flb_plg_error (ins , "When using service_principal auth, tenant_id, client_id, and client_secret are required" );
609+ return NULL ;
610+ }
611+ }
612+ else if (strcasecmp (tmp , "managed_identity ") == 0 ) {
613+ /* Check if client_id indicates system-assigned or user-assigned managed identity */
614+ if (!ctx -> client_id ) {
615+ flb_plg_error (ins , "When using managed_identity auth, client_id must be set to 'system' for system-assigned or the managed identity client ID" );
616+ return NULL ;
617+ }
618+
619+ if (strcasecmp (ctx -> client_id , "system" ) == 0 ) {
620+ ctx -> atype = FLB_AZURE_AUTH_MANAGED_IDENTITY_SYSTEM ;
621+ } else {
622+ ctx -> atype = FLB_AZURE_AUTH_MANAGED_IDENTITY_USER ;
623+ }
601624 }
625+ else if (strcasecmp (tmp , "workload_identity ") == 0 ) {
626+ ctx -> atype = FLB_AZURE_AUTH_WORKLOAD_IDENTITY ;
627+
628+ /* Verify required parameters for Workload Identity auth */
629+ if (!ctx -> tenant_id || !ctx -> client_id ) {
630+ flb_plg_error (ins , "When using workload_identity auth, tenant_id and client_id are required" );
631+ return NULL ;
632+ }
633+
634+ /* Set default token file path if not specified */
635+ if (!ctx -> workload_identity_token_file ) {
636+ ctx -> workload_identity_token_file = flb_sds_create (FLB_AZURE_WORKLOAD_IDENTITY_TOKEN_FILE );
637+ if (!ctx -> workload_identity_token_file ) {
638+ flb_errno ();
639+ flb_plg_error (ins , "Could not allocate default workload identity token path" );
640+ return NULL ;
641+ }
642+ }
643+ }
644+ #else
645+ else if (strcasecmp (tmp , "service_principal ") == 0 ||
646+ strcasecmp (tmp , "managed_identity ") == 0 ||
647+ strcasecmp (tmp , "workload_identity" ) == 0 ) {
648+ flb_plg_error (ctx -> ins , "OAuth authentication requires TLS support. " \
649+ "Rebuild with -DFLB_TLS=ON" );
650+ return NULL ;
651+ }
652+ #endif
602653 else {
603- flb_plg_error (ctx -> ins , "invalid auth_type value '%s'" , tmp );
654+ flb_plg_error (ctx -> ins , "invalid auth_type value '%s'. Valid options are: 'key', 'sas', 'service_principal', 'managed_identity', or 'workload_identity' " , tmp );
604655 return NULL ;
605656 }
606657 }
607- if (ctx -> atype == AZURE_BLOB_AUTH_KEY &&
658+
659+ /* Validate auth-specific requirements */
660+ if (ctx -> atype == FLB_AZURE_AUTH_KEY &&
608661 ctx -> shared_key == NULL ) {
609662 flb_plg_error (ctx -> ins , "'shared_key' has not been set" );
610663 return NULL ;
611664 }
612665
613- if (ctx -> atype == AZURE_BLOB_AUTH_SAS ) {
666+ if (ctx -> atype == FLB_AZURE_AUTH_SAS ) {
614667 if (ctx -> sas_token == NULL ) {
615668 flb_plg_error (ctx -> ins , "'sas_token' has not been set" );
616669 return NULL ;
@@ -621,7 +674,7 @@ struct flb_azure_blob *flb_azure_blob_conf_create(struct flb_output_instance *in
621674 }
622675
623676 /* If the shared key is set decode it */
624- if (ctx -> atype == AZURE_BLOB_AUTH_KEY &&
677+ if (ctx -> atype == FLB_AZURE_AUTH_KEY &&
625678 ctx -> shared_key != NULL ) {
626679 ret = set_shared_key (ctx );
627680 if (ret == -1 ) {
@@ -730,6 +783,37 @@ struct flb_azure_blob *flb_azure_blob_conf_create(struct flb_output_instance *in
730783 }
731784 flb_output_upstream_set (ctx -> u , ins );
732785
786+ #ifdef FLB_HAVE_TLS
787+ /* Initialize OAuth2 context for OAuth-based authentication methods */
788+ if (ctx -> atype == FLB_AZURE_AUTH_SERVICE_PRINCIPAL ||
789+ ctx -> atype == FLB_AZURE_AUTH_MANAGED_IDENTITY_SYSTEM ||
790+ ctx -> atype == FLB_AZURE_AUTH_MANAGED_IDENTITY_USER ||
791+ ctx -> atype == FLB_AZURE_AUTH_WORKLOAD_IDENTITY ) {
792+
793+ /* Build OAuth URL based on auth type */
794+ ctx -> oauth_url = flb_azure_auth_build_oauth_url (ctx -> atype ,
795+ ctx -> tenant_id ,
796+ ctx -> client_id ,
797+ FLB_AZURE_BLOB_RESOURCE );
798+ if (!ctx -> oauth_url ) {
799+ flb_plg_error (ctx -> ins , "failed to create OAuth URL" );
800+ return NULL ;
801+ }
802+
803+ /* Create OAuth2 context */
804+ ctx -> o = flb_oauth2_create (ctx -> config , ctx -> oauth_url , 3000 );
805+ if (!ctx -> o ) {
806+ flb_plg_error (ctx -> ins , "cannot create oauth2 context" );
807+ return NULL ;
808+ }
809+
810+ /* Initialize token mutex */
811+ pthread_mutex_init (& ctx -> token_mutex , NULL );
812+
813+ flb_plg_info (ctx -> ins , "oauth2 context initialized for auth type" );
814+ }
815+ #endif
816+
733817 /* Compose base uri */
734818 ctx -> base_uri = flb_sds_create_size (256 );
735819 if (!ctx -> base_uri ) {
@@ -746,7 +830,7 @@ struct flb_azure_blob *flb_azure_blob_conf_create(struct flb_output_instance *in
746830 }
747831
748832 /* Prepare shared key buffer */
749- if (ctx -> atype == AZURE_BLOB_AUTH_KEY ) {
833+ if (ctx -> atype == FLB_AZURE_AUTH_KEY ) {
750834 ctx -> shared_key_prefix = flb_sds_create_size (256 );
751835 if (!ctx -> shared_key_prefix ) {
752836 flb_plg_error (ctx -> ins , "cannot create shared key prefix" );
@@ -772,13 +856,40 @@ struct flb_azure_blob *flb_azure_blob_conf_create(struct flb_output_instance *in
772856
773857 pthread_mutex_init (& ctx -> file_upload_commit_file_parts , NULL );
774858
775- flb_plg_info (ctx -> ins ,
776- "account_name=%s, container_name=%s, blob_type=%s, emulator_mode=%s, endpoint=%s, auth_type=%s" ,
777- ctx -> account_name , ctx -> container_name ,
778- ctx -> btype == AZURE_BLOB_APPENDBLOB ? "appendblob" : "blockblob" ,
779- ctx -> emulator_mode ? "yes" : "no" ,
780- ctx -> real_endpoint ? ctx -> real_endpoint : "no" ,
781- ctx -> atype == AZURE_BLOB_AUTH_KEY ? "key" : "sas" );
859+ /* Log configuration summary */
860+ {
861+ const char * auth_type_str ;
862+ switch (ctx -> atype ) {
863+ case FLB_AZURE_AUTH_KEY :
864+ auth_type_str = "key" ;
865+ break ;
866+ case FLB_AZURE_AUTH_SAS :
867+ auth_type_str = "sas" ;
868+ break ;
869+ case FLB_AZURE_AUTH_SERVICE_PRINCIPAL :
870+ auth_type_str = "service_principal" ;
871+ break ;
872+ case FLB_AZURE_AUTH_MANAGED_IDENTITY_SYSTEM :
873+ auth_type_str = "managed_identity (system)" ;
874+ break ;
875+ case FLB_AZURE_AUTH_MANAGED_IDENTITY_USER :
876+ auth_type_str = "managed_identity (user)" ;
877+ break ;
878+ case FLB_AZURE_AUTH_WORKLOAD_IDENTITY :
879+ auth_type_str = "workload_identity" ;
880+ break ;
881+ default :
882+ auth_type_str = "unknown" ;
883+ }
884+
885+ flb_plg_info (ctx -> ins ,
886+ "account_name=%s, container_name=%s, blob_type=%s, emulator_mode=%s, endpoint=%s, auth_type=%s" ,
887+ ctx -> account_name , ctx -> container_name ,
888+ ctx -> btype == AZURE_BLOB_APPENDBLOB ? "appendblob" : "blockblob" ,
889+ ctx -> emulator_mode ? "yes" : "no" ,
890+ ctx -> real_endpoint ? ctx -> real_endpoint : "no" ,
891+ auth_type_str );
892+ }
782893 return ctx ;
783894}
784895
@@ -826,6 +937,23 @@ void flb_azure_blob_conf_destroy(struct flb_azure_blob *ctx)
826937 flb_upstream_destroy (ctx -> u );
827938 }
828939
940+ #ifdef FLB_HAVE_TLS
941+ /* Cleanup OAuth2 resources */
942+ if (ctx -> oauth_url ) {
943+ flb_sds_destroy (ctx -> oauth_url );
944+ }
945+
946+ if (ctx -> o ) {
947+ flb_oauth2_destroy (ctx -> o );
948+ }
949+
950+ if (ctx -> atype == FLB_AZURE_AUTH_SERVICE_PRINCIPAL ||
951+ ctx -> atype == FLB_AZURE_AUTH_MANAGED_IDENTITY_SYSTEM ||
952+ ctx -> atype == FLB_AZURE_AUTH_MANAGED_IDENTITY_USER ||
953+ ctx -> atype == FLB_AZURE_AUTH_WORKLOAD_IDENTITY ) {
954+ pthread_mutex_destroy (& ctx -> token_mutex );
955+ }
956+ #endif
829957
830958 azb_db_close (ctx );
831959 flb_free (ctx );
0 commit comments