Skip to content

Commit

Permalink
Merge pull request #2310 from openziti/linux-docker-configure-console
Browse files Browse the repository at this point in the history
Linux docker configure console
  • Loading branch information
qrkourier authored Sep 11, 2024
2 parents c665010 + 98b7d6d commit 738ddfb
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 5 deletions.
11 changes: 11 additions & 0 deletions dist/dist-packages/linux/openziti-controller/bootstrap.bash
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ makeConfig() {
_command+=("${ZITI_BOOTSTRAP_CONFIG_ARGS}")
fi

# don't configure the console if explicitly disabled or if the location is not set or console files are missing
if [[ "${ZITI_BOOTSTRAP_CONSOLE:-}" == true && -n "${ZITI_CONSOLE_LOCATION:-}" ]]; then
if [[ ! -s "${ZITI_CONSOLE_LOCATION}/index.html" ]]; then
echo "WARN: ${ZITI_CONSOLE_LOCATION}/index.html is missing; install 'openziti-console' to enable the console" >&2
fi
elif [[ "${ZITI_BOOTSTRAP_CONSOLE:-}" == false ]]; then
unset ZITI_CONSOLE_LOCATION
echo "DEBUG: ZITI_CONSOLE_LOCATION unset because ZITI_BOOTSTRAP_CONSOLE is false" >&3
fi

if [[ -s "${_config_file}" && "${1:-}" == --force ]]; then
echo "INFO: recreating config file: ${_config_file}"
mv --no-clobber "${_config_file}"{,".${ZITI_BOOTSTRAP_NOW}.old"}
Expand Down Expand Up @@ -563,6 +573,7 @@ else
SVC_ENV_FILE=/opt/openziti/etc/controller/service.env
BOOT_ENV_FILE=/opt/openziti/etc/controller/bootstrap.env
SVC_FILE=/etc/systemd/system/ziti-controller.service.d/override.conf
: "${ZITI_CONSOLE_LOCATION:=/opt/openziti/share/console}"

if [[ "${1:-}" =~ ^[-] ]]
then
Expand Down
8 changes: 8 additions & 0 deletions dist/dist-packages/linux/openziti-controller/service.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# utilized by bootstrap.bash to distinguish between systemd and docker
ZITI_RUNTIME='systemd'

# set "false" to disable bootstrapping
ZITI_BOOTSTRAP=''
Expand All @@ -12,6 +14,12 @@ ZITI_BOOTSTRAP_CONFIG='true'
# create a new database unless it exists
ZITI_BOOTSTRAP_DATABASE='true'

# configure the web console if 'true'
ZITI_BOOTSTRAP_CONSOLE='true'

# configure controller to serve static HTML provided by openziti-console package
ZITI_CONSOLE_LOCATION='/opt/openziti/share/console'

# BASH script that defines function bootstrap()
ZITI_CTRL_BOOTSTRAP_BASH='/opt/openziti/etc/controller/bootstrap.bash'

Expand Down
2 changes: 2 additions & 0 deletions dist/docker-images/ziti-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ COPY ${CONTROLLER_PACKAGE}/entrypoint.bash /

# copy the console SPA build files
COPY --from=ziti-console /usr/src/app/dist/app-ziti-console /ziti-console
ENV ZITI_CONSOLE_LOCATION=/ziti-console

RUN mkdir -p /ziti-controller
RUN chown -R ziggy:ziggy /ziti-controller /ziti-console
Expand All @@ -52,6 +53,7 @@ ENV ZITI_BOOTSTRAP=true
ENV ZITI_BOOTSTRAP_PKI=true
ENV ZITI_BOOTSTRAP_CONFIG=true
ENV ZITI_BOOTSTRAP_DATABASE=true
ENV ZITI_BOOTSTRAP_CONSOLE=true

# defaults for bootstrapping PKI
ENV ZITI_PKI_ROOT=pki
Expand Down
8 changes: 4 additions & 4 deletions ziti/cmd/create/config_templates/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ web:
options: { }
- binding: fabric
options: { }
#- binding: zac
# options:
# location: /ziti-console
# indexFile: index.html
{{ if not .Controller.Web.BindPoints.Console.Enabled }}#{{- end }}- binding: zac
{{ if not .Controller.Web.BindPoints.Console.Enabled }}#{{- end }} options:
{{ if not .Controller.Web.BindPoints.Console.Enabled }}#{{- end }} location: {{ .Controller.Web.BindPoints.Console.Location }}
{{ if not .Controller.Web.BindPoints.Console.Enabled }}#{{- end }} indexFile: index.html
6 changes: 6 additions & 0 deletions ziti/cmd/create/create_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ type BindPointsValues struct {
InterfacePort string
AddressAddress string
AddressPort string
Console ConsoleValues
}

type ConsoleValues struct {
Enabled bool
Location string
}

type IdentityValues struct {
Expand Down
23 changes: 23 additions & 0 deletions ziti/cmd/create/create_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func NewCmdCreateConfigController() *CreateControllerConfigCmd {
SetControllerIdentity(&data.Controller)
SetEdgeConfig(&data.Controller)
SetWebConfig(&data.Controller)
// process console options
SetConsoleConfig(&data.Controller.Web.BindPoints.Console)

},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -197,27 +199,31 @@ func SetControllerIdentity(data *ControllerTemplateValues) {
SetControllerIdentityKey(data)
SetControllerIdentityCA(data)
}

func SetControllerIdentityCert(c *ControllerTemplateValues) {
val := os.Getenv(constants.PkiCtrlCertVarName)
if val == "" {
val = helpers.GetZitiHome() + "/" + helpers.HostnameOrNetworkName() + ".cert" // default
}
c.Identity.Cert = helpers.NormalizePath(val)
}

func SetControllerIdentityServerCert(c *ControllerTemplateValues) {
val := os.Getenv(constants.PkiCtrlServerCertVarName)
if val == "" {
val = helpers.GetZitiHome() + "/" + helpers.HostnameOrNetworkName() + ".server.chain.cert" // default
}
c.Identity.ServerCert = helpers.NormalizePath(val)
}

func SetControllerIdentityKey(c *ControllerTemplateValues) {
val := os.Getenv(constants.PkiCtrlKeyVarName)
if val == "" {
val = helpers.GetZitiHome() + "/" + helpers.HostnameOrNetworkName() + ".key" // default
}
c.Identity.Key = helpers.NormalizePath(val)
}

func SetControllerIdentityCA(c *ControllerTemplateValues) {
val := os.Getenv(constants.PkiCtrlCAVarName)
if val == "" {
Expand All @@ -230,6 +236,7 @@ func SetEdgeConfig(data *ControllerTemplateValues) {
SetEdgeSigningCert(data)
SetEdgeSigningKey(data)
}

func SetEdgeSigningCert(c *ControllerTemplateValues) {
val := os.Getenv(constants.PkiSignerCertVarName)
if val == "" {
Expand All @@ -238,6 +245,7 @@ func SetEdgeSigningCert(c *ControllerTemplateValues) {
c.EdgeEnrollment.SigningCert = helpers.NormalizePath(val)

}

func SetEdgeSigningKey(c *ControllerTemplateValues) {
val := os.Getenv(constants.PkiSignerKeyVarName)
if val == "" {
Expand All @@ -253,27 +261,42 @@ func SetWebConfig(data *ControllerTemplateValues) {
SetWebIdentityCA(data)
SetCtrlAltServerCerts(data)
}

func SetConsoleConfig(v *ConsoleValues) {
location := strings.TrimSpace(os.Getenv(constants.CtrlConsoleLocationVarName))
if location == "" {
v.Enabled = false
v.Location = "./console"
} else {
v.Enabled = true
v.Location = helpers.NormalizePath(location)
}
}

func SetWebIdentityCert(c *ControllerTemplateValues) {
val := os.Getenv(constants.CtrlPkiEdgeCertVarName)
if val == "" {
val = c.Identity.Cert //default
}
c.Web.Identity.Cert = helpers.NormalizePath(val)
}

func SetWebIdentityServerCert(c *ControllerTemplateValues) {
val := os.Getenv(constants.CtrlPkiEdgeServerCertVarName)
if val == "" {
val = c.Identity.ServerCert //default
}
c.Web.Identity.ServerCert = helpers.NormalizePath(val)
}

func SetWebIdentityKey(c *ControllerTemplateValues) {
val := os.Getenv(constants.CtrlPkiEdgeKeyVarName)
if val == "" {
val = c.Identity.Key //default
}
c.Web.Identity.Key = helpers.NormalizePath(val)
}

func SetWebIdentityCA(c *ControllerTemplateValues) {
val := os.Getenv(constants.CtrlPkiEdgeCAVarName)
if val == "" {
Expand Down
5 changes: 4 additions & 1 deletion ziti/cmd/create/create_config_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (options *CreateConfigEnvironmentOptions) addFlags(cmd *cobra.Command) {
// NewCmdCreateConfigEnvironment creates a command object for the "environment" command
func NewCmdCreateConfigEnvironment() *cobra.Command {
environmentOptions = &CreateConfigEnvironmentOptions{}

data := &ConfigTemplateValues{}

cmd := &cobra.Command{
Expand All @@ -98,6 +98,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command {
SetControllerIdentity(&data.Controller)
SetEdgeConfig(&data.Controller)
SetWebConfig(&data.Controller)
SetConsoleConfig(&data.Controller.Web.BindPoints.Console)

environmentOptions.EnvVars = []EnvVar{
{constants.ZitiHomeVarName, constants.ZitiHomeVarDescription, data.ZitiHome},
Expand All @@ -110,6 +111,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command {
{constants.CtrlBindAddressVarName, constants.CtrlBindAddressVarDescription, data.Controller.Ctrl.BindAddress},
{constants.CtrlAdvertisedAddressVarName, constants.CtrlAdvertisedAddressVarDescription, data.Controller.Ctrl.AdvertisedAddress},
{constants.CtrlAdvertisedPortVarName, constants.CtrlAdvertisedPortVarDescription, data.Controller.Ctrl.AdvertisedPort},
{constants.CtrlConsoleLocationVarName, constants.CtrlConsoleLocationVarDescription, data.Controller.Web.BindPoints.Console.Location},
{constants.CtrlEdgeAdvertisedAddressVarName, constants.CtrlEdgeAdvertisedAddressVarDescription, data.Controller.EdgeApi.Address},
{constants.CtrlEdgeAltAdvertisedAddressVarName, constants.CtrlEdgeAltAdvertisedAddressVarDescription, data.Controller.EdgeApi.Address},
{constants.CtrlEdgeAdvertisedPortVarName, constants.CtrlEdgeAdvertisedPortVarDescription, data.Controller.EdgeApi.Port},
Expand Down Expand Up @@ -197,6 +199,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command {
sb.WriteString(fmt.Sprintf("%-40s %-50s\n", constants.CtrlAdvertisedAddressVarName, constants.CtrlAdvertisedAddressVarDescription))
sb.WriteString(fmt.Sprintf("%-40s %-50s\n", constants.CtrlEdgeAltAdvertisedAddressVarName, constants.CtrlEdgeAltAdvertisedAddressVarDescription))
sb.WriteString(fmt.Sprintf("%-40s %-50s\n", constants.CtrlAdvertisedPortVarName, constants.CtrlAdvertisedPortVarDescription))
sb.WriteString(fmt.Sprintf("%-40s %-50s\n", constants.CtrlConsoleLocationVarName, constants.CtrlConsoleLocationVarDescription))
sb.WriteString(fmt.Sprintf("%-40s %-50s\n", constants.CtrlEdgeBindAddressVarName, constants.CtrlEdgeBindAddressVarDescription))
sb.WriteString(fmt.Sprintf("%-40s %-50s\n", constants.CtrlEdgeAdvertisedPortVarName, constants.CtrlEdgeAdvertisedPortVarDescription))
sb.WriteString(fmt.Sprintf("%-40s %-50s\n", constants.PkiSignerCertVarName, constants.PkiSignerCertVarDescription))
Expand Down
1 change: 1 addition & 0 deletions ziti/cmd/create/create_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func getZitiEnvironmentVariables() []string {
"ZITI_CTRL_DATABASE_FILE",
"ZITI_CTRL_EDGE_ALT_ADVERTISED_ADDRESS",
"ZITI_CTRL_ADVERTISED_PORT",
"ZITI_CONSOLE_LOCATION",
"ZITI_PKI_SIGNER_CERT",
"ZITI_PKI_SIGNER_KEY",
"ZITI_CTRL_EDGE_ADVERTISED_ADDRESS",
Expand Down
2 changes: 2 additions & 0 deletions ziti/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const (
CtrlAdvertisedAddressVarDescription = "The address routers will use to connect to the controller"
CtrlAdvertisedPortVarName = "ZITI_CTRL_ADVERTISED_PORT"
CtrlAdvertisedPortVarDescription = "TCP port routers will use to connect to the controller"
CtrlConsoleLocationVarName = "ZITI_CONSOLE_LOCATION"
CtrlConsoleLocationVarDescription = "The filesystem path to controller's web console static HTML files"
CtrlEdgeBindAddressVarName = "ZITI_CTRL_EDGE_BIND_ADDRESS"
CtrlEdgeBindAddressVarDescription = "The address where the controller will listen for edge API connections"
CtrlEdgeAdvertisedAddressVarName = "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS"
Expand Down

0 comments on commit 738ddfb

Please sign in to comment.