mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-04 13:36:35 +02:00
security: default metrics server to loopback
Fixes unauthenticated metrics exposure be defaulting to 127.0.0.1 when no host is provided. Logs a warning when bound to non-loopback addresses.
This commit is contained in:
@@ -113,6 +113,22 @@ func (p *prog) runMetricsServer(ctx context.Context, reloadCh chan struct{}) {
|
||||
}
|
||||
|
||||
addr := p.cfg.Service.MetricsListener
|
||||
if addr != "" {
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msgf("Invalid metrics listener address (%s); expected host:port", addr)
|
||||
} else {
|
||||
if host == "" {
|
||||
host = "127.0.0.1"
|
||||
addr = net.JoinHostPort(host, port)
|
||||
}
|
||||
ip := net.ParseIP(host)
|
||||
if (ip != nil && !ip.IsLoopback()) || (ip == nil && host != "localhost") {
|
||||
mainLog.Load().Warn().Msgf("Metrics server is bound to a non-loopback address (%s). This exposes sensitive data without authentication.", addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ms, err := newMetricsServer(addr, reg)
|
||||
if err != nil {
|
||||
mainLog.Load().Warn().Err(err).Msg("could not create new metrics server")
|
||||
|
||||
Reference in New Issue
Block a user