Skip to content

out_http: add bearer token authentication - #5671

Merged
Watson1978 merged 2 commits into
fluent:masterfrom
cvas22:out-http-bearer-auth
Nov 25, 2026
Merged

Watson1978 merged 2 commits into
fluent:masterfrom
cvas22:out-http-bearer-auth

Conversation

@cvas22

@cvas22 cvas22 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Fixes #3587

What this PR does / why we need it:
Adds method bearer to the <auth> section of out_http. You either set token (masked like password) or point token_path at a file. The file is read on every request, so a rotated token like a projected Kubernetes service account token keeps working without a restart. Today people put the token in headers, which shows up unmasked in the config dump.

With method bearer, set exactly one of token and token_path. At configure time, it rejects non-ASCII input, strips surrounding whitespace (including a trailing newline), and rejects an empty value or any remaining CR or LF. It also fails if the token file can't be read. If the file later goes missing or its contents fail these checks, the flush fails and goes through the normal retry.

<auth>
  method bearer
  token_path /var/run/secrets/tokens/fluentd
</auth>

Docs Changes:
fluent/fluentd-docs-gitbook#729

Release Note:
out_http: add bearer token authentication with token or token_path

Add method bearer to <auth>. The token is set with token, or read from
token_path on every request so a rotated token file, such as a projected
Kubernetes service account token, is picked up without a restart.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@Watson1978 Watson1978 added the enhancement Feature request or improve operations label Nov 23, 2026

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this. I tried it with a real fluentd and a small HTTP server on Linux. A rotated token is used on the next flush, a missing file is retried, and token is masked in the config dump. The tests in this PR also pass on Windows 10.

I am requesting changes for one issue. If the token value contains a line break, the plugin starts, but Net::HTTP raises ArgumentError when Fluentd flushes. Fluentd does not retry this error. With no secondary, the chunk goes to the backup directory, even with retry_forever true. A common config hits this: token "#{File.read('/path/to/token')}" keeps the trailing newline of the file. Details are inline.

Comment thread lib/fluent/plugin/out_http.rb Resolved
Comment thread lib/fluent/plugin/out_http.rb Resolved
Comment thread test/plugin/test_out_http.rb Resolved
A token with a trailing newline (e.g. read with File.read in the config) is stripped now. A token that still has a line break, is empty or isn't ASCII fails configure, and a bad token_path file at flush time raises an error that Fluentd retries. Also warn when token or token_path is set without method bearer.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the update. I verified the fixes in 163ab90 with a real fluentd. With YAML token: |, the server received Bearer demo without the trailing newline. When the token file changed to two lines, Fluentd retried the flush and delivered the same chunk after I fixed the file. The unused-token warning now appears when token or token_path is set with a non-bearer method, including the default basic. All four test strings now use \n. The 48 out_http tests passed on Linux and Windows 10.

@Watson1978 Watson1978 added this to the v1.21.0 milestone Nov 25, 2026
@Watson1978

Copy link
Copy Markdown
Contributor

Thanks again for this. Since the code looks good now, could you open the docs PR you mentioned in the description?

The out_http page is output/http.md in fluent/fluentd-docs-gitbook. In the <auth> section, it would be good to cover:

  • bearer in the table and the list for method, with version 1.21.0.
  • A "Parameters for method bearer" subsection with an example, like the ones for basic and aws_sigv4.
  • token and token_path, with their type, default and version. token is masked in the config dump. token_path is read on every request, so a rotated token is used without a restart.
  • Exactly one of them must be set. At configure time, non-ASCII input is rejected, surrounding whitespace (including a trailing newline) is stripped, and an empty value or a remaining CR or LF is rejected. The token file must also be readable at startup. If the file later goes missing or fails these checks, the flush fails and is retried.
  • The warning when token or token_path is set without method bearer.

@cvas22

cvas22 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Opened the docs PR here: fluent/fluentd-docs-gitbook#729. It covers the points you listed. thx

@Watson1978
Watson1978 merged commit 9b101e6 into fluent:master Nov 25, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature request or improve operations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Http output bearer token authentication

2 participants