Skip to content

Fix authorization_endpoint_url for blob uploads#11436

Open
agup006 wants to merge 3 commits intofluent:masterfrom
agup006:fix-authorization-endpoint-url
Open

Fix authorization_endpoint_url for blob uploads#11436
agup006 wants to merge 3 commits intofluent:masterfrom
agup006:fix-authorization-endpoint-url

Conversation

@agup006
Copy link
Member

@agup006 agup006 commented Feb 6, 2026

Summary

This PR fixes several issues with the authorization_endpoint_url feature for blob uploads:

  • Port validation: Changed from error to debug log when presigned URL uses a different port than configured. When using an authorization endpoint, the presigned URL is to a different server, so port validation doesn't make sense.

  • Keepalive connection reuse: Disabled keepalive when switching hosts to force new connections. Previously, keepalive connections bound to the original endpoint would be reused, causing requests to go to the wrong server.

  • TLS handling: Disabled TLS for HTTP (port 80) presigned URLs. The auth endpoint may return HTTP URLs which require non-TLS connections.

  • Wrong endpoint URL: Fixed blob_fetch_multipart_abort_pre_signed_url which was incorrectly using /multipart_upload_presigned_url/ instead of /multipart_abort_presigned_url/.

Test Plan

  • Tested multipart upload with authorization endpoint server
  • Verified all parts upload successfully to S3
  • Verified CompleteMultipartUpload works correctly

Fixes issues identified in #11246

Summary by CodeRabbit

Release Notes

  • New Features

    • Added presigned URL support to the S3 plugin, enabling seamless integration with authorization endpoints for secure object uploads.
  • Improvements

    • Enhanced multipart upload operations to handle presigned URLs with port awareness and connection management.
    • Improved error handling and resource cleanup across S3 operations to ensure proper state restoration.

edsiper and others added 3 commits December 2, 2025 17:07
When using pre-signed URLs for blob uploads via authorization_endpoint_url),
the plugin didn't extract or use the host from the pre-signed URL. It treated
the URL as a URI path, so requests went to the wrong host or failed.

This patch added s3_parse_presigned_url() to parse pre-signed URLs and extract
host, URI, and port Updated put_blob_object(), complete_multipart_upload(),
and abort_multipart_upload() to:

- Extract the host from the pre-signed URL
- Temporarily set ctx->s3_client->host to the extracted host
- Validate the port matches the configuration
- Restore the original host after the request

Now blob uploads using pre-signed URLs now correctly use the host specified in
the URL instead of the default S3 client host.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
- Presigned multipart uploads now temporarily override both the S3 client host and upstream
  target when using authorization-generated URLs, ensuring each multipart operation connects
  to the correct presigned endpoint before restoring the original settings.

- Presigned single-part blob uploads likewise update the upstream host/port while the
  presigned URL is in use so requests are sent to the right destination.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
- Change port validation from error to debug log when using auth endpoint
- Disable keepalive when switching hosts to force new connections
- Disable TLS for HTTP (port 80) presigned URLs
- Fix blob_fetch_multipart_abort_pre_signed_url using wrong endpoint URL
@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

The changes add presigned URL parsing capability to S3 PutObject and multipart operations. A new function parses presigned URLs to extract host, port, and URI components. The S3 client configuration is temporarily swapped when using presigned URLs, with automatic restoration and proper resource cleanup on all code paths.

Changes

Cohort / File(s) Summary
Presigned URL Parsing
plugins/out_s3/s3.h, plugins/out_s3/s3.c
Added new s3_parse_presigned_url function to parse presigned URLs into host, port, and URI components with error handling and resource management. Updated create_headers signature with additional parameters for headers and multipart upload support.
PutObject Flow
plugins/out_s3/s3.c
Reworked PutObject error paths to route through centralized cleanup block. Integrated presigned URL parsing, temporary host/port configuration swapping, TLS/keepalive adjustments, and state restoration logic.
Multipart Operations
plugins/out_s3/s3_multipart.c
Extended multipart operations (complete, abort, create, upload-part) with presigned URL handling. Added port-aware configuration swapping, state tracking for original host/upstream settings, and centralized cleanup paths ensuring proper restoration on all execution paths.

Sequence Diagram

sequenceDiagram
    participant Operation as Multipart/PutObject
    participant Parser as s3_parse_presigned_url
    participant Config as S3 Client Config
    participant Request as HTTP Request
    participant Cleanup as Cleanup Handler

    Operation->>Parser: Parse presigned URL
    Parser->>Parser: Extract host, port, URI
    Parser-->>Operation: Return parsed components
    
    Operation->>Config: Save original host/port
    Operation->>Config: Swap to presigned host/port
    Operation->>Config: Adjust TLS/keepalive for presigned
    
    Operation->>Request: Execute with presigned config
    Request-->>Operation: Response received
    
    Operation->>Cleanup: Trigger cleanup
    Cleanup->>Config: Restore original host/port
    Cleanup->>Cleanup: Free presigned resources
    Cleanup-->>Operation: Complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 A presigned URL hops in from the cloud,
Our parser breaks it down, oh so proud!
Host, port, and URI—neatly arranged,
Then swapped in the client with careful exchange,
Cleanup restores what was there before,
State management magic, we couldn't ask for more! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix authorization_endpoint_url for blob uploads' directly and clearly summarizes the main change—fixing authorization endpoint URL handling for blob uploads. This is precisely the primary objective of the PR as stated in the objectives.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@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: 5369de3a9c

ℹ️ 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".

Comment on lines +2614 to +2617
/* Disable TLS for HTTP (port 80), enable for HTTPS (port 443) */
if (presigned_port == 80) {
ctx->s3_client->upstream->base.flags &= ~FLB_IO_TLS;
}

Choose a reason for hiding this comment

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

P2 Badge Enable TLS when presigned URL requires HTTPS

The new presigned-host switch only clears TLS when the parsed port is 80, but it never re-enables TLS for HTTPS URLs. If authorization_endpoint_url is HTTP (so the original upstream flags have TLS disabled) and the presigned URL is HTTPS (e.g., https://... on 443 or another port), the client will keep TLS off and attempt a plain HTTP request to an HTTPS endpoint, which fails. The same mismatch happens for HTTP presigned URLs on non-80 ports (TLS stays enabled). Consider explicitly setting FLB_IO_TLS based on the URL scheme (or port) rather than only clearing it for port 80.

Useful? React with 👍 / 👎.

Copy link

@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 (1)
plugins/out_s3/s3.c (1)

2652-2661: ⚠️ Potential issue | 🟡 Minor

Log message will include presigned URL query parameters.

When using a presigned URL, uri contains the full path + query string (e.g., /bucket/key?X-Amz-Algorithm=...). The final_key calculation at line 2657 (uri + strlen(ctx->bucket) + 1) skips the bucket prefix but retains the query parameters, producing a noisy log like:

Successfully uploaded object /my-key?X-Amz-Algorithm=AWS4-HMAC-SHA256&...

For virtual-hosted-style presigned URLs (where the bucket is in the hostname, not the path), this offset would point to the wrong position in the string entirely. Consider logging uri directly or truncating at ? when in the presigned URL path.

🤖 Fix all issues with AI agents
In `@plugins/out_s3/s3_multipart.c`:
- Around line 449-455: The code relies on presigned_port to decide TLS which
fails for non-standard HTTP/HTTPS ports; change s3_parse_presigned_url to return
a boolean (e.g., use_tls) derived from the URL scheme (http vs https) and update
the call sites that currently inspect presigned_port to instead set/clear
FLB_IO_TLS based on that use_tls flag (explicitly set FLB_IO_TLS when use_tls is
true, clear it when false) for the ctx->s3_client->upstream->base.flags
manipulation; apply this same change to all five occurrences of the port-based
TLS toggle and keep the existing keepalive-disable line as-is.
🧹 Nitpick comments (2)
plugins/out_s3/s3_multipart.c (2)

416-455: Extract duplicated presigned URL setup/teardown into helpers.

The presigned URL setup block (~20 lines: parse URL → save original state → override host/port/flags → disable TLS/keepalive) and the cleanup block (~8 lines: restore originals → free presigned_host) are copy-pasted into five functions (complete_multipart_upload, abort_multipart_upload, create_multipart_upload, upload_part, and put_blob_object in s3.c).

Extracting these into two small helpers (e.g., s3_presigned_override_apply / s3_presigned_override_restore) would reduce ~115 lines of duplication and ensure future fixes (like the TLS port logic) propagate automatically.

Also applies to: 515-526


727-773: Cleanup runs before response processing—correct but inconsistent with peer functions.

Unlike complete_multipart_upload, abort_multipart_upload, and upload_part which process the HTTP response before the cleanup label, create_multipart_upload restores host/frees uri at the cleanup: label and then falls through to process c. This works because the response in c is self-contained, but the structural inconsistency may confuse future readers.

Consider restructuring to match the pattern used by the other functions (process response first, then cleanup) for uniformity.

Comment on lines +449 to +455
/* Disable TLS for HTTP (port 80), enable for HTTPS (port 443) */
if (presigned_port == 80) {
ctx->s3_client->upstream->base.flags &= ~FLB_IO_TLS;
}

/* Disable keepalive to force new connection to the new host */
ctx->s3_client->upstream->base.flags &= ~FLB_IO_TCP_KA;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

TLS toggle based on port 80 alone may miss non-standard HTTP ports.

The comment says "Disable TLS for HTTP (port 80), enable for HTTPS (port 443)" but only the disable-for-80 branch is implemented. If the authorization endpoint returns a presigned URL on a non-standard HTTP port (e.g., http://s3-proxy:8080/...), presigned_port will be 8080 and TLS won't be disabled, causing the request to fail against the original HTTPS-configured upstream.

Consider returning a use_tls boolean from s3_parse_presigned_url based on the URL scheme rather than relying on port number. This same issue appears in all five instances of this pattern.

🤖 Prompt for AI Agents
In `@plugins/out_s3/s3_multipart.c` around lines 449 - 455, The code relies on
presigned_port to decide TLS which fails for non-standard HTTP/HTTPS ports;
change s3_parse_presigned_url to return a boolean (e.g., use_tls) derived from
the URL scheme (http vs https) and update the call sites that currently inspect
presigned_port to instead set/clear FLB_IO_TLS based on that use_tls flag
(explicitly set FLB_IO_TLS when use_tls is true, clear it when false) for the
ctx->s3_client->upstream->base.flags manipulation; apply this same change to all
five occurrences of the port-based TLS toggle and keep the existing
keepalive-disable line as-is.

@edsiper
Copy link
Member

edsiper commented Feb 9, 2026

@codex review

@edsiper edsiper added this to the Fluent Bit v5.0 milestone Feb 9, 2026
Copy link

@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: 5369de3a9c

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2614 to +2616
/* Disable TLS for HTTP (port 80), enable for HTTPS (port 443) */
if (presigned_port == 80) {
ctx->s3_client->upstream->base.flags &= ~FLB_IO_TLS;

Choose a reason for hiding this comment

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

P2 Badge Disable TLS based on scheme, not only port 80

The presigned URL path switches the upstream host/port, but TLS is only disabled when presigned_port == 80. If the authorization endpoint returns an HTTP URL on a non‑80 port (e.g., http://...:8080/...), s3_parse_presigned_url will set presigned_port to 8080 and the original FLB_IO_TLS flag remains enabled. That causes a TLS handshake against a plain‑HTTP endpoint, so uploads fail in that configuration. This logic is new with the presigned URL host/port handling and should instead key TLS on the URL scheme (or explicitly disable TLS for any non‑HTTPS scheme), not just port 80.

Useful? React with 👍 / 👎.

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.

2 participants