mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-30 20:12:43 +00:00
feat(metrics): enable mTLS support
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -3,11 +3,13 @@ package metrics
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/pprof"
|
"net/http/pprof"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
@@ -78,6 +80,21 @@ func (s *Server) run(ctx context.Context, lg *slog.Logger) error {
|
|||||||
srv.TLSConfig = &tls.Config{
|
srv.TLSConfig = &tls.Config{
|
||||||
GetCertificate: kpr.GetCertificate,
|
GetCertificate: kpr.GetCertificate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.Config.TLS.CA != "" {
|
||||||
|
caCert, err := os.ReadFile(s.Config.TLS.CA)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%w %s: %w", config.ErrCantReadFile, s.Config.TLS.CA, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
certPool := x509.NewCertPool()
|
||||||
|
if !certPool.AppendCertsFromPEM(caCert) {
|
||||||
|
return fmt.Errorf("%w %s", config.ErrInvalidMetricsCACertificate, s.Config.TLS.CA)
|
||||||
|
}
|
||||||
|
|
||||||
|
srv.TLSConfig.ClientCAs = certPool
|
||||||
|
srv.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lg.Debug("listening for metrics", "url", metricsURL)
|
lg.Debug("listening for metrics", "url", metricsURL)
|
||||||
|
|||||||
Reference in New Issue
Block a user