Skip to content

out_http: Added support for http_bearer_token_file option - #12165

Open
fernandoalexandre wants to merge 2 commits into
fluent:masterfrom
fernandoalexandre:feature/bearer-token-file
Open

out_http: Added support for http_bearer_token_file option#12165
fernandoalexandre wants to merge 2 commits into
fluent:masterfrom
fernandoalexandre:feature/bearer-token-file

Conversation

@fernandoalexandre

@fernandoalexandre fernandoalexandre commented Jul 28, 2026

Copy link
Copy Markdown

Summary

  • Added support for http_bearer_token_file option that allows a bearer token to be used in an Authorization header (Authorization: Bearer <token>)
  • Token is read on every request to ensure non-stale content.

Motivation

In Kubernetes, mounting secrets as files is considered best practice, with widely used for projected tokens and external secret services such as CSI drivers and External Secrets Operator.

Additionally other systems offer similar functionality, for example OpenTelemetry Bearer token extension.

Validation

  • cmake --build build -j8 && cd tests/integration/ && ./run_tests.py -k bearer_token_token - 4 passed
  • cmake --build build -j8 && cd tests/integration/ && ./run_tests.py -k out_http - 24 passed
  • Tested in a local kubernetes cluster with full authentication integration leveraging a token fetching using a mounted service account token, and calling a Gloo service that validated the resulting token as well.

Example Configuration

[OUTPUT]
        Name                            http
        Alias                           http.authenticated
        Match                           kube.*
        Host                            gateway-proxy.default.svc.cluster.local
        port                            8080
        tls                             off
        tls.verify                      off
        uri                             /v1/metrics
        http_bearer_token_file          /var/run/secret/bearer/token
        storage.total_limit_size        1G
        format                          json_stream

Infrastructure deployment

extraVolumeMounts:
  - mountPath: /var/run/secret/bearer
    name: token
    readOnly: true

extraVolumes:
  - name: token
    secret:
      secretName: bearer-token

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

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

  • N/A Run local packaging test showing all targets (including any new ones) build.
  • N/A 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

Summary by CodeRabbit

  • New Features
    • Added HTTP Bearer token authentication via a configured token file.
    • The token file is re-read on every request; whitespace/newline-only content is rejected.
  • Bug Fixes
    • When the token file is missing or empty/whitespace, the output retries instead of sending requests.
    • Configuration validation prevents using Bearer token file auth together with Basic auth or OAuth2.
  • Tests
    • Added integration and runtime coverage for Bearer header injection, token rotation, retry behavior, and auth conflict handling.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds file-backed Bearer authentication to out_http, rereading and trimming the token per request, retrying read failures, rejecting conflicting authentication settings, and adding integration and runtime coverage.

Changes

Out_http bearer authentication

Layer / File(s) Summary
Authentication contract and validation
plugins/out_http/http.h, plugins/out_http/http.c, plugins/out_http/http_conf.c
Adds the bearer token file setting and rejects combinations with Basic authentication or OAuth2.
Per-request token loading
plugins/out_http/http.c
Reads and trims the token for every request, sets the Bearer authorization header, and retries with cleanup when loading fails.
Authentication behavior coverage
tests/integration/scenarios/out_http/..., tests/runtime/out_http.c
Tests header generation, token rotation, missing or empty files, and invalid authentication combinations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant http_request
  participant http_bearer_token_file_auth
  participant TokenFile
  participant HTTPClient
  http_request->>http_bearer_token_file_auth: load bearer token
  http_bearer_token_file_auth->>TokenFile: read and trim token
  http_bearer_token_file_auth->>HTTPClient: set Authorization header
  http_request->>HTTPClient: send request
Loading

Possibly related PRs

Suggested reviewers: edsiper

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for the http_bearer_token_file option.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@tests/integration/scenarios/out_http/tests/test_out_http_001.py`:
- Around line 249-253: Wrap the service lifecycle in the test around
service.start(), configure_http_response(), and wait_for_requests() with a
try/finally block, and move service.stop() into finally so it always executes on
assertion or timeout failures. Match the cleanup structure used by the rotation
and failure-path tests.
🪄 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 Plus

Run ID: 74f2aeae-ddb2-4718-91ed-a780af8155c0

📥 Commits

Reviewing files that changed from the base of the PR and between cb7256c and 4d843d8.

📒 Files selected for processing (6)
  • plugins/out_http/http.c
  • plugins/out_http/http.h
  • plugins/out_http/http_conf.c
  • tests/integration/scenarios/out_http/config/out_http_bearer_token_file.yaml
  • tests/integration/scenarios/out_http/tests/test_out_http_001.py
  • tests/runtime/out_http.c

Comment thread tests/integration/scenarios/out_http/tests/test_out_http_001.py Outdated

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

Copy link
Copy Markdown

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: 4d843d89f8

ℹ️ 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 thread plugins/out_http/http.c Outdated
… allows a bearer token to be used in an Authorization header

Signed-off-by: Fernando Alexandre <fernandoalexandre@users.noreply.github.com>
…teardown.

Added a guard when the `Authorization` header fails to be set.
Fixed integration test to ensure the service properly stops on failure.

Signed-off-by: Fernando Alexandre <fernandoalexandre@users.noreply.github.com>
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