mirror of
https://github.com/openziti/ziti.git
synced 2026-10-15 00:22:01 +00:00
allow csr section to be overridden
This commit is contained in:
@@ -58,11 +58,11 @@ csr:
|
||||
{{ else }}
|
||||
edge:
|
||||
csr:
|
||||
country: US
|
||||
province: NC
|
||||
locality: Charlotte
|
||||
organization: NetFoundry
|
||||
organizationalUnit: Ziti
|
||||
country: {{ .Router.Edge.CsrC }}
|
||||
province: {{ .Router.Edge.CsrST }}
|
||||
locality: {{ .Router.Edge.CsrL }}
|
||||
organization: {{ .Router.Edge.CsrO }}
|
||||
organizationalUnit: {{ .Router.Edge.CsrOU }}
|
||||
sans:
|
||||
dns:
|
||||
- {{ .Router.Edge.AdvertisedHost }}
|
||||
|
||||
@@ -162,6 +162,11 @@ type EdgeRouterTemplateValues struct {
|
||||
AdvertisedHost string
|
||||
LanInterface string
|
||||
ListenerBindPort string
|
||||
CsrC string
|
||||
CsrST string
|
||||
CsrL string
|
||||
CsrO string
|
||||
CsrOU string
|
||||
}
|
||||
|
||||
type WSSRouterTemplateValues struct {
|
||||
@@ -278,6 +283,11 @@ func (data *ConfigTemplateValues) populateConfigValues() {
|
||||
// ************* Router Values ************
|
||||
data.Router.Edge.Port = cmdHelper.GetZitiEdgeRouterPort()
|
||||
data.Router.Edge.ListenerBindPort = cmdHelper.GetZitiEdgeRouterListenerBindPort()
|
||||
data.Router.Edge.CsrC = cmdHelper.GetZitiEdgeRouterC()
|
||||
data.Router.Edge.CsrST = cmdHelper.GetZitiEdgeRouterST()
|
||||
data.Router.Edge.CsrL = cmdHelper.GetZitiEdgeRouterL()
|
||||
data.Router.Edge.CsrO = cmdHelper.GetZitiEdgeRouterO()
|
||||
data.Router.Edge.CsrOU = cmdHelper.GetZitiEdgeRouterOU()
|
||||
data.Router.Listener.GetSessionTimeout = constants.DefaultGetSessionTimeout
|
||||
|
||||
data.Router.Wss.WriteTimeout = foundation.DefaultWsWriteTimeout
|
||||
|
||||
@@ -125,6 +125,11 @@ func NewCmdCreateConfigEnvironment() *cobra.Command {
|
||||
{constants.ZitiRouterIdentityCAVarName, constants.ZitiRouterIdentityCAVarDescription, data.Router.IdentityCA},
|
||||
{constants.ZitiEdgeRouterIPOverrideVarName, constants.ZitiEdgeRouterIPOverrideVarDescription, data.Router.Edge.IPOverride},
|
||||
{constants.ZitiEdgeRouterAdvertisedHostVarName, constants.ZitiEdgeRouterAdvertisedHostVarDescription, data.Router.Edge.AdvertisedHost},
|
||||
{constants.ZitiEdgeRouterCsrCVarName, constants.ZitiEdgeRouterCsrCVarDescription, data.Router.Edge.CsrC},
|
||||
{constants.ZitiEdgeRouterCsrSTVarName, constants.ZitiEdgeRouterCsrSTVarDescription, data.Router.Edge.CsrST},
|
||||
{constants.ZitiEdgeRouterCsrLVarName, constants.ZitiEdgeRouterCsrLVarDescription, data.Router.Edge.CsrL},
|
||||
{constants.ZitiEdgeRouterCsrOVarName, constants.ZitiEdgeRouterCsrOVarDescription, data.Router.Edge.CsrO},
|
||||
{constants.ZitiEdgeRouterCsrOUVarName, constants.ZitiEdgeRouterCsrOUVarDescription, data.Router.Edge.CsrOU},
|
||||
}
|
||||
|
||||
// Setup logging
|
||||
@@ -196,6 +201,11 @@ func NewCmdCreateConfigEnvironment() *cobra.Command {
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiRouterIdentityCAVarName, constants.ZitiRouterIdentityCAVarDescription, data.Router.IdentityCA))
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiEdgeRouterIPOverrideVarName, constants.ZitiEdgeRouterIPOverrideVarDescription, data.Router.Edge.IPOverride))
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiEdgeRouterAdvertisedHostVarName, constants.ZitiEdgeRouterAdvertisedHostVarDescription, data.Router.Edge.AdvertisedHost))
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiEdgeRouterCsrCVarName, constants.ZitiEdgeRouterCsrCVarDescription, data.Router.Edge.CsrC))
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiEdgeRouterCsrSTVarName, constants.ZitiEdgeRouterCsrSTVarDescription, data.Router.Edge.CsrST))
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiEdgeRouterCsrLVarName, constants.ZitiEdgeRouterCsrLVarDescription, data.Router.Edge.CsrL))
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiEdgeRouterCsrOVarName, constants.ZitiEdgeRouterCsrOVarDescription, data.Router.Edge.CsrO))
|
||||
sb.WriteString(fmt.Sprintf("%-40s %-50s %s\n", constants.ZitiEdgeRouterCsrOUVarName, constants.ZitiEdgeRouterCsrOUVarDescription, data.Router.Edge.CsrOU))
|
||||
|
||||
cmd.Long = sb.String()
|
||||
|
||||
|
||||
@@ -287,3 +287,44 @@ func TestEdgeRouterIPOverrideIsConsumed(t *testing.T) {
|
||||
}
|
||||
assert.True(t, found, "Expected value not found; expected to find value of "+constants.ZitiEdgeRouterIPOverrideVarName+" in edge router config output.")
|
||||
}
|
||||
|
||||
func TestEdgeRouterCsrFields(t *testing.T) {
|
||||
routerOptions := clearEnvAndInitializeTestData()
|
||||
routerName := "CstTest"
|
||||
config, data := createRouterConfig([]string{"edge", "--routerName", routerName}, routerOptions, nil)
|
||||
// Check that the template values now contains the custom external IP override value
|
||||
assert.Equal(t, "US", data.Router.Edge.CsrC)
|
||||
assert.Equal(t, "US", config.Edge.Csr.Country)
|
||||
assert.Equal(t, "NC", data.Router.Edge.CsrST)
|
||||
assert.Equal(t, "NC", config.Edge.Csr.Province)
|
||||
assert.Equal(t, "Charlotte", data.Router.Edge.CsrL)
|
||||
assert.Equal(t, "Charlotte", config.Edge.Csr.Locality)
|
||||
assert.Equal(t, "NetFoundry", data.Router.Edge.CsrO)
|
||||
assert.Equal(t, "NetFoundry", config.Edge.Csr.Organization)
|
||||
assert.Equal(t, "Ziti", data.Router.Edge.CsrOU)
|
||||
assert.Equal(t, "Ziti", config.Edge.Csr.OrganizationalUnit)
|
||||
|
||||
C := "C"
|
||||
ST := "ST"
|
||||
L := "L"
|
||||
O := "O"
|
||||
OU := "OU"
|
||||
_ = os.Setenv(constants.ZitiEdgeRouterCsrCVarName, C)
|
||||
_ = os.Setenv(constants.ZitiEdgeRouterCsrSTVarName, ST)
|
||||
_ = os.Setenv(constants.ZitiEdgeRouterCsrLVarName, L)
|
||||
_ = os.Setenv(constants.ZitiEdgeRouterCsrOVarName, O)
|
||||
_ = os.Setenv(constants.ZitiEdgeRouterCsrOUVarName, OU)
|
||||
|
||||
config2, data2 := createRouterConfig([]string{"edge", "--routerName", routerName}, routerOptions, nil)
|
||||
// Check that the template values now contains the custom external IP override value
|
||||
assert.Equal(t, C, data2.Router.Edge.CsrC)
|
||||
assert.Equal(t, C, config2.Edge.Csr.Country)
|
||||
assert.Equal(t, ST, data2.Router.Edge.CsrST)
|
||||
assert.Equal(t, ST, config2.Edge.Csr.Province)
|
||||
assert.Equal(t, L, data2.Router.Edge.CsrL)
|
||||
assert.Equal(t, L, config2.Edge.Csr.Locality)
|
||||
assert.Equal(t, O, data2.Router.Edge.CsrO)
|
||||
assert.Equal(t, O, config2.Edge.Csr.Organization)
|
||||
assert.Equal(t, OU, data2.Router.Edge.CsrOU)
|
||||
assert.Equal(t, OU, config2.Edge.Csr.OrganizationalUnit)
|
||||
}
|
||||
|
||||
@@ -64,6 +64,11 @@ func getZitiEnvironmentVariables() []string {
|
||||
"ZITI_PKI_ALT_SERVER_CERT",
|
||||
"ZITI_PKI_ALT_SERVER_KEY",
|
||||
"ZITI_CTRL_EDGE_BIND_ADDRESS",
|
||||
"ZITI_EDGE_ROUTER_CSR_C",
|
||||
"ZITI_EDGE_ROUTER_CSR_ST",
|
||||
"ZITI_EDGE_ROUTER_CSR_L",
|
||||
"ZITI_EDGE_ROUTER_CSR_O",
|
||||
"ZITI_EDGE_ROUTER_CSR_OU",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +120,7 @@ func TestNoUnknownOutputEnvVariablesExist(t *testing.T) {
|
||||
|
||||
assert.Zero(t, len(unknownValues))
|
||||
for _, value := range unknownValues {
|
||||
fmt.Printf("The variable %s was found in env command output but was not expected.\n -If this is a new variable, add it to the ZITI env variables list in create_config_test.\n -If this variable was removed, remove the variable from the env command output.\n", value)
|
||||
fmt.Printf("The variable %s was found in env command output but was not expected.\n -If this is a new variable, add it to the ZITI env variables list in create_config_test.getZitiEnvironmentVariables().\n -If this variable was removed, remove the variable from the env command output.\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +199,7 @@ func TestAllKnownEnvVariablesAreFoundInHelpOutput(t *testing.T) {
|
||||
|
||||
assert.Zero(t, len(unfoundVariables))
|
||||
for _, value := range unfoundVariables {
|
||||
fmt.Printf("The variable %s was expected in env command's help output but was not found.\n -If this is variable was removed, remove it from the ZITI env variables list in create_config_test.\n -If this is a new variable, add it to the env command's help output.\n", value)
|
||||
fmt.Printf("The variable %s was expected in env command's help output but was not found.\n -If this is variable was removed, remove it from the ZITI env variables list in create_config_test.getZitiEnvironmentVariables().\n -If this is a new variable, add it to the env command's help output.\n", value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,6 +158,26 @@ func GetCtrlEdgeRouterEnrollmentDuration() time.Duration {
|
||||
return time.Duration(retValInt) * time.Minute
|
||||
}
|
||||
|
||||
func GetZitiEdgeRouterC() string {
|
||||
return getFromEnv(constants.ZitiEdgeRouterCsrCVarName, defaultValue(constants.DefaultEdgeRouterCsrC))
|
||||
}
|
||||
|
||||
func GetZitiEdgeRouterST() string {
|
||||
return getFromEnv(constants.ZitiEdgeRouterCsrSTVarName, defaultValue(constants.DefaultEdgeRouterCsrST))
|
||||
}
|
||||
|
||||
func GetZitiEdgeRouterL() string {
|
||||
return getFromEnv(constants.ZitiEdgeRouterCsrLVarName, defaultValue(constants.DefaultEdgeRouterCsrL))
|
||||
}
|
||||
|
||||
func GetZitiEdgeRouterO() string {
|
||||
return getFromEnv(constants.ZitiEdgeRouterCsrOVarName, defaultValue(constants.DefaultEdgeRouterCsrO))
|
||||
}
|
||||
|
||||
func GetZitiEdgeRouterOU() string {
|
||||
return getFromEnv(constants.ZitiEdgeRouterCsrOUVarName, defaultValue(constants.DefaultEdgeRouterCsrOU))
|
||||
}
|
||||
|
||||
type envVarNotFound func() string
|
||||
|
||||
func getFromEnv(envVarName string, onNotFound envVarNotFound) string {
|
||||
|
||||
@@ -46,6 +46,12 @@ const (
|
||||
|
||||
DefaultCtrlEdgeBindAddress = "0.0.0.0"
|
||||
DefaultCtrlEdgeAdvertisedPort = "1280"
|
||||
|
||||
DefaultEdgeRouterCsrC = "US"
|
||||
DefaultEdgeRouterCsrST = "NC"
|
||||
DefaultEdgeRouterCsrL = "Charlotte"
|
||||
DefaultEdgeRouterCsrO = "NetFoundry"
|
||||
DefaultEdgeRouterCsrOU = "Ziti"
|
||||
)
|
||||
|
||||
// Env Var Constants
|
||||
@@ -113,4 +119,14 @@ const (
|
||||
ZitiEdgeRouterAdvertisedHostVarDescription = "The advertised host of the router"
|
||||
ZitiEdgeRouterListenerBindPortVarName = "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT"
|
||||
ZitiEdgeRouterListenerBindPortVarDescription = "The port a public router will advertise on"
|
||||
ZitiEdgeRouterCsrCVarName = "ZITI_EDGE_ROUTER_CSR_C"
|
||||
ZitiEdgeRouterCsrCVarDescription = "The country (C) to use for router CSRs"
|
||||
ZitiEdgeRouterCsrSTVarName = "ZITI_EDGE_ROUTER_CSR_ST"
|
||||
ZitiEdgeRouterCsrSTVarDescription = "The state/province (ST) to use for router CSRs"
|
||||
ZitiEdgeRouterCsrLVarName = "ZITI_EDGE_ROUTER_CSR_L"
|
||||
ZitiEdgeRouterCsrLVarDescription = "The locality (L) to use for router CSRs"
|
||||
ZitiEdgeRouterCsrOVarName = "ZITI_EDGE_ROUTER_CSR_O"
|
||||
ZitiEdgeRouterCsrOVarDescription = "The organization (O) to use for router CSRs"
|
||||
ZitiEdgeRouterCsrOUVarName = "ZITI_EDGE_ROUTER_CSR_OU"
|
||||
ZitiEdgeRouterCsrOUVarDescription = "The organization unit to use for router CSRs"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user