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

Authentication bearer token #29

Open
Traver72 opened this issue Jun 25, 2024 · 3 comments
Open

Authentication bearer token #29

Traver72 opened this issue Jun 25, 2024 · 3 comments

Comments

@Traver72
Copy link

Thanks for all the work on this great gem. Is there a simple way to protect the "/metrics" endpoint using a bearer token? Or is it the way to go to use a middleware for this? As far as I know, it is possible to configure prometheus server so that you can use bearer token for scraping servers.

@Traver72 Traver72 changed the title Autenthication bearer token Authentication bearer token Jun 25, 2024
@Envek
Copy link
Member

Envek commented Jun 25, 2024

Yabeda exporter extends exporter from Prometheus Ruby client which is a Rack middleware.

Probably, easiest way is to just place bearer checking middleware (like this one: https://github.com/yujideveloper/rack-bearer_auth) before exporter with the same path.

Something like this:

use Rack::BearerAuth::Middleware do
  match path: "/metrics", token: "very_secret"
end

use Yabeda::Prometheus::Exporter

@Traver72
Copy link
Author

Thank you very much for your quick reply. I may rephrase my question. What is the best practice not to make the metrics path publicly accessible? Especially via a bearer token, or is another way more common?

@luizkowalski
Copy link

hey 👋🏻

here is an idea that I'm using at the moment:

constraints ->(request) { request.authorization&.match?(/^Bearer\s+#{ENV.fetch('PROMETHEUS_TOKEN', nil)}$/) } do
  mount Yabeda::Prometheus::Exporter, at: "metrics"
end

Then curl -H "Authorization: Bearer $TOKEN" localhost:3000/metrics. without the token, it returns 404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants