Repository navigation
out_http: add bearer token authentication - #5671
Conversation
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
left a comment
There was a problem hiding this comment.
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.
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
left a comment
There was a problem hiding this comment.
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.
|
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
|
|
Opened the docs PR here: fluent/fluentd-docs-gitbook#729. It covers the points you listed. thx |
Which issue(s) this PR fixes:
Fixes #3587
What this PR does / why we need it:
Adds
method bearerto the<auth>section of out_http. You either settoken(masked likepassword) or pointtoken_pathat 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 inheaders, which shows up unmasked in the config dump.With
method bearer, set exactly one oftokenandtoken_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.Docs Changes:
fluent/fluentd-docs-gitbook#729
Release Note:
out_http: add bearer token authentication with
tokenortoken_path