From d27a72f8598dca51071ade36a0723bd84dbf55cf Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Mon, 15 Feb 2021 17:55:41 +0100 Subject: [PATCH] IPv6: Support host address configured with enclosing square brackets (#31226) Signed-off-by: Arve Knudsen --- pkg/api/http_server.go | 5 ++++- pkg/services/ldap/ldap.go | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index 521989a2014..85e3c232b82 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -10,6 +10,7 @@ import ( "os" "path" "path/filepath" + "strings" "sync" "github.com/grafana/grafana/pkg/services/live" @@ -103,8 +104,10 @@ func (hs *HTTPServer) Run(ctx context.Context) error { hs.applyRoutes() + // Remove any square brackets enclosing IPv6 addresses, a format we support for backwards compatibility + host := strings.TrimSuffix(strings.TrimPrefix(setting.HttpAddr, "["), "]") hs.httpSrv = &http.Server{ - Addr: net.JoinHostPort(setting.HttpAddr, setting.HttpPort), + Addr: net.JoinHostPort(host, setting.HttpPort), Handler: hs.macaron, } switch hs.Cfg.Protocol { diff --git a/pkg/services/ldap/ldap.go b/pkg/services/ldap/ldap.go index c7084839b04..6caf5494205 100644 --- a/pkg/services/ldap/ldap.go +++ b/pkg/services/ldap/ldap.go @@ -114,6 +114,8 @@ func (server *Server) Dial() error { } } for _, host := range strings.Split(server.Config.Host, " ") { + // Remove any square brackets enclosing IPv6 addresses, a format we support for backwards compatibility + host = strings.TrimSuffix(strings.TrimPrefix(host, "["), "]") address := net.JoinHostPort(host, strconv.Itoa(server.Config.Port)) if server.Config.UseSSL { tlsCfg := &tls.Config{