Skip to content

Commit

Permalink
fix(ipv6): do not build malformed enroll url with ipv6 host
Browse files Browse the repository at this point in the history
replace string concat with net func to avoid building a malformed
url if the host is an ipv6
  • Loading branch information
kruskall committed Feb 26, 2025
1 parent 2614cb5 commit 77aa4cb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"fmt"
"io"
"math/rand/v2"
"net"
"os"
"os/exec"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -433,7 +435,7 @@ func (c *enrollCmd) prepareFleetTLS() error {
if c.options.FleetServer.Host == "" {
c.options.FleetServer.Host = defaultFleetServerInternalHost
}
c.options.URL = fmt.Sprintf("http://%s:%d", host, port)
c.options.URL = "http://" + net.JoinHostPort(host, strconv.Itoa(int(port)))
c.options.Insecure = true
return nil
}
Expand All @@ -453,7 +455,7 @@ func (c *enrollCmd) prepareFleetTLS() error {
}
c.options.FleetServer.Cert = string(pair.Crt)
c.options.FleetServer.CertKey = string(pair.Key)
c.options.URL = fmt.Sprintf("https://%s:%d", hostname, port)
c.options.URL = "https://" + net.JoinHostPort(hostname, strconv.Itoa(int(port)))
c.options.CAs = []string{string(ca.Crt())}
}
// running with custom Cert and CertKey; URL is required to be set
Expand All @@ -465,7 +467,7 @@ func (c *enrollCmd) prepareFleetTLS() error {
if c.options.FleetServer.InternalPort != defaultFleetServerInternalPort {
c.log.Warnf("Internal endpoint configured to: %d. Changing this value is not supported.", c.options.FleetServer.InternalPort)
}
c.options.InternalURL = fmt.Sprintf("%s:%d", defaultFleetServerInternalHost, c.options.FleetServer.InternalPort)
c.options.InternalURL = net.JoinHostPort(defaultFleetServerInternalHost, strconv.Itoa(int(c.options.FleetServer.InternalPort)))
}

return nil
Expand Down

0 comments on commit 77aa4cb

Please sign in to comment.