Skip to content

Commit c2caad6

Browse files
out_azure_logs_ingestion: safeguard against null auth_type
Fail fast in case auth_type is null, and default to "service_principal" if empty. Defer the assignment of the context after all validation of configuration has taken place. Signed-off-by: Stefano Boriero <[email protected]>
1 parent a3ab629 commit c2caad6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

plugins/out_azure_logs_ingestion/azure_logs_ingestion_conf.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
4242
return NULL;
4343
}
4444

45-
/* Set the conext in output_instance so that we can retrieve it later */
45+
/* Set the context in output_instance so that we can retrieve it later */
4646
ctx->ins = ins;
4747
ctx->config = config;
48-
/* Set context */
49-
flb_output_set_context(ins, ctx);
5048

5149
/* Load config map */
5250
ret = flb_output_config_map_set(ins, (void *) ctx);
@@ -56,7 +54,18 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
5654
}
5755

5856
/* Auth method validation and setup */
59-
if (strcasecmp(ctx->auth_type_str, "service_principal") == 0) {
57+
if (!ctx->auth_type_str || strlen(ctx->auth_type_str) == 0) {
58+
/* Default to service_principal if auth_type_str is NULL or empty */
59+
ctx->auth_type = FLB_AZ_LI_AUTH_SERVICE_PRINCIPAL;
60+
61+
/* Verify required parameters for Service Principal auth */
62+
if (!ctx->tenant_id || !ctx->client_id || !ctx->client_secret) {
63+
flb_plg_error(ins, "When using service_principal auth, tenant_id, client_id, and client_secret are required");
64+
flb_az_li_ctx_destroy(ctx);
65+
return NULL;
66+
}
67+
}
68+
else if (strcasecmp(ctx->auth_type_str, "service_principal") == 0) {
6069
ctx->auth_type = FLB_AZ_LI_AUTH_SERVICE_PRINCIPAL;
6170

6271
/* Verify required parameters for Service Principal auth */
@@ -182,6 +191,9 @@ struct flb_az_li* flb_az_li_ctx_create(struct flb_output_instance *ins,
182191
flb_plg_info(ins, "dce_url='%s', dcr='%s', table='%s', stream='Custom-%s'",
183192
ctx->dce_url, ctx->dcr_id, ctx->table_name, ctx->table_name);
184193

194+
/* Set context only after all validation and initialization is complete */
195+
flb_output_set_context(ins, ctx);
196+
185197
return ctx;
186198
}
187199

0 commit comments

Comments
 (0)