[fix] allow IPv6 controllers, workers, and targets (#5221)
Co-authored-by: Damian Debkowski <damian.debkowski@hashicorp.com>
This commit is contained in:
1 parent
680bb02af9
commit
62c41191ff
42 files changed
+1996
-546
No files matched your search
+18
-14
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/boundary/internal/util"
|
||||
"github.com/hashicorp/boundary/testing/dbtest"
|
||||
capoidc "github.com/hashicorp/cap/oidc"
|
||||
"github.com/jimlambrt/gldap"
|
||||
@@ -242,13 +243,9 @@ func (b *Server) CreateDevLdapAuthMethod(ctx context.Context) error {
|
||||
if purpose != "api" {
|
||||
continue
|
||||
}
|
||||
host, _, err = net.SplitHostPort(ln.Config.Address)
|
||||
host, _, err = util.SplitHostPort(ln.Config.Address)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "missing port") {
|
||||
host = ln.Config.Address
|
||||
} else {
|
||||
return fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
return fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
}
|
||||
if host == "" {
|
||||
@@ -259,6 +256,16 @@ func (b *Server) CreateDevLdapAuthMethod(ctx context.Context) error {
|
||||
tb := &oidcLogger{}
|
||||
|
||||
port = testdirectory.FreePort(tb)
|
||||
|
||||
// The util.SplitHostPort() method removes the square brackets that enclose the
|
||||
// host address when the address type is ipv6. The square brackets must be
|
||||
// added back, otherwise the gldap server will fail to start due to a parsing
|
||||
// error.
|
||||
if ip := net.ParseIP(host); ip != nil {
|
||||
if ip.To16() != nil {
|
||||
host = fmt.Sprintf("[%s]", host)
|
||||
}
|
||||
}
|
||||
b.DevLdapSetup.testDirectory = testdirectory.Start(tb,
|
||||
testdirectory.WithNoTLS(tb),
|
||||
testdirectory.WithHost(tb, host),
|
||||
@@ -455,15 +462,12 @@ func (b *Server) CreateDevOidcAuthMethod(ctx context.Context) error {
|
||||
if purpose != "api" {
|
||||
continue
|
||||
}
|
||||
b.DevOidcSetup.hostAddr, b.DevOidcSetup.callbackPort, err = net.SplitHostPort(ln.Config.Address)
|
||||
b.DevOidcSetup.hostAddr, b.DevOidcSetup.callbackPort, err = util.SplitHostPort(ln.Config.Address)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "missing port") {
|
||||
b.DevOidcSetup.hostAddr = ln.Config.Address
|
||||
// Use the default API port in the callback
|
||||
b.DevOidcSetup.callbackPort = "9200"
|
||||
} else {
|
||||
return fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
return fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
if b.DevOidcSetup.callbackPort == "" {
|
||||
b.DevOidcSetup.callbackPort = "9200"
|
||||
}
|
||||
}
|
||||
if b.DevOidcSetup.hostAddr == "" {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
_ "crypto/sha512"
|
||||
"crypto/tls"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/util"
|
||||
"github.com/hashicorp/go-secure-stdlib/listenerutil"
|
||||
"github.com/hashicorp/go-secure-stdlib/reloadutil"
|
||||
"github.com/mitchellh/cli"
|
||||
@@ -137,24 +138,22 @@ func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.U
|
||||
}
|
||||
}
|
||||
|
||||
host, port, err := net.SplitHostPort(l.Address)
|
||||
host, port, err := util.SplitHostPort(l.Address)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "missing port") {
|
||||
switch purpose {
|
||||
case "api":
|
||||
port = "9200"
|
||||
case "cluster":
|
||||
port = "9201"
|
||||
case "proxy":
|
||||
port = "9202"
|
||||
case "ops":
|
||||
port = "9203"
|
||||
default:
|
||||
return "", nil, errors.New("no purpose provided for listener and no port discoverable")
|
||||
}
|
||||
host = l.Address
|
||||
} else {
|
||||
return "", nil, fmt.Errorf("error splitting host/port: %w", err)
|
||||
return "", nil, fmt.Errorf("error splitting host/port: %w", err)
|
||||
}
|
||||
if port == "" {
|
||||
switch purpose {
|
||||
case "api":
|
||||
port = "9200"
|
||||
case "cluster":
|
||||
port = "9201"
|
||||
case "proxy":
|
||||
port = "9202"
|
||||
case "ops":
|
||||
port = "9203"
|
||||
default:
|
||||
return "", nil, errors.New("no purpose provided for listener and no port discoverable")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -58,10 +56,6 @@ const (
|
||||
WorkerAuthReqFile = "auth_request_token"
|
||||
)
|
||||
|
||||
// This regular expression is used to find all instances of square brackets within a string.
|
||||
// This regular expression is used to remove the square brackets from an IPv6 address.
|
||||
var squareBrackets = regexp.MustCompile("\\[|\\]")
|
||||
|
||||
func init() {
|
||||
metric.InitializeBuildInfo(prometheus.DefaultRegisterer)
|
||||
}
|
||||
@@ -841,20 +835,14 @@ func (b *Server) SetupWorkerPublicAddress(conf *config.Config, flagValue string)
|
||||
}
|
||||
}
|
||||
|
||||
host, port, err := net.SplitHostPort(conf.Worker.PublicAddr)
|
||||
host, port, err := util.SplitHostPort(conf.Worker.PublicAddr)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "missing port") {
|
||||
port = "9202"
|
||||
host = conf.Worker.PublicAddr
|
||||
} else {
|
||||
return fmt.Errorf("Error splitting public adddress host/port: %w", err)
|
||||
}
|
||||
return fmt.Errorf("Error splitting public adddress host/port: %w", err)
|
||||
}
|
||||
|
||||
// remove the square brackets from the ipv6 address because the method
|
||||
// net.JoinHostPort() will add a second pair of square brackets.
|
||||
host = squareBrackets.ReplaceAllString(host, "")
|
||||
conf.Worker.PublicAddr = net.JoinHostPort(host, port)
|
||||
if port == "" {
|
||||
port = "9202"
|
||||
}
|
||||
conf.Worker.PublicAddr = util.JoinHostPort(host, port)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user