Skip to content

Commit 6ecf807

Browse files
ravgupmsdceravigupta
authored andcommitted
support for system managed identity
1 parent 9f6a222 commit 6ecf807

File tree

4 files changed

+57
-40
lines changed

4 files changed

+57
-40
lines changed

plugins/out_azure_kusto/azure_kusto.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ flb_sds_t get_azure_kusto_token(struct flb_azure_kusto *ctx)
9999
}
100100

101101
if (flb_oauth2_token_expired(ctx->o) == FLB_TRUE) {
102-
if (ctx->managed_identity_id != NULL) {
102+
if (ctx->managed_identity_client_id != NULL) {
103103
ret = azure_kusto_get_msi_token(ctx);
104104
}
105105
else {
@@ -503,9 +503,9 @@ static struct flb_config_map config_map[] = {
503503
offsetof(struct flb_azure_kusto, client_secret),
504504
"Set the client secret (Application Password) of the AAD application used for "
505505
"authentication"},
506-
{FLB_CONFIG_MAP_STR, "managed_identity_id", (char *)NULL, 0, FLB_TRUE,
507-
offsetof(struct flb_azure_kusto, managed_identity_id),
508-
"A managed identity id to authenticate with. "
506+
{FLB_CONFIG_MAP_STR, "managed_identity_client_id", (char *)NULL, 0, FLB_TRUE,
507+
offsetof(struct flb_azure_kusto, managed_identity_client_id),
508+
"A managed identity client id to authenticate with. "
509509
"Set to 'system' for system-assigned managed identity. "
510510
"Set the MI client ID (GUID) for user-assigned managed identity."},
511511
{FLB_CONFIG_MAP_STR, "ingestion_endpoint", (char *)NULL, 0, FLB_TRUE,

plugins/out_azure_kusto/azure_kusto.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ struct flb_azure_kusto {
6868
flb_sds_t tenant_id;
6969
flb_sds_t client_id;
7070
flb_sds_t client_secret;
71-
72-
/* A managed identity id to authenticate with.
73-
* Set to "system" for system-assigned managed identity.
74-
* Set the MI client ID (GUID) for user-assigned managed identity. */
75-
flb_sds_t managed_identity_id;
71+
flb_sds_t managed_identity_client_id;
7672
flb_sds_t ingestion_endpoint;
7773
flb_sds_t database_name;
7874
flb_sds_t table_name;

plugins/out_azure_kusto/azure_kusto_conf.c

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -602,27 +602,10 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
602602
return NULL;
603603
}
604604

605-
if (ctx->managed_identity_id == NULL) {
606-
/* config: 'tenant_id' */
607-
if (ctx->tenant_id == NULL) {
608-
flb_plg_error(ctx->ins, "property 'tenant_id' is not defined.");
609-
flb_azure_kusto_conf_destroy(ctx);
610-
return NULL;
611-
}
612-
613-
/* config: 'client_id' */
614-
if (ctx->client_id == NULL) {
615-
flb_plg_error(ctx->ins, "property 'client_id' is not defined");
616-
flb_azure_kusto_conf_destroy(ctx);
617-
return NULL;
618-
}
619-
620-
/* config: 'client_secret' */
621-
if (ctx->client_secret == NULL) {
622-
flb_plg_error(ctx->ins, "property 'client_secret' is not defined");
623-
flb_azure_kusto_conf_destroy(ctx);
624-
return NULL;
625-
}
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");
607+
flb_azure_kusto_conf_destroy(ctx);
608+
return NULL;
626609
}
627610

628611
/* config: 'ingestion_endpoint' */
@@ -646,20 +629,58 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance *
646629
return NULL;
647630
}
648631

649-
if (ctx->managed_identity_id != NULL) {
650-
ctx->oauth_url = flb_sds_create_size(sizeof(FLB_AZURE_MSIAUTH_URL_TEMPLATE) - 1 +
651-
flb_sds_len(ctx->managed_identity_id));
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);
652636

653-
if (!ctx->oauth_url) {
654-
flb_errno();
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, ctx->managed_identity_client_id);
660+
}
661+
}
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");
655680
flb_azure_kusto_conf_destroy(ctx);
656681
return NULL;
657682
}
658683

659-
flb_sds_snprintf(&ctx->oauth_url, flb_sds_alloc(ctx->oauth_url),
660-
FLB_AZURE_MSIAUTH_URL_TEMPLATE, ctx->managed_identity_id);
661-
}
662-
else {
663684
/* Create the auth URL */
664685
ctx->oauth_url = flb_sds_create_size(sizeof(FLB_MSAL_AUTH_URL_TEMPLATE) - 1 +
665686
flb_sds_len(ctx->tenant_id));

plugins/out_azure_kusto/azure_msiauth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/* MSAL authorization URL */
2323
#define FLB_AZURE_MSIAUTH_URL_TEMPLATE \
24-
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2021-02-01&client_id=%s&resource=https://api.kusto.windows.net"
24+
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2021-02-01%s&resource=https://api.kusto.windows.net"
2525

2626
char *flb_azure_msiauth_token_get(struct flb_oauth2 *ctx);
2727

0 commit comments

Comments
 (0)