Add public address config option (#405)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-22 08:28:10 -04:00
1 parent 475c6cdebe
commit 262ff06042
7 files changed
+92 -25

No files matched your search

+32
View File
@@ -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
}
+28
View File
@@ -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())
+30 -12
View File
@@ -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
}
}
+1
View File
@@ -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 {