-
Notifications
You must be signed in to change notification settings - Fork 1.9k
azure_kusto: Added support for region-based(Global and China cloud) authentication for Azure Kusto #11395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
azure_kusto: Added support for region-based(Global and China cloud) authentication for Azure Kusto #11395
Changes from all commits
d880763
6185e2b
7e65d49
cbfaf63
e9057b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,20 @@ | |
| #include "azure_kusto_conf.h" | ||
| #include "azure_msiauth.h" | ||
|
|
||
| /* Cloud helpers: resolve MSAL auth URL template and Kusto scope/IMDS resource */ | ||
| static const char *get_msal_auth_url_template(int cloud_env) | ||
| { | ||
| if (cloud_env == FLB_AZURE_CLOUD_CHINA) { | ||
| return FLB_MSAL_AUTH_URL_TEMPLATE_CHINA; | ||
| } | ||
| return FLB_MSAL_AUTH_URL_TEMPLATE_GLOBAL; | ||
| } | ||
|
|
||
| static const char *get_imds_resource(int cloud_env) | ||
| { | ||
| return flb_azure_kusto_get_imds_resource(cloud_env); | ||
| } | ||
|
|
||
| /* Constants for PCG random number generator */ | ||
| #define PCG_DEFAULT_MULTIPLIER_64 6364136223846793005ULL | ||
| #define PCG_DEFAULT_INCREMENT_64 1442695040888963407ULL | ||
|
|
@@ -782,6 +796,12 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance * | |
| return NULL; | ||
| } | ||
|
|
||
| /* Determine cloud environment dynamically from ingestion_endpoint */ | ||
| ctx->cloud_environment = FLB_AZURE_CLOUD_GLOBAL; /* default */ | ||
| if (ctx->ingestion_endpoint && strstr(ctx->ingestion_endpoint, "chinacloudapi.cn") != NULL) { | ||
| ctx->cloud_environment = FLB_AZURE_CLOUD_CHINA; | ||
| } | ||
|
|
||
| /* config: 'database_name' */ | ||
| if (ctx->database_name == NULL) { | ||
| flb_plg_error(ctx->ins, "property 'database_name' is not defined"); | ||
|
|
@@ -800,40 +820,47 @@ struct flb_azure_kusto *flb_azure_kusto_conf_create(struct flb_output_instance * | |
| if (ctx->auth_type == FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_SYSTEM || | ||
| ctx->auth_type == FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_USER) { | ||
| /* MSI auth */ | ||
| const char *imds_resource; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to define this variable on top of this function scope, too. |
||
|
|
||
| imds_resource = get_imds_resource(ctx->cloud_environment); | ||
|
|
||
| /* Construct the URL template with or without client_id for managed identity */ | ||
| if (ctx->auth_type == FLB_AZURE_KUSTO_AUTH_MANAGED_IDENTITY_SYSTEM) { | ||
| ctx->oauth_url = flb_sds_create_size(sizeof(FLB_AZURE_MSIAUTH_URL_TEMPLATE) - 1); | ||
| ctx->oauth_url = flb_sds_create_size(strlen(FLB_AZURE_MSIAUTH_URL_TEMPLATE) + strlen(imds_resource) + 1); | ||
| if (!ctx->oauth_url) { | ||
| flb_errno(); | ||
| flb_azure_kusto_conf_destroy(ctx); | ||
| return NULL; | ||
| } | ||
| flb_sds_snprintf(&ctx->oauth_url, flb_sds_alloc(ctx->oauth_url), | ||
| FLB_AZURE_MSIAUTH_URL_TEMPLATE, "", ""); | ||
| FLB_AZURE_MSIAUTH_URL_TEMPLATE, | ||
| "", "", imds_resource); | ||
| } else { | ||
| /* User-assigned managed identity */ | ||
| ctx->oauth_url = flb_sds_create_size(sizeof(FLB_AZURE_MSIAUTH_URL_TEMPLATE) - 1 + | ||
| sizeof("&client_id=") - 1 + | ||
| flb_sds_len(ctx->client_id)); | ||
| ctx->oauth_url = flb_sds_create_size(strlen(FLB_AZURE_MSIAUTH_URL_TEMPLATE) + | ||
| strlen("&client_id=") + | ||
| flb_sds_len(ctx->client_id) + | ||
| strlen(imds_resource) + 1); | ||
| if (!ctx->oauth_url) { | ||
| flb_errno(); | ||
| flb_azure_kusto_conf_destroy(ctx); | ||
| return NULL; | ||
| } | ||
| flb_sds_snprintf(&ctx->oauth_url, flb_sds_alloc(ctx->oauth_url), | ||
| FLB_AZURE_MSIAUTH_URL_TEMPLATE, "&client_id=", ctx->client_id); | ||
| FLB_AZURE_MSIAUTH_URL_TEMPLATE, | ||
| "&client_id=", ctx->client_id, imds_resource); | ||
| } | ||
| } else { | ||
| /* Standard OAuth2 for service principal or workload identity */ | ||
| ctx->oauth_url = flb_sds_create_size(sizeof(FLB_MSAL_AUTH_URL_TEMPLATE) - 1 + | ||
| flb_sds_len(ctx->tenant_id)); | ||
| const char *tmpl = get_msal_auth_url_template(ctx->cloud_environment); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. E.g.) const char *auth_url_tmpl;would be better. |
||
| ctx->oauth_url = flb_sds_create_size(strlen(tmpl) + flb_sds_len(ctx->tenant_id) + 1); | ||
| if (!ctx->oauth_url) { | ||
| flb_errno(); | ||
| flb_azure_kusto_conf_destroy(ctx); | ||
| return NULL; | ||
| } | ||
| flb_sds_snprintf(&ctx->oauth_url, flb_sds_alloc(ctx->oauth_url), | ||
| FLB_MSAL_AUTH_URL_TEMPLATE, ctx->tenant_id); | ||
| tmpl, ctx->tenant_id); | ||
| } | ||
|
|
||
| ctx->resources = flb_calloc(1, sizeof(struct flb_azure_kusto_resources)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| #include <fluent-bit/flb_http_client.h> | ||
|
|
||
| #include "azure_msiauth.h" | ||
| #include "azure_kusto.h" | ||
|
|
||
| char *flb_azure_msiauth_token_get(struct flb_oauth2 *ctx) | ||
| { | ||
|
|
@@ -176,7 +177,16 @@ int flb_azure_workload_identity_token_get(struct flb_oauth2 *ctx, const char *to | |
| body = flb_sds_cat(body, "&client_assertion=", 18); | ||
| body = flb_sds_cat(body, federated_token, flb_sds_len(federated_token)); | ||
| /* Use the correct scope and length for Kusto */ | ||
| body = flb_sds_cat(body, "&scope=https://help.kusto.windows.net/.default", 46); | ||
| { | ||
| int cloud_env = FLB_AZURE_CLOUD_GLOBAL; | ||
| if ((ctx->host && strstr(ctx->host, "chinacloudapi.cn") != NULL) || | ||
| (ctx->uri && strstr(ctx->uri, "chinacloudapi.cn") != NULL)) { | ||
| cloud_env = FLB_AZURE_CLOUD_CHINA; | ||
| } | ||
| const char *scope = flb_azure_kusto_get_scope(cloud_env); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to define this variable on top of |
||
| body = flb_sds_cat(body, "&scope=", 7); | ||
| body = flb_sds_cat(body, scope, strlen(scope)); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (!body) { | ||
| /* This check might be redundant if flb_sds_cat handles errors, but safe */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you define this variable on top of this function?
This is because we still need to compile CentOS7 and gcc4.2.
This coding style causes compilation error(s) in that platform.