Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http_client): Add token_file feature #20138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

unautre
Copy link
Contributor

@unautre unautre commented Mar 19, 2024

Add a "token_file" option to http::Auth to read the bearer token from a file.
This is especially useful when using a Kubernetes provided token file (/run/secrets/kubernetes.io/serviceaccount/token).

@unautre unautre requested a review from a team as a code owner March 19, 2024 21:01
@github-actions github-actions bot added the domain: sinks Anything related to the Vector's sinks label Mar 19, 2024
Copy link
Contributor

@tobz tobz left a comment

Choose a reason for hiding this comment

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

Overall, the intended functionality makes sense to me... but I think what is less clear is if this actually needs to read the token file every single time.

It would certainly be useful from the perspective of always using the latest token value, but it also feels like it will lead to unintended consequences around errors being throw if the file goes away, or is briefly unavailable, or the actaul call to read the file is slowed down and then in turn slows down the sink/whatever is using this style of authentication.

Can you explain a little more about your use case for this?

@unautre
Copy link
Contributor Author

unautre commented Mar 25, 2024

Hello @tobz , thanks for the feedback

My use case is to use vector's prometheus_scrape to scrape k8s metrics. This requires authentification, given by a token file that might be refreshed at the kubelet's convenance.

From what I gather from the k8s docs, "The application is responsible for reloading the token when it rotates. Periodic reloading (e.g. once every 5 minutes) is sufficient for most use cases.", so caching the file for a duration is possible ; but that is out of my meager rust expertise for now.

@tobz
Copy link
Contributor

tobz commented Mar 27, 2024

Nice, yeah, that makes sense.

I'll have a chat with the team. I can see the appeal of just reading the file every single time we want to build an authenticated request, but I'm not sure if we're comfortable with that overhead or not.

Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

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

Thanks for opening this @unautre !

I think having Vector read the file each time would be a bit of a departure from how Vector handles the rest of its configuration where it loads it at start-time. I can see that you need the token to be refreshed while Vector is running, though, which makes me think of a few options:

  • Having --watch-config watch for changes to this file and reload. This is something we are generally aspiring towards in Vector, that `--watch-config watches files referenced by configuration in addition to the configuration files itself, but implementation so far has been spotty. You can read more about this here: Ensure that --watch-config watches all configuration files for changes #17283
  • Another option would be to use Vector's secret loading mechanism instead to load a secret that is just used with auth.bearer. A caveat is that that doesn’t support expiring secrets (yet) but I think it does respect SIGHUP so you could have an external process issues a SIGHUP when the file changes

I think both of those would be more consistent with Vector's current UX than re-reading the file on each request. I know they are also much larger changes though. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: sinks Anything related to the Vector's sinks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants