Splitting listener and advertised addresses into separate variables

This commit is contained in:
gberl002
2022-02-10 16:49:54 -05:00
parent 8c76409d2d
commit c4ddd72af2
8 changed files with 68 additions and 30 deletions
@@ -25,7 +25,7 @@ ctrl:
#maxOutstandingConnects: 100
# the number of milliseconds to wait before a hello synchronization fails and closes the connection (30ms to 60000ms, default: 1000ms)
#connectTimeoutMs: 3000
listener: tls:{{ .Controller.ListenerHostPort }}
listener: tls:{{ .Controller.ListenerAddress }}:{{ .Controller.Port }}
# the endpoint that management tools connect to the controller over.
mgmt:
@@ -2,7 +2,13 @@
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiHomeVarName }}={{ .ZitiHome }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlNameVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlNameVarName }}={{ .Controller.Name }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlPortVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlPortVarName }}={{ .Controller.Port }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeRouterHostnameVarDescription }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlListenerAddressVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlListenerAddressVarName }}={{ .Controller.ListenerAddress }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlAdvertisedAddressVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlAdvertisedAddressVarName }}={{ .Controller.AdvertisedAddress }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeRouterHostnameVarName }}={{ .Router.Edge.Hostname }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlIdentityCertVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiEdgeCtrlIdentityCertVarName }}={{ .Controller.Edge.IdentityCert }}
@@ -32,8 +38,6 @@
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiSigningCertVarName }}={{ .ZitiSigningCert }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiSigningKeyVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiSigningKeyVarName }}={{ .ZitiSigningKey }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlListenerHostPortVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlListenerHostPortVarName }}={{ .Controller.ListenerHostPort }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiCtrlMgmtListenerHostPortVarDescription }}
{{ if eq .OS "windows" }}SET{{ else }}export{{ end }} {{ .ZitiCtrlMgmtListenerHostPortVarName }}={{ .Controller.MgmtListenerHostPort }}
{{ if eq .OS "windows" }}Rem {{ else }}# {{ end }}{{ .ZitiEdgeCtrlListenerHostPortVarDescription }}
@@ -14,7 +14,7 @@ identity:
ca: "{{ .Router.IdentityCA }}"
ctrl:
endpoint: tls:{{ .Controller.Edge.AdvertisedHostPort }}
endpoint: tls:{{ .Controller.AdvertisedAddress }}:{{ .Controller.Port }}
link:
dialers:
+17 -5
View File
@@ -54,7 +54,9 @@ type ConfigTemplateValues struct {
type ControllerTemplateValues struct {
Name string
ListenerHostPort string
Port string
AdvertisedAddress string
ListenerAddress string
MgmtListenerHostPort string
IdentityCert string
IdentityServerCert string
@@ -234,9 +236,17 @@ func (data *ConfigTemplateValues) populateEnvVars() {
zitiEdgeCtrlIdentityCA, err := cmdhelper.GetZitiEdgeIdentityCA()
handleVariableError(err, cmdhelper.EnvVariableDetails.ZitiCtrlIdentityCAVarName)
// Get Ziti Controller Listener Host and Port
zitiCtrlListenerHostPort, err := cmdhelper.GetZitiCtrlListenerHostPort()
handleVariableError(err, cmdhelper.EnvVariableDetails.ZitiCtrlListenerHostPortVarName)
// Get Ziti Controller Listener Address
zitiCtrlListenerAddress, err := cmdhelper.GetZitiCtrlListenerAddress()
handleVariableError(err, cmdhelper.EnvVariableDetails.ZitiCtrlListenerAddressVarName)
// Get Ziti Controller Advertised Address
zitiCtrlAdvertisedAddress, err := cmdhelper.GetZitiCtrlAdvertisedAddress()
handleVariableError(err, cmdhelper.EnvVariableDetails.ZitiCtrlAdvertisedAddressVarName)
// Get Ziti Controller Port
zitiCtrlPort, err := cmdhelper.GetZitiCtrlPort()
handleVariableError(err, cmdhelper.EnvVariableDetails.ZitiCtrlPortVarName)
// Get Ziti Controller Management Host and Port
zitiCtrlMgmtListenerHostPort, err := cmdhelper.GetZitiCtrlMgmtListenerHostPort()
@@ -263,7 +273,9 @@ func (data *ConfigTemplateValues) populateEnvVars() {
data.ZitiSigningCert = zitiSigningCert
data.ZitiSigningKey = zitiSigningKey
data.Controller.Name = zitiCtrlHostname
data.Controller.ListenerHostPort = zitiCtrlListenerHostPort
data.Controller.ListenerAddress = zitiCtrlListenerAddress
data.Controller.AdvertisedAddress = zitiCtrlAdvertisedAddress
data.Controller.Port = zitiCtrlPort
data.Controller.MgmtListenerHostPort = zitiCtrlMgmtListenerHostPort
data.Controller.Edge.ListenerHostPort = zitiEdgeCtrlListenerHostPort
data.Controller.Edge.AdvertisedHostPort = zitiEdgeCtrlAdvertisedHostPort
@@ -31,7 +31,7 @@ import (
)
const (
optionCtrlListener = "ctrlListener"
optionCtrlPort = "ctrlPort"
optionMgmtListener = "mgmtListener"
optionDatabaseFile = "databaseFile"
)
@@ -46,7 +46,7 @@ var (
ziti create config controller
# Create the controller config with a particular ctrlListener host and port
ziti create config controller --ctrlListener 0.0.0.0:6262
ziti create config controller --ctrlPort 6262
# Print the controller config to the console
ziti create config controller --output stdout
@@ -63,7 +63,7 @@ var controllerConfigTemplate string
type CreateConfigControllerOptions struct {
CreateConfigOptions
CtrlListener string
CtrlPort string
MgmtListener string
}
@@ -92,8 +92,8 @@ func NewCmdCreateConfigController(data *ConfigTemplateValues) *cobra.Command {
}
// Update controller specific values with configOptions passed in if the argument was provided or the value is currently blank
if data.Controller.ListenerHostPort == "" || controllerOptions.CtrlListener != constants.DefaultZitiEdgeListenerHostPort {
data.Controller.ListenerHostPort = controllerOptions.CtrlListener
if data.Controller.Port == "" || controllerOptions.CtrlPort != constants.DefaultZitiControllerPort {
data.Controller.Port = controllerOptions.CtrlPort
}
if data.Controller.MgmtListenerHostPort == "" || controllerOptions.MgmtListener != constants.DefaultZitiMgmtControllerListenerHostPort {
data.Controller.MgmtListenerHostPort = controllerOptions.MgmtListener
@@ -117,7 +117,7 @@ func NewCmdCreateConfigController(data *ConfigTemplateValues) *cobra.Command {
}
func (options *CreateConfigControllerOptions) addFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&options.CtrlListener, optionCtrlListener, constants.DefaultZitiControllerListenerHostPort, "address and port of the config controller listener")
cmd.Flags().StringVar(&options.CtrlPort, optionCtrlPort, constants.DefaultZitiControllerPort, "port to use for the config controller")
cmd.Flags().StringVar(&options.DatabaseFile, optionDatabaseFile, "ctrl.db", "location of the database file")
cmd.Flags().StringVar(&options.MgmtListener, optionMgmtListener, constants.DefaultZitiMgmtControllerListenerHostPort, "address and port of the config management listener")
}
@@ -119,11 +119,15 @@ func NewCmdCreateConfigEnvironment(data *ConfigTemplateValues) *cobra.Command {
"%-36s %-50s %s\n"+
"%-36s %-50s %s\n"+
"%-36s %-50s %s\n"+
"%-36s %-50s %s\n"+
"%-36s %-50s %s\n"+
"%-36s %-50s %s",
cmdhelper.EnvVariableDetails.ZitiHomeVarName, cmdhelper.EnvVariableDetails.ZitiHomeVarDescription, data.ZitiHome,
cmdhelper.EnvVariableDetails.ZitiCtrlListenerHostPortVarName, cmdhelper.EnvVariableDetails.ZitiCtrlListenerHostPortVarDescription, data.Controller.ListenerHostPort,
cmdhelper.EnvVariableDetails.ZitiCtrlPortVarName, cmdhelper.EnvVariableDetails.ZitiCtrlPortVarDescription, data.Controller.Port,
cmdhelper.EnvVariableDetails.ZitiCtrlMgmtListenerHostPortVarName, cmdhelper.EnvVariableDetails.ZitiCtrlMgmtListenerHostPortVarDescription, data.Controller.MgmtListenerHostPort,
cmdhelper.EnvVariableDetails.ZitiCtrlNameVarName, cmdhelper.EnvVariableDetails.ZitiCtrlNameVarDescription, data.Controller.Name,
cmdhelper.EnvVariableDetails.ZitiCtrlAdvertisedAddressVarName, cmdhelper.EnvVariableDetails.ZitiCtrlAdvertisedAddressVarDescription, data.Controller.AdvertisedAddress,
cmdhelper.EnvVariableDetails.ZitiCtrlListenerAddressVarName, cmdhelper.EnvVariableDetails.ZitiCtrlListenerAddressVarDescription, data.Controller.ListenerAddress,
cmdhelper.EnvVariableDetails.ZitiEdgeCtrlListenerHostPortVarName, cmdhelper.EnvVariableDetails.ZitiEdgeCtrlListenerHostPortVarDescription, data.Controller.Edge.ListenerHostPort,
cmdhelper.EnvVariableDetails.ZitiEdgeCtrlAdvertisedHostPortVarName, cmdhelper.EnvVariableDetails.ZitiEdgeCtrlAdvertisedHostPortVarDescription, data.Controller.Edge.AdvertisedHostPort,
cmdhelper.EnvVariableDetails.ZitiEdgeRouterHostnameVarName, cmdhelper.EnvVariableDetails.ZitiEdgeRouterHostnameVarDescription, data.Router.Edge.Hostname,
@@ -146,17 +150,10 @@ func NewCmdCreateConfigEnvironment(data *ConfigTemplateValues) *cobra.Command {
cmd.Long = createConfigLong
environmentOptions.addCreateFlags(cmd)
environmentOptions.addFlags(cmd)
return cmd
}
func (options *CreateConfigEnvironmentOptions) addFlags(cmd *cobra.Command) {
// cmd.Flags().StringVar(&options.CtrlListener, optionCtrlListener, constants.DefaultZitiControllerListenerHostPort, "address and port of the config controller listener")
// cmd.Flags().StringVar(&options.DatabaseFile, optionDatabaseFile, "ctrl.db", "location of the database file")
// cmd.Flags().StringVar(&options.MgmtListener, optionMgmtListener, constants.DefaultZitiMgmtControllerListenerHostPort, "address and port of the config management listener")
}
// run implements the command
func (options *CreateConfigEnvironmentOptions) run() error {
+30 -6
View File
@@ -29,6 +29,7 @@ type EnvVariableMetaData struct {
PathSeparator string
ZitiHomeVarName string
ZitiCtrlNameVarName string
ZitiCtrlPortVarName string
ZitiEdgeRouterHostnameVarName string
ZitiEdgeRouterPortVarName string
ZitiEdgeCtrlIdentityCertVarName string
@@ -41,7 +42,6 @@ type EnvVariableMetaData struct {
ZitiCtrlIdentityCAVarName string
ZitiSigningCertVarName string
ZitiSigningKeyVarName string
ZitiCtrlListenerHostPortVarName string
ZitiCtrlMgmtListenerHostPortVarName string
ZitiEdgeCtrlListenerHostPortVarName string
ZitiEdgeCtrlAdvertisedHostPortVarName string
@@ -49,6 +49,8 @@ type EnvVariableMetaData struct {
ZitiRouterIdentityServerCertVarName string
ZitiRouterIdentityKeyVarName string
ZitiRouterIdentityCAVarName string
ZitiCtrlListenerAddressVarName string
ZitiCtrlAdvertisedAddressVarName string
ZitiHomeVarDescription string
ZitiCtrlNameVarDescription string
ZitiEdgeRouterHostnameVarDescription string
@@ -63,7 +65,9 @@ type EnvVariableMetaData struct {
ZitiCtrlIdentityCAVarDescription string
ZitiSigningCertVarDescription string
ZitiSigningKeyVarDescription string
ZitiCtrlListenerHostPortVarDescription string
ZitiCtrlPortVarDescription string
ZitiCtrlListenerAddressVarDescription string
ZitiCtrlAdvertisedAddressVarDescription string
ZitiCtrlMgmtListenerHostPortVarDescription string
ZitiEdgeCtrlListenerHostPortVarDescription string
ZitiEdgeCtrlAdvertisedHostPortVarDescription string
@@ -79,6 +83,8 @@ var EnvVariableDetails = EnvVariableMetaData{
ZitiHomeVarDescription: "Root home directory for Ziti related files",
ZitiCtrlNameVarName: "ZITI_CONTROLLER_NAME",
ZitiCtrlNameVarDescription: "The name of the Ziti Controller",
ZitiCtrlPortVarName: "ZITI_CTRL_PORT",
ZitiCtrlPortVarDescription: "The port of the Ziti Controller",
ZitiEdgeRouterHostnameVarName: "ZITI_EDGE_ROUTER_HOSTNAME",
ZitiEdgeRouterHostnameVarDescription: "Hostname of the Ziti Edge Router",
ZitiEdgeRouterPortVarName: "ZITI_EDGE_ROUTER_PORT",
@@ -111,8 +117,10 @@ var EnvVariableDetails = EnvVariableMetaData{
ZitiRouterIdentityKeyVarDescription: "Path to Identity Key for Ziti Router",
ZitiRouterIdentityCAVarName: "ZITI_ROUTER_IDENTITY_CA",
ZitiRouterIdentityCAVarDescription: "Path to Identity CA for Ziti Router",
ZitiCtrlListenerHostPortVarName: "ZITI_CTRL_LISTENER_HOST_PORT",
ZitiCtrlListenerHostPortVarDescription: "Host and port of the Ziti Controller Listener",
ZitiCtrlListenerAddressVarName: "ZITI_CTRL_LISTENER_ADDRESS",
ZitiCtrlListenerAddressVarDescription: "The Ziti Controller Listener Address",
ZitiCtrlAdvertisedAddressVarName: "ZITI_CTRL_ADVERTISED_ADDRESS",
ZitiCtrlAdvertisedAddressVarDescription: "The Ziti Controller Advertised Address",
ZitiCtrlMgmtListenerHostPortVarName: "ZITI_CTRL_MGMT_HOST_PORT",
ZitiCtrlMgmtListenerHostPortVarDescription: "Host and port of the Ziti Controller Management Listener",
ZitiEdgeCtrlListenerHostPortVarName: "ZITI_CTRL_EDGE_LISTENER_HOST_PORT",
@@ -336,8 +344,24 @@ func GetZitiEdgeIdentityCA() (string, error) {
return getValueOrSetAndGetDefault(EnvVariableDetails.ZitiEdgeCtrlIdentityCAVarName, fmt.Sprintf("%s/%s-cas.pem", workingDir, controllerName), false)
}
func GetZitiCtrlListenerHostPort() (string, error) {
return getValueOrSetAndGetDefault(EnvVariableDetails.ZitiCtrlListenerHostPortVarName, constants.DefaultZitiControllerListenerHostPort, false)
func GetZitiCtrlAdvertisedAddress() (string, error) {
hostname, err := os.Hostname()
if err != nil {
err := errors.Wrap(err, "Unable to get hostname")
if err != nil {
return "", err
}
}
return getValueOrSetAndGetDefault(EnvVariableDetails.ZitiCtrlAdvertisedAddressVarName, hostname, false)
}
func GetZitiCtrlPort() (string, error) {
return getValueOrSetAndGetDefault(EnvVariableDetails.ZitiCtrlPortVarName, constants.DefaultZitiControllerPort, false)
}
func GetZitiCtrlListenerAddress() (string, error) {
return getValueOrSetAndGetDefault(EnvVariableDetails.ZitiCtrlListenerAddressVarName, constants.DefaultZitiControllerListenerAddress, false)
}
func GetZitiCtrlMgmtListenerHostPort() (string, error) {
+2 -1
View File
@@ -54,7 +54,8 @@ const (
DefaultWebListenerMaxTLSVersion = "TLS1.3"
DefaultZitiEdgeAPIPort = "1280"
DefaultZitiEdgeListenerHostPort = "0.0.0.0:1280"
DefaultZitiControllerListenerHostPort = "0.0.0.0:6262"
DefaultZitiControllerListenerAddress = "0.0.0.0"
DefaultZitiControllerPort = "6262"
DefaultZitiMgmtControllerListenerHostPort = "0.0.0.0:10000"
DefaultControllerHealthCheckIntervalSec = 30
DefaultControllerHealthCheckTimeoutSec = 15