Add public address config option (#405)

pull/405/merge
Jeff Mitchell 6 years ago committed by GitHub
parent 475c6cdebe
commit 262ff06042
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"net"
"os"
"sort"
"strconv"
@ -621,3 +622,34 @@ func (b *Server) DestroyDevDatabase() error {
}
return nil
}
func (b *Server) SetupWorkerPublicAddress(conf *config.Config, flagValue string) error {
if conf.Worker == nil {
conf.Worker = new(config.Worker)
}
if flagValue != "" {
conf.Worker.PublicAddr = flagValue
}
if conf.Worker.PublicAddr == "" {
FindAddr:
for _, listener := range conf.Listeners {
for _, purpose := range listener.Purpose {
if purpose == "proxy" {
conf.Worker.PublicAddr = listener.Address
break FindAddr
}
}
}
}
host, port, err := net.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)
}
}
conf.Worker.PublicAddr = fmt.Sprintf("%s:%s", host, port)
return nil
}

@ -34,6 +34,8 @@ type Command struct {
flagDevAuthMethodId string
flagDevControllerAPIListenAddr string
flagDevControllerClusterListenAddr string
flagDevWorkerProxyListenAddr string
flagDevWorkerPublicAddr string
flagDevSkipAuthMethodCreation bool
flagDevDisableDatabaseDestruction bool
}
@ -119,6 +121,20 @@ func (c *Command) Flags() *base.FlagSets {
Usage: "Address to bind to for controller \"cluster\" purpose.",
})
f.StringVar(&base.StringVar{
Name: "dev-proxy-listen-address",
Target: &c.flagDevWorkerProxyListenAddr,
EnvVar: "BOUNDARY_DEV_WORKER_PROXY_LISTEN_ADDRESS",
Usage: "Address to bind to for worker \"proxy\" purpose.",
})
f.StringVar(&base.StringVar{
Name: "dev-worker-public-address",
Target: &c.flagDevWorkerPublicAddr,
EnvVar: "BOUNDARY_DEV_WORKER_PUBLIC_ADDRESS",
Usage: "Public address at which the worker is reachable for session proxying.",
})
f.BoolVar(&base.BoolVar{
Name: "dev-skip-auth-method-creation",
Target: &c.flagDevSkipAuthMethodCreation,
@ -204,6 +220,11 @@ func (c *Command) Run(args []string) int {
if c.flagDevControllerClusterListenAddr != "" {
l.Address = c.flagDevControllerClusterListenAddr
}
case "proxy":
if c.flagDevWorkerProxyListenAddr != "" {
l.Address = c.flagDevWorkerProxyListenAddr
}
}
}
@ -247,6 +268,13 @@ func (c *Command) Run(args []string) int {
return 1
}
if err := c.SetupWorkerPublicAddress(devConfig, c.flagDevWorkerPublicAddr); err != nil {
c.UI.Error(err.Error())
return 1
}
c.InfoKeys = append(c.InfoKeys, "worker public addr")
c.Info["worker public addr"] = devConfig.Worker.PublicAddr
// Write out the PID to the file now that server has successfully started
if err := c.StorePidFile(devConfig.PidFile); err != nil {
c.UI.Error(fmt.Errorf("Error storing PID: %w", err).Error())

@ -36,13 +36,14 @@ type Command struct {
configWrapper wrapping.Wrapper
flagConfig string
flagConfigKms string
flagLogLevel string
flagLogFormat string
flagDev bool
flagDevWorkerListenAddr string
flagCombineLogs bool
flagConfig string
flagConfigKms string
flagLogLevel string
flagLogFormat string
flagDev bool
flagDevWorkerProxyListenAddr string
flagDevWorkerPublicAddr string
flagCombineLogs bool
}
func (c *Command) Synopsis() string {
@ -116,12 +117,19 @@ func (c *Command) Flags() *base.FlagSets {
})
f.StringVar(&base.StringVar{
Name: "dev-listen-address",
Target: &c.flagDevWorkerListenAddr,
EnvVar: "BOUNDARY_DEV_WORKER_LISTEN_ADDRESS",
Name: "dev-proxy-listen-address",
Target: &c.flagDevWorkerProxyListenAddr,
EnvVar: "BOUNDARY_DEV_WORKER_PROXY_LISTEN_ADDRESS",
Usage: "Address to bind the worker to in \"dev\" mode.",
})
f.StringVar(&base.StringVar{
Name: "dev-worker-public-address",
Target: &c.flagDevWorkerPublicAddr,
EnvVar: "BOUNDARY_DEV_WORKER_PUBLIC_ADDRESS",
Usage: "Public address at which the worker is reachable for session proxying.",
})
f.BoolVar(&base.BoolVar{
Name: "combine-logs",
Target: &c.flagCombineLogs,
@ -193,6 +201,16 @@ func (c *Command) Run(args []string) int {
return 1
}
if !c.flagDev {
c.flagDevWorkerPublicAddr = ""
}
if err := c.SetupWorkerPublicAddress(c.Config, c.flagDevWorkerPublicAddr); err != nil {
c.UI.Error(err.Error())
return 1
}
c.InfoKeys = append(c.InfoKeys, "public addr")
c.Info["public addr"] = c.Config.Worker.PublicAddr
// Write out the PID to the file now that server has successfully started
if err := c.StorePidFile(c.Config.PidFile); err != nil {
c.UI.Error(fmt.Errorf("Error storing PID: %w", err).Error())
@ -266,8 +284,8 @@ func (c *Command) ParseFlagsAndConfig(args []string) int {
return 1
}
if c.flagDevWorkerListenAddr != "" {
c.Config.Listeners[0].Address = c.flagDevWorkerListenAddr
if c.flagDevWorkerProxyListenAddr != "" {
c.Config.Listeners[0].Address = c.flagDevWorkerProxyListenAddr
}
}

@ -110,6 +110,7 @@ type Worker struct {
Name string `hcl:"name"`
Description string `hcl:"description"`
Controllers []string `hcl:"controllers"`
PublicAddr string `hcl:"public_addr"`
}
type Database struct {

@ -31,10 +31,6 @@ func (w *Worker) startListeners() error {
return fmt.Errorf("unknown listener purpose %q", purpose)
}
if w.listeningAddress != "" {
return errors.New("more than one listening address found")
}
handler := w.handler(HandlerProperties{
ListenerConfig: ln.Config,
})
@ -81,11 +77,6 @@ func (w *Worker) startListeners() error {
servers = append(servers, func() {
go server.Serve(l)
})
if w.listeningAddress == "" {
w.listeningAddress = l.Addr().String()
w.logger.Info("reporting listening address to controllers", "address", w.listeningAddress)
}
}
}

@ -85,7 +85,7 @@ func (w *Worker) startStatusTicking(cancelCtx context.Context) {
Name: w.conf.RawConfig.Worker.Name,
Type: resource.Worker.String(),
Description: w.conf.RawConfig.Worker.Description,
Address: w.listeningAddress,
Address: w.conf.RawConfig.Worker.PublicAddr,
},
})
if err != nil {

@ -27,8 +27,6 @@ type Worker struct {
controllerStatusConn *atomic.Value
lastStatusSuccess *atomic.Value
listeningAddress string
controllerResolver *atomic.Value
controllerResolverCleanup *atomic.Value
@ -128,7 +126,6 @@ func (w *Worker) Shutdown(skipListeners bool) error {
return fmt.Errorf("error stopping worker listeners: %w", err)
}
}
w.listeningAddress = ""
w.started.Store(false)
return nil
}

Loading…
Cancel
Save