3030
3131#include "azure_kusto.h"
3232#include "azure_kusto_conf.h"
33+ #include "azure_msiauth.h"
3334
3435static struct flb_upstream_node * flb_upstream_node_create_url (struct flb_azure_kusto * ctx ,
3536 struct flb_config * config ,
@@ -601,23 +602,8 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
601602 return NULL ;
602603 }
603604
604- /* config: 'tenant_id' */
605- if (ctx -> tenant_id == NULL ) {
606- flb_plg_error (ctx -> ins , "property 'tenant_id' is not defined." );
607- flb_azure_kusto_conf_destroy (ctx );
608- return NULL ;
609- }
610-
611- /* config: 'client_id' */
612- if (ctx -> client_id == NULL ) {
613- flb_plg_error (ctx -> ins , "property 'client_id' is not defined" );
614- flb_azure_kusto_conf_destroy (ctx );
615- return NULL ;
616- }
617-
618- /* config: 'client_secret' */
619- if (ctx -> client_secret == NULL ) {
620- flb_plg_error (ctx -> ins , "property 'client_secret' is not defined" );
605+ if (ctx -> tenant_id == NULL && ctx -> client_id == NULL && ctx -> client_secret == NULL && ctx -> managed_identity_client_id == NULL ) {
606+ flb_plg_error (ctx -> ins , "Service Principal or Managed Identity is not defined" );
621607 flb_azure_kusto_conf_destroy (ctx );
622608 return NULL ;
623609 }
@@ -643,17 +629,70 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
643629 return NULL ;
644630 }
645631
646- /* Create the auth URL */
647- ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_MSAL_AUTH_URL_TEMPLATE ) - 1 +
648- flb_sds_len (ctx -> tenant_id ));
649- if (!ctx -> oauth_url ) {
650- flb_errno ();
651- flb_azure_kusto_conf_destroy (ctx );
652- return NULL ;
632+ if (ctx -> managed_identity_client_id != NULL ) {
633+ /* system assigned managed identity */
634+ if (strcasecmp (ctx -> managed_identity_client_id , "system" ) == 0 ) {
635+ ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_AZURE_MSIAUTH_URL_TEMPLATE ) - 1 );
636+
637+ if (!ctx -> oauth_url ) {
638+ flb_errno ();
639+ flb_azure_kusto_conf_destroy (ctx );
640+ return NULL ;
641+ }
642+
643+ flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
644+ FLB_AZURE_MSIAUTH_URL_TEMPLATE , "" , "" );
645+
646+ } else {
647+ /* user assigned managed identity */
648+ ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_AZURE_MSIAUTH_URL_TEMPLATE ) - 1 +
649+ sizeof ("&client_id=" ) - 1 +
650+ flb_sds_len (ctx -> managed_identity_client_id ));
651+
652+ if (!ctx -> oauth_url ) {
653+ flb_errno ();
654+ flb_azure_kusto_conf_destroy (ctx );
655+ return NULL ;
656+ }
657+
658+ flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
659+ FLB_AZURE_MSIAUTH_URL_TEMPLATE , "&client_id=" , ctx -> managed_identity_client_id );
660+ }
653661 }
654- flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
655- FLB_MSAL_AUTH_URL_TEMPLATE , ctx -> tenant_id );
662+ else {
663+ /* config: 'tenant_id' */
664+ if (ctx -> tenant_id == NULL ) {
665+ flb_plg_error (ctx -> ins , "property 'tenant_id' is not defined." );
666+ flb_azure_kusto_conf_destroy (ctx );
667+ return NULL ;
668+ }
669+
670+ /* config: 'client_id' */
671+ if (ctx -> client_id == NULL ) {
672+ flb_plg_error (ctx -> ins , "property 'client_id' is not defined" );
673+ flb_azure_kusto_conf_destroy (ctx );
674+ return NULL ;
675+ }
676+
677+ /* config: 'client_secret' */
678+ if (ctx -> client_secret == NULL ) {
679+ flb_plg_error (ctx -> ins , "property 'client_secret' is not defined" );
680+ flb_azure_kusto_conf_destroy (ctx );
681+ return NULL ;
682+ }
656683
684+ /* Create the auth URL */
685+ ctx -> oauth_url = flb_sds_create_size (sizeof (FLB_MSAL_AUTH_URL_TEMPLATE ) - 1 +
686+ flb_sds_len (ctx -> tenant_id ));
687+ if (!ctx -> oauth_url ) {
688+ flb_errno ();
689+ flb_azure_kusto_conf_destroy (ctx );
690+ return NULL ;
691+ }
692+ flb_sds_snprintf (& ctx -> oauth_url , flb_sds_alloc (ctx -> oauth_url ),
693+ FLB_MSAL_AUTH_URL_TEMPLATE , ctx -> tenant_id );
694+ }
695+
657696 ctx -> resources = flb_calloc (1 , sizeof (struct flb_azure_kusto_resources ));
658697 if (!ctx -> resources ) {
659698 flb_errno ();
0 commit comments