Support for mTLS in Loki Hook #1289

Closed
opened 2026-03-27 16:40:53 +00:00 by maxhamon · 4 comments
Contributor

What I'd like to do and why

Grafana Loki does not come with any included authentication layer (doc) and relies on reverse proxies, effectively suggesting the use of basic auth, which can be used today in Borgmatic by doing things like this in URL : https://{loki_user}:{loki_password}@{loki_url}/loki/api/v1/push

If we want to go further we could use mTLS instead. In this setup, the client must present a certificate and a private key to the reverse proxy to be authorized.
Currently, Borgmatic's Loki hook does not provide a way to pass these TLS credentials, making it impossible to send logs to a Loki instance protected by mTLS.

Other notes / implementation ideas

I have tested a local modification of hooks/monitoring/loki.py that implements this feature using the cert parameter of the requests library. It works as expected in my mTLS environment.
I'm providing this file, just for checking.

I haven't opened a PR (yet ?) because I'm not sure about the best way to implement this. It might make more sense to implement this at another level rather than just for my specific Loki use case.

### What I'd like to do and why Grafana Loki does not come with any included authentication layer ([doc](https://grafana.com/docs/loki/latest/operations/authentication)) and relies on reverse proxies, effectively suggesting the use of basic auth, which can be used today in Borgmatic by doing things like this in URL : `https://{loki_user}:{loki_password}@{loki_url}/loki/api/v1/push` If we want to go further we could use mTLS instead. In this setup, the client must present a certificate and a private key to the reverse proxy to be authorized. Currently, Borgmatic's Loki hook does not provide a way to pass these TLS credentials, making it impossible to send logs to a Loki instance protected by mTLS. ### Other notes / implementation ideas I have tested a local modification of `hooks/monitoring/loki.py` that implements this feature using the cert parameter of the requests library. It works as expected in my mTLS environment. I'm providing this file, just for checking. I haven't opened a PR (yet ?) because I'm not sure about the best way to implement this. It might make more sense to implement this at another level rather than just for my specific Loki use case.
5.6 KiB
maxhamon changed title from Feature: support for mTLS in Loki Hook to Support for mTLS in Loki Hook 2026-03-27 16:43:14 +00:00
Owner

Thanks for filing this. I had a look at your changes, and the general approach makes sense to me. I do think they make sense to do at this level, rather than, say, in some sort of generalized way that's not specific to the Loki hook. I will say that I'm not wild about the existing design of Loki_log_buffer insofar as it's a little OOPier than I'd like, but that well predates any of your changes. (And if it bothers me enough, I can always refactor after.) So if you're up to do a PR for this, that would be great.

Couple of minor points of pre-feedback though:

  • This will of course require schema.yaml changes to, which I assume you've already done separately.
  • I might suggest calling tls_options just tls, as everything in the schema is an option!
  • Doc updates for this feature would be ideal, but I'm also happy to do that if you'd prefer.

Also be aware of #1199, a related feature!

Thanks for filing this. I had a look at your changes, and the general approach makes sense to me. I do think they make sense to do at this level, rather than, say, in some sort of generalized way that's not specific to the Loki hook. I will say that I'm not wild about the existing design of `Loki_log_buffer` insofar as it's a little OOPier than I'd like, but that well predates any of your changes. (And if it bothers me enough, I can always refactor after.) So if you're up to do a PR for this, that would be great. Couple of minor points of pre-feedback though: - This will of course require `schema.yaml` changes to, which I assume you've already done separately. - I might suggest calling `tls_options` just `tls`, as everything in the schema is an option! - Doc updates for this feature would be ideal, but I'm also happy to do that if you'd prefer. Also be aware of #1199, a related feature!
Author
Contributor

PR is up. Renamed tls_options to tls and updated cert filenames options too.
Docs are updated, I'll leave the versioning to you.

PR is up. Renamed `tls_options` to `tls` and updated cert filenames options too. Docs are updated, I'll leave the versioning to you.
Owner

Implemented in main (by @maxhamon) and will be part of the next release. Thanks again!

Implemented in main (by @maxhamon) and will be part of the next release. Thanks again!
Owner

Released in borgmatic 2.1.5!

Released in borgmatic 2.1.5!
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
borgmatic-collective/borgmatic#1289
No description provided.