Skip to content

out_azure_blob: add service principal auth#11889

Open
Vaibhav-C-S wants to merge 4 commits into
fluent:masterfrom
Vaibhav-C-S:out-azure-blob-service-principal
Open

out_azure_blob: add service principal auth#11889
Vaibhav-C-S wants to merge 4 commits into
fluent:masterfrom
Vaibhav-C-S:out-azure-blob-service-principal

Conversation

@Vaibhav-C-S
Copy link
Copy Markdown

@Vaibhav-C-S Vaibhav-C-S commented Jun 1, 2026

Summary

This PR adds focused service principal authentication support for the Azure Blob output plugin.

It supports Microsoft Entra ID client credentials authentication for Azure public cloud using the default authority host:

https://login.microsoftonline.com

Related


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
[SERVICE]
    Flush        1
    Daemon       Off
    Log_Level    debug

[INPUT]
    Name   dummy
    Tag    test
    Dummy  {"message": "hello from azure service principal test"}
    Rate   1

[OUTPUT]
    Name                  azure_blob
    Match                 *
    account_name           <redacted>
    container_name        <redacted>
    auth_type             service_principal
    tenant_id             <redacted>
    client_id             <redacted>
    client_secret         <redacted>
    tls                   On
    auto_create_container Off



  • Debug log output from testing the change
/01 15:36:18.533] [debug] [output:azure_blob:azure_blob.0] http_send_blob()=1
[2026/06/01 15:36:18.533] [debug] [out flush] cb_destroy coro_id=261
[2026/06/01 15:36:18.533] [debug] [task] destroy task=0x1348042f0 (task_id=0)
[2026/06/01 15:36:19.253] [debug] [task] created task=0x14472f690 id=0 OK
[2026/06/01 15:36:19.253] [debug] [output:azure_blob:azure_blob.0] task_id=0 assigned to thread #0
[2026/06/01 15:36:19.253] [ info] [output:azure_blob:azure_blob.0] auto_create_container is disabled, assuming container '<redacted>' already exists
[2026/06/01 15:36:19.253] [debug] [output:azure_blob:azure_blob.0] generated blob uri ::: /<redacted>/test?comp=appendblock
[2026/06/01 15:36:19.253] [debug] [upstream] KA connection #47 to <redacted>:443 has been assigned (recycled)
[2026/06/01 15:36:19.254] [debug] [http_client] not using http_proxy for header
[2026/06/01 15:36:19.532] [ info] [output:azure_blob:azure_blob.0] content uploaded successfully: 
[2026/06/01 15:36:19.532] [debug] [upstream] KA connection #47 to <redacted>:443 is now available
[2026/06/01 15:36:19.532] [debug] [output:azure_blob:azure_blob.0] http_send_blob()=1
  • Attached Valgrind output that shows no leaks or memory corruption was found
valgrind \
  --tool=memcheck \
  --leak-check=full \
  --show-leak-kinds=all \
  --track-origins=yes \
  --num-callers=30 \
  --log-file=/src/valgrind-azure-blob-test.log \
  ./bin/fluent-bit -c /tmp/azure-blob-test.conf

Result:

HEAP SUMMARY:
    in use at exit: 0 bytes in 0 blocks
  total heap usage: 36,391 allocs, 36,391 frees, 21,674,540 bytes allocated

All heap blocks were freed -- no leaks are possible

ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • New Features

    • Service Principal authentication for Azure Blob output (tenant_id, client_id, client_secret)
    • OAuth2 token management with automatic refresh; TLS is required for this auth mode
  • Bug Fixes

    • Improved HTTP setup and upload error handling with explicit cleanup and safer startup/shutdown
  • Documentation

    • auth_type help text updated to include service_principal and stronger validation messages

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 676791b6-ff26-480f-931d-2e9199ffc656

📥 Commits

Reviewing files that changed from the base of the PR and between 27acbc4 and 2fd82e9.

📒 Files selected for processing (1)
  • plugins/out_azure_blob/azure_blob.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/out_azure_blob/azure_blob.c

📝 Walkthrough

Walkthrough

Adds service-principal OAuth2 auth and thread‑safe token handling, integrates Authorization header into HTTP client setup, and adds explicit error handling for azb_http_client_setup() failures across Azure Blob request helpers.

Changes

Service Principal OAuth2 Authentication

Layer / File(s) Summary
Data Model and OAuth2 Defaults
plugins/out_azure_blob/azure_blob.h
Adds OAuth2 include, defines AZURE_BLOB_AUTH_SERVICE_PRINCIPAL and OAuth2 defaults, and extends flb_azure_blob with tenant/client credential fields plus OAuth2 runtime state and a token mutex.
OAuth2 Token and Authorization Header Handling
plugins/out_azure_blob/azure_blob_http.c
Implements OAuth2 client‑credentials payload and token retrieval, mutex‑protected refresh on expiry, builds Authorization: <token_type> <access_token> SDS, and integrates this header into HTTP client setup for service‑principal requests.
Configuration Parsing, Validation, and Resource Cleanup
plugins/out_azure_blob/azure_blob_conf.c, plugins/out_azure_blob/azure_blob.c
Parses auth_type=service_principal, requires tenant_id, client_id, and client_secret, enforces TLS, updates auth_type help text and config entries, and destroys OAuth2 resources on config/plugin destroy.
Plugin Initialization and HTTP client setup checks
plugins/out_azure_blob/azure_blob.c, plugins/out_azure_blob/azure_blob_blockblob.c
Assigns plugin instance earlier, initializes token mutex and tenant‑scoped OAuth2 context in cb_azure_blob_init, conditionally destroys the token mutex in cb_azure_blob_exit, and adds return/cleanup handling when azb_http_client_setup() fails in multiple request helpers (create/delete/send container, ensure container, put block list).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • edsiper
  • cosmo0920

Poem

🐰 I nibbled headers through the night,

mutex snug and tokens bright.
Client creds hum, the handshake sings,
Authorization flaps its wings.
Azure blobs now hop in light.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'out_azure_blob: add service principal auth' clearly and concisely describes the main objective of the changeset: adding service principal authentication support to the Azure Blob output plugin.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
plugins/out_azure_blob/azure_blob.c

plugins/out_azure_blob/azure_blob.c:20:10: fatal error: 'fluent-bit/flb_output_plugin.h' file not found
20 | #include <fluent-bit/flb_output_plugin.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/2fd82e9d8f468a664a0d14ec438f6637c4c2d36a-f844d79a27a0ee27/tmp/clang_command_.tmp.7bfbf3.txt
++Contents of '/tmp/coderabbit-infer/2fd82e9d8f468a664a0d14ec438f6637c4c2d36a-f844d79a27a0ee27/tmp/clang_command_.tmp.7bfbf3.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_6

... [truncated 778 characters] ...

x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/f844d79a27a0ee27/file.o" "-x" "c"
"plugins/out_azure_blob/azure_blob.c" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68ab3396b7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


ret = flb_oauth2_payload_append(ctx->o,
"client_secret", 13,
ctx->client_secret, -1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Encode OAuth2 form values before requesting tokens

When an Azure service principal secret contains form-reserved characters such as +, %, or &, this sends the raw secret in an application/x-www-form-urlencoded OAuth2 body. flb_oauth2_payload_append() only concatenates key=value pairs (unlike the config-based OAuth2 builder in src/flb_oauth2.c, which URI-encodes values), so Azure AD will parse a different client_secret and reject token acquisition for valid generated secrets. Percent-encode these values or use the OAuth2 config path that encodes them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch,
azure client secret document mentions client secret is a combination of only

If changes are further required and we have to use config-based OAuth2 builder , we can make those changes.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/out_azure_blob/azure_blob_conf.c`:
- Around line 620-621: The remote config is applied before the auth_type is
parsed so flb_azure_blob_apply_remote_configuration(ctx) sees ctx->atype == 0
and mis-handles service_principal; move the auth_type parsing (the strcasecmp
branch that sets ctx->atype = AZURE_BLOB_AUTH_SERVICE_PRINCIPAL) to run before
calling flb_azure_blob_apply_remote_configuration(ctx), or alternatively modify
flb_azure_blob_apply_remote_configuration to accept the raw auth_type property
and use that when deciding branches; update the code paths that reference
ctx->atype (and any callers expecting the parsed value) to rely on the parsed
value being set first.
- Around line 646-659: The service-principal validation only checks for NULLs;
update the AZURE_BLOB_AUTH_SERVICE_PRINCIPAL branch to also reject empty strings
by using flb_sds_len(...) == 0 for ctx->tenant_id, ctx->client_id, and
ctx->client_secret (in addition to the existing NULL checks), and call
flb_plg_error with the same clear messages when any of those values are empty so
startup fails fast with a helpful error; reference ctx, ctx->atype,
AZURE_BLOB_AUTH_SERVICE_PRINCIPAL, tenant_id, client_id, client_secret, and
flb_sds_len in your changes.

In `@plugins/out_azure_blob/azure_blob_http.c`:
- Around line 485-490: The call sites that invoke azb_http_client_setup (and the
branch that now returns non-zero from azb_get_oauth2_authorization_header) must
check the function return value and abort the operation on any non-zero result;
update callers in azure_blob.c where azb_http_client_setup is used to test its
return and immediately return/propagate an error (do not continue the request
without Authorization). Locate azb_http_client_setup and the code paths that
handle AZURE_BLOB_AUTH_SERVICE_PRINCIPAL (and any callers that previously
ignored the result) and change them to bail out on non-zero return codes so
token refresh failures are surfaced to the caller.

In `@plugins/out_azure_blob/azure_blob.c`:
- Around line 1420-1446: The OAuth2 service-principal init paths leak resources
and skip full teardown; ensure every early exit funnels to the central cleanup
(call flb_azure_blob_conf_destroy(ctx)) and also properly destroys the mutex
created by pthread_mutex_init(&ctx->token_mutex, NULL) and frees token_url
(flb_sds_destroy) before cleanup: on token_url allocation failure, on
flb_sds_snprintf failure, and when flb_oauth2_create returns NULL, release
token_url if allocated, call pthread_mutex_destroy(&ctx->token_mutex) if
initialized, then call flb_azure_blob_conf_destroy(ctx) and return error; keep
the successful path unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0fe197e1-4afd-4e21-b415-515a8e343144

📥 Commits

Reviewing files that changed from the base of the PR and between 19cc8f9 and 68ab339.

📒 Files selected for processing (4)
  • plugins/out_azure_blob/azure_blob.c
  • plugins/out_azure_blob/azure_blob.h
  • plugins/out_azure_blob/azure_blob_conf.c
  • plugins/out_azure_blob/azure_blob_http.c

Comment thread plugins/out_azure_blob/azure_blob_conf.c Outdated
Comment thread plugins/out_azure_blob/azure_blob_conf.c
Comment thread plugins/out_azure_blob/azure_blob_http.c
Comment thread plugins/out_azure_blob/azure_blob.c
Signed-off-by: Cheruvu.Sahithee.Vaibhav@ibm.com <Cheruvu.Sahithee.Vaibhav@ibm.com>
@Vaibhav-C-S Vaibhav-C-S force-pushed the out-azure-blob-service-principal branch from 68ab339 to 0eba4c2 Compare June 1, 2026 16:07
Signed-off-by: Cheruvu.Sahithee.Vaibhav@ibm.com <Cheruvu.Sahithee.Vaibhav@ibm.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
plugins/out_azure_blob/azure_blob_blockblob.c (1)

323-329: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Release the client and connection before retrying on send errors.

The ret == -1 branch returns without flb_http_client_destroy(c) or flb_upstream_conn_release(u_conn). In retry paths, that leaks both objects.

Suggested fix
     if (ret == -1) {
         flb_plg_error(ctx->ins, "error sending block_blob");
+        flb_http_client_destroy(c);
+        flb_upstream_conn_release(u_conn);
         return FLB_RETRY;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/out_azure_blob/azure_blob_blockblob.c` around lines 323 - 329, The
error path after flb_http_do(c, &b_sent) currently returns FLB_RETRY without
releasing resources; modify the ret == -1 branch to first call
flb_http_client_destroy(c) and flb_upstream_conn_release(u_conn) (or the
appropriate destroy/release helpers used elsewhere in this file) before logging
and returning FLB_RETRY so the HTTP client (c) and upstream connection (u_conn)
are always cleaned up on send errors.
plugins/out_azure_blob/azure_blob.c (2)

1365-1372: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Destroy the HTTP client on container-check send failures.

The ret == -1 branch releases u_conn but never destroys c. Since ensure_container() can run on every flush, repeated transport failures will leak clients.

Suggested fix
     if (ret == -1) {
         flb_plg_error(ctx->ins, "error requesting container properties");
+        flb_http_client_destroy(c);
         flb_upstream_conn_release(u_conn);
         return FLB_FALSE;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/out_azure_blob/azure_blob.c` around lines 1365 - 1372, The
error-handling path after flb_http_do(c, &b_sent) leaks the HTTP client `c` on
transport failures; in the `ret == -1` branch (inside
ensure_container()/container-check), call the HTTP client destructor
(flb_http_client_destroy(c)) before releasing the upstream connection `u_conn`
(flb_upstream_conn_release(u_conn)) and returning FLB_FALSE so the client is not
repeatedly leaked on flush failures.

1454-1455: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Check pthread_mutex_init() return code and fix ensure_container() client cleanup on flb_http_do() failure

  • cb_azure_blob_init() doesn’t check pthread_mutex_init(&ctx->token_mutex, NULL);—if it fails, later code may use an uninitialized mutex; fail fast and reuse existing teardown.

    Suggested fix
        if (ctx->atype == AZURE_BLOB_AUTH_SERVICE_PRINCIPAL) {
    -        pthread_mutex_init(&ctx->token_mutex, NULL);
    +        if (pthread_mutex_init(&ctx->token_mutex, NULL) != 0) {
    +            flb_plg_error(ctx->ins, "failed to initialize token mutex");
    +            flb_azure_blob_conf_destroy(ctx);
    +            return -1;
    +        }
            flb_sds_t token_url;
        ```
    </details>
  • ensure_container() returns FLB_FALSE on flb_http_do(c, &b_sent) transport failure without calling flb_http_client_destroy(c), leaking the HTTP client; destroy c before returning.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/out_azure_blob/azure_blob.c` around lines 1454 - 1455, In
cb_azure_blob_init(), check the return value of
pthread_mutex_init(&ctx->token_mutex, NULL) and on failure clean up any
partially-initialized resources and return an error (match existing teardown
path) so the uninitialized ctx->token_mutex is never used; in
ensure_container(), if flb_http_do(c, &b_sent) fails, call
flb_http_client_destroy(c) before returning FLB_FALSE to avoid leaking the HTTP
client—ensure the cleanup path covers both success and failure branches and
reference the local HTTP client variable c and ctx->token_mutex when applying
these fixes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/out_azure_blob/azure_blob_blockblob.c`:
- Around line 313-320: azb_block_blob_put_block_list() is now returning
FLB_RETRY on HTTP setup failure which cb_azb_blob_file_upload() does not treat
as an error, leading to transient failures being treated as successful commits;
either make azb_block_blob_put_block_list() return the existing failure sentinel
(-1) for unrecoverable/failed commit paths (including when azb_http_client_setup
fails) or update cb_azb_blob_file_upload() to treat FLB_RETRY from
azb_block_blob_commit_file_parts()/azb_block_blob_put_block_list() as a failure
(same handling as -1) so it does not log success or delete the buffered file on
transient setup/auth errors. Ensure the change references
azb_block_blob_put_block_list, azb_block_blob_commit_file_parts, and
cb_azb_blob_file_upload so callers consistently interpret FLB_RETRY as an error
condition.

---

Outside diff comments:
In `@plugins/out_azure_blob/azure_blob_blockblob.c`:
- Around line 323-329: The error path after flb_http_do(c, &b_sent) currently
returns FLB_RETRY without releasing resources; modify the ret == -1 branch to
first call flb_http_client_destroy(c) and flb_upstream_conn_release(u_conn) (or
the appropriate destroy/release helpers used elsewhere in this file) before
logging and returning FLB_RETRY so the HTTP client (c) and upstream connection
(u_conn) are always cleaned up on send errors.

In `@plugins/out_azure_blob/azure_blob.c`:
- Around line 1365-1372: The error-handling path after flb_http_do(c, &b_sent)
leaks the HTTP client `c` on transport failures; in the `ret == -1` branch
(inside ensure_container()/container-check), call the HTTP client destructor
(flb_http_client_destroy(c)) before releasing the upstream connection `u_conn`
(flb_upstream_conn_release(u_conn)) and returning FLB_FALSE so the client is not
repeatedly leaked on flush failures.
- Around line 1454-1455: In cb_azure_blob_init(), check the return value of
pthread_mutex_init(&ctx->token_mutex, NULL) and on failure clean up any
partially-initialized resources and return an error (match existing teardown
path) so the uninitialized ctx->token_mutex is never used; in
ensure_container(), if flb_http_do(c, &b_sent) fails, call
flb_http_client_destroy(c) before returning FLB_FALSE to avoid leaking the HTTP
client—ensure the cleanup path covers both success and failure branches and
reference the local HTTP client variable c and ctx->token_mutex when applying
these fixes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33091bc1-d351-4b3f-aaad-4a9d05e4f0e5

📥 Commits

Reviewing files that changed from the base of the PR and between 0eba4c2 and d673b96.

📒 Files selected for processing (3)
  • plugins/out_azure_blob/azure_blob.c
  • plugins/out_azure_blob/azure_blob_blockblob.c
  • plugins/out_azure_blob/azure_blob_conf.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/out_azure_blob/azure_blob_conf.c

Comment thread plugins/out_azure_blob/azure_blob_blockblob.c
Signed-off-by: Cheruvu.Sahithee.Vaibhav@ibm.com <Cheruvu.Sahithee.Vaibhav@ibm.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
plugins/out_azure_blob/azure_blob.c (2)

1244-1252: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Free uri on flb_http_client() failures.

Line 1248 and Line 1347 return after flb_http_client() fails, but both helpers have already allocated uri. Under repeated setup failures that leaks one SDS per attempt.

Suggested fix
     c = flb_http_client(u_conn, FLB_HTTP_PUT,
                         uri,
                         NULL, 0, NULL, 0, NULL, 0);
     if (!c) {
         flb_plg_error(ctx->ins, "cannot create HTTP client context");
+        flb_sds_destroy(uri);
         flb_upstream_conn_release(u_conn);
         return FLB_FALSE;
     }
     c = flb_http_client(u_conn, FLB_HTTP_GET,
                         uri,
                         NULL, 0, NULL, 0, NULL, 0);
     if (!c) {
         flb_plg_error(ctx->ins, "cannot create HTTP client context");
+        flb_sds_destroy(uri);
         flb_upstream_conn_release(u_conn);
         return FLB_FALSE;
     }

Also applies to: 1343-1351

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/out_azure_blob/azure_blob.c` around lines 1244 - 1252, The code
returns on flb_http_client() failure after allocating the SDS uri, leaking
memory; update both failure paths where c is NULL (the HTTP client creation
blocks that set c via flb_http_client) to free/destroy the allocated uri before
calling flb_plg_error/flb_upstream_conn_release and returning (use the
appropriate SDS free function, e.g., flb_sds_destroy or flb_sds_free). Ensure
you apply this fix in both occurrences around the flb_http_client() calls that
check if (!c) so uri is always freed on error.

1424-1491: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Unwind buffering state on all post-store init failures.

Once Line 1428 succeeds, the returns in Lines 1429-1446 and the new OAuth2 failure paths in Lines 1456-1491 bypass azure_blob_store_exit(ctx). cb_azure_blob_exit() already shows that store teardown is separate from flb_azure_blob_conf_destroy(ctx), so these init failures can leave the buffering store partially initialized.

Suggested cleanup pattern
 static int cb_azure_blob_init(struct flb_output_instance *ins,
                               struct flb_config *config, void *data)
 {
     int ret;
+    int store_initialized = FLB_FALSE;
+    int token_mutex_initialized = FLB_FALSE;
     struct flb_azure_blob *ctx = NULL;
+    flb_sds_t token_url = NULL;
     (void) ins;
     (void) config;
     (void) data;
@@
     if (ctx->buffering_enabled == FLB_TRUE) {
         ctx->retry_time = 0;
 
         /* Initialize local storage */
-        int ret = azure_blob_store_init(ctx);
+        ret = azure_blob_store_init(ctx);
         if (ret == -1) {
             flb_plg_error(ctx->ins, "Failed to initialize kusto storage: %s",
                           ctx->store_dir);
-            return -1;
+            goto init_error;
         }
+        store_initialized = FLB_TRUE;
@@
         if (ctx->file_size <= 0) {
             flb_plg_error(ctx->ins, "Failed to parse upload_file_size");
-            return -1;
+            goto init_error;
         }
         if (ctx->file_size < 1000000) {
             flb_plg_error(ctx->ins, "upload_file_size must be at least 1MB");
-            return -1;
+            goto init_error;
         }
         if (ctx->file_size > MAX_FILE_SIZE) {
             flb_plg_error(ctx->ins, "Max total_file_size must be lower than %ld bytes", MAX_FILE_SIZE);
-            return -1;
+            goto init_error;
         }
@@
     if (ctx->atype == AZURE_BLOB_AUTH_SERVICE_PRINCIPAL) {
         ret = pthread_mutex_init(&ctx->token_mutex, NULL);
         if (ret != 0) {
             flb_plg_error(ctx->ins, "failed to initialize token mutex");
-            flb_azure_blob_conf_destroy(ctx);
-            return -1;
+            goto init_error;
         }
+        token_mutex_initialized = FLB_TRUE;
 
-        flb_sds_t token_url;
-
         token_url = flb_sds_create_size(256);
         if (!token_url) {
             flb_plg_error(ctx->ins, "failed to allocate token URL");
-            pthread_mutex_destroy(&ctx->token_mutex);
-            flb_azure_blob_conf_destroy(ctx);
-            return -1;
+            goto init_error;
         }
@@
         if (ret < 0) {
             flb_plg_error(ctx->ins, "failed to build token URL");
-            flb_sds_destroy(token_url);
-            pthread_mutex_destroy(&ctx->token_mutex);
-            flb_azure_blob_conf_destroy(ctx);
-            return -1;
+            goto init_error;
         }
@@
         if (!ctx->o) {
             flb_plg_error(ctx->ins, "failed to create OAuth2 context");
-            pthread_mutex_destroy(&ctx->token_mutex);
-            flb_azure_blob_conf_destroy(ctx);
-            return -1;
+            goto init_error;
         }
     }
@@
     flb_output_set_http_debug_callbacks(ins);
     return 0;
+
+init_error:
+    if (token_url != NULL) {
+        flb_sds_destroy(token_url);
+    }
+    if (token_mutex_initialized == FLB_TRUE) {
+        pthread_mutex_destroy(&ctx->token_mutex);
+    }
+    if (store_initialized == FLB_TRUE) {
+        azure_blob_store_exit(ctx);
+    }
+    flb_azure_blob_conf_destroy(ctx);
+    return -1;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/out_azure_blob/azure_blob.c` around lines 1424 - 1491, The buffering
store is initialized by azure_blob_store_init(ctx) when ctx->buffering_enabled
is true but some subsequent failure paths (file_size validation and OAuth2 setup
branches) return without calling azure_blob_store_exit(ctx), leaving the store
partially initialized; update all failure returns after azure_blob_store_init
succeeds to call azure_blob_store_exit(ctx) before destroying config or
returning (specifically add azure_blob_store_exit(ctx) in the file_size
validation error returns and in each OAuth2 failure path after
pthread_mutex_init/ flb_sds_create_size/ flb_sds_snprintf/ flb_oauth2_create
failures, prior to calling pthread_mutex_destroy and
flb_azure_blob_conf_destroy(ctx) or returning).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@plugins/out_azure_blob/azure_blob.c`:
- Around line 1244-1252: The code returns on flb_http_client() failure after
allocating the SDS uri, leaking memory; update both failure paths where c is
NULL (the HTTP client creation blocks that set c via flb_http_client) to
free/destroy the allocated uri before calling
flb_plg_error/flb_upstream_conn_release and returning (use the appropriate SDS
free function, e.g., flb_sds_destroy or flb_sds_free). Ensure you apply this fix
in both occurrences around the flb_http_client() calls that check if (!c) so uri
is always freed on error.
- Around line 1424-1491: The buffering store is initialized by
azure_blob_store_init(ctx) when ctx->buffering_enabled is true but some
subsequent failure paths (file_size validation and OAuth2 setup branches) return
without calling azure_blob_store_exit(ctx), leaving the store partially
initialized; update all failure returns after azure_blob_store_init succeeds to
call azure_blob_store_exit(ctx) before destroying config or returning
(specifically add azure_blob_store_exit(ctx) in the file_size validation error
returns and in each OAuth2 failure path after pthread_mutex_init/
flb_sds_create_size/ flb_sds_snprintf/ flb_oauth2_create failures, prior to
calling pthread_mutex_destroy and flb_azure_blob_conf_destroy(ctx) or
returning).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 70b487f2-e363-4598-afb0-234a0b3c6958

📥 Commits

Reviewing files that changed from the base of the PR and between d673b96 and 27acbc4.

📒 Files selected for processing (2)
  • plugins/out_azure_blob/azure_blob.c
  • plugins/out_azure_blob/azure_blob_blockblob.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/out_azure_blob/azure_blob_blockblob.c

Signed-off-by: Cheruvu.Sahithee.Vaibhav@ibm.com <Cheruvu.Sahithee.Vaibhav@ibm.com>
@Vaibhav-C-S
Copy link
Copy Markdown
Author

@cosmo0920 @edsiper Could you please review this PR when you have time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant