From 77f8316456bd040601e16f8fc0ed85927cc175d7 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 24 Mar 2023 12:45:31 -0400 Subject: [PATCH 01/26] smerging latest from release-next and original branch Signed-off-by: gberl002 --- doc/003-local-deploy.md | 2 +- quickstart/README.md | 2 +- quickstart/docker/.env | 11 +- quickstart/docker/docker-compose.yml | 36 +- quickstart/docker/image/Dockerfile | 2 +- quickstart/docker/image/run-controller.sh | 17 +- quickstart/docker/image/run-router.sh | 45 +- quickstart/docker/image/run-with-ziti-cli.sh | 15 +- quickstart/docker/image/ziti-cli-functions.sh | 2153 ++++++++--------- .../docker/simplified-docker-compose.yml | 17 +- quickstart/local/add-zcat.sh | 2 +- quickstart/local/restart-ziti.sh | 2 +- quickstart/local/run-dns.sh | 44 - quickstart/local/test-ziti.sh | 8 +- quickstart/test/quickstart_test.go | 8 +- quickstart/ziti-cli-functions.sh | 1 - ziti/cmd/config_templates/controller.yml | 106 +- ziti/cmd/config_templates/router.yml | 2 +- ziti/cmd/create_config.go | 251 +- ziti/cmd/create_config_controller.go | 87 +- ziti/cmd/create_config_controller_test.go | 970 ++++++-- ziti/cmd/create_config_environment.go | 91 +- ziti/cmd/create_config_router.go | 3 +- ziti/cmd/create_config_router_common.go | 2 +- ziti/cmd/create_config_router_edge_test.go | 70 +- ziti/cmd/create_config_router_fabric_test.go | 19 +- ziti/cmd/create_config_router_test.go | 34 +- ziti/cmd/create_config_test.go | 75 +- ziti/cmd/helpers/env_helpers.go | 156 +- ziti/cmd/helpers/helpers_test.go | 370 +-- ziti/cmd/{ => install}/common_install_test.go | 4 +- ziti/constants/constants.go | 133 +- 32 files changed, 2434 insertions(+), 2304 deletions(-) mode change 100755 => 100644 quickstart/docker/image/ziti-cli-functions.sh delete mode 100755 quickstart/local/run-dns.sh delete mode 120000 quickstart/ziti-cli-functions.sh rename ziti/cmd/{ => install}/common_install_test.go (91%) diff --git a/doc/003-local-deploy.md b/doc/003-local-deploy.md index 74106bdaf..6dc4d6ed4 100644 --- a/doc/003-local-deploy.md +++ b/doc/003-local-deploy.md @@ -83,7 +83,7 @@ Generate a configuration file for router01. ```bash ZITI_HOME=./db \ ZITI_CTRL_ADVERTISED_ADDRESS=127.0.0.1 \ -ZITI_EDGE_ROUTER_RAWNAME=localhost \ +ZITI_EDGE_ROUTER_NAME=localhost \ ziti create config router edge \ --routerName router01 \ --output ./db/router01-config.yml diff --git a/quickstart/README.md b/quickstart/README.md index 7e16850b3..087d58253 100644 --- a/quickstart/README.md +++ b/quickstart/README.md @@ -103,7 +103,7 @@ Ziti Controller: Ziti Edge Router: - routerName=edge-router; docker run -d --name "${zitinw}-${routerName}" --rm -e ZITI_EDGE_ROUTER_RAWNAME="${routerName}" --volume "${zitinw_shared}":/openziti/shared -it --network="${zitinw}" --hostname "${routerName}" --network-alias="${routerName}" --rm openziti/quickstart /openziti/scripts/run-router.sh edge + routerName=edge-router; docker run -d --name "${zitinw}-${routerName}" --rm -e ZITI_EDGE_ROUTER_NAME="${routerName}" --volume "${zitinw_shared}":/openziti/shared -it --network="${zitinw}" --hostname "${routerName}" --network-alias="${routerName}" --rm openziti/quickstart /openziti/scripts/run-router.sh edge diff --git a/quickstart/docker/.env b/quickstart/docker/.env index af21b1eff..9e4a2791f 100644 --- a/quickstart/docker/.env +++ b/quickstart/docker/.env @@ -8,16 +8,13 @@ ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION=10080 ZITI_EDGE_ROUTER_ENROLLMENT_DURATION=10080 # controller address/port information -ZITI_CONTROLLER_RAWNAME=ziti-controller -#ZITI_CONTROLLER_HOSTNAME=advertised.address -#ZITI_CTRL_PORT=8440 +ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=ziti-edge-controller +#ZITI_CTRL_EDGE_ADVERTISED_PORT=8441 +#ZITI_CTRL_WEB_LISTENER_PORT=8440 -ZITI_EDGE_CONTROLLER_RAWNAME=ziti-edge-controller -#ZITI_EDGE_CONTROLLER_HOSTNAME=advertised.address -#ZITI_EDGE_CONTROLLER_PORT=8441 #ZITI_EDGE_CONTROLLER_IP_OVERRIDE=172.17.0.1 # router address/port information -#ZITI_EDGE_ROUTER_RAWNAME=advertised.address +#ZITI_EDGE_ROUTER_NAME=advertised.address #ZITI_EDGE_ROUTER_PORT=8442 #ZITI_EDGE_ROUTER_IP_OVERRIDE=172.17.0.1 diff --git a/quickstart/docker/docker-compose.yml b/quickstart/docker/docker-compose.yml index 7cff37dce..af9ce4570 100644 --- a/quickstart/docker/docker-compose.yml +++ b/quickstart/docker/docker-compose.yml @@ -5,8 +5,8 @@ services: env_file: - ./.env ports: - - ${ZITI_EDGE_CONTROLLER_PORT:-1280}:${ZITI_EDGE_CONTROLLER_PORT:-1280} - - ${ZITI_CTRL_PORT:-6262}:${ZITI_CTRL_PORT:-6262} + - ${ZITI_CTRL_EDGE_ADVERTISED_PORT:-1280}:${ZITI_CTRL_EDGE_ADVERTISED_PORT:-1280} + - ${ZITI_CTRL_LISTENER_PORT:-6262}:${ZITI_CTRL_LISTENER_PORT:-6262} environment: - ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION=${ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION} - ZITI_EDGE_ROUTER_ENROLLMENT_DURATION=${ZITI_EDGE_ROUTER_ENROLLMENT_DURATION} @@ -27,8 +27,7 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" env_file: - ./.env networks: @@ -50,9 +49,8 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" - - ZITI_EDGE_ROUTER_RAWNAME=${ZITI_EDGE_ROUTER_RAWNAME:-ziti-edge-router} + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + - ZITI_EDGE_ROUTER_NAME=${ZITI_EDGE_ROUTER_NAME:-ziti-edge-router} - ZITI_EDGE_ROUTER_ROLES=public ports: - ${ZITI_EDGE_ROUTER_PORT:-3022}:${ZITI_EDGE_ROUTER_PORT:-3022} @@ -69,9 +67,8 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" - - ZITI_EDGE_ROUTER_RAWNAME=ziti-edge-router-wss + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + - ZITI_EDGE_ROUTER_NAME=ziti-edge-router-wss - ZITI_EDGE_ROUTER_PORT=3023 - ZITI_EDGE_ROUTER_ROLES=public ports: @@ -89,9 +86,8 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" - - ZITI_EDGE_ROUTER_RAWNAME=ziti-fabric-router-br + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + - ZITI_EDGE_ROUTER_NAME=ziti-fabric-router-br #ports: # - 3024:3024 networks: @@ -107,9 +103,8 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" - - ZITI_EDGE_ROUTER_RAWNAME=ziti-private-red + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + - ZITI_EDGE_ROUTER_NAME=ziti-private-red #ports: # - 3025:3025 networks: @@ -124,9 +119,8 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" - - ZITI_EDGE_ROUTER_RAWNAME=ziti-private-blue + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + - ZITI_EDGE_ROUTER_NAME=ziti-private-blue #ports: # - 3026:3026 networks: @@ -150,8 +144,8 @@ services: ziti-console: image: openziti/zac environment: - - ZAC_SERVER_CERT_CHAIN=/persistent/pki/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-intermediate/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-server.cert - - ZAC_SERVER_KEY=/persistent/pki/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-intermediate/keys/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-server.key + - ZAC_SERVER_CERT_CHAIN=/persistent/pki/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-intermediate/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-server.cert + - ZAC_SERVER_KEY=/persistent/pki/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-intermediate/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-server.key - PORTTLS=8443 ports: - 1408:1408 diff --git a/quickstart/docker/image/Dockerfile b/quickstart/docker/image/Dockerfile index a7e4bac4c..bfbec1755 100644 --- a/quickstart/docker/image/Dockerfile +++ b/quickstart/docker/image/Dockerfile @@ -32,7 +32,7 @@ ENV ZITI_BIN_ROOT="${ZITI_BIN_DIR}" ENV ZITI_SCRIPTS=/var/openziti/scripts # copy the ziti binaries to a directory already on the path -COPY --chown=ziti --from=fetch-ziti-bins /ziti-bin "${ZITI_BIN_DIR}" +COPY --chown=ziti ziti.ignore "${ZITI_BIN_DIR}" COPY --chown=ziti ziti-cli-functions.sh "${ZITI_SCRIPTS}/" COPY --chown=ziti run-controller.sh "${ZITI_SCRIPTS}/" COPY --chown=ziti run-router.sh "${ZITI_SCRIPTS}/" diff --git a/quickstart/docker/image/run-controller.sh b/quickstart/docker/image/run-controller.sh index 21a0c34b3..af3788dec 100755 --- a/quickstart/docker/image/run-controller.sh +++ b/quickstart/docker/image/run-controller.sh @@ -1,18 +1,19 @@ #!/bin/bash - +echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS is ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" ziti_controller_cfg="${ZITI_HOME}/ziti-edge-controller.yaml" -export ZITI_CONTROLLER_RAWNAME=ziti-controller -export ZITI_EDGE_CONTROLLER_RAWNAME=ziti-edge-controller +export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=ziti-edge-controller . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" -generateEnvFile +echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS is ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" +setupEnvironment +persistEnvironmentValues . ${ZITI_HOME}/ziti.env - +echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS is ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" # create pki createPki - +echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS is ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" if [ ! -f "${ziti_controller_cfg}" ]; then echo " " echo "${ziti_controller_cfg} doesn't exist. Generating config file" @@ -26,9 +27,9 @@ else fi # initialize the database with the admin user: -"${ZITI_BIN_DIR}/ziti-controller" edge init "${ZITI_HOME}/ziti-edge-controller.yaml" -u "${ZITI_USER}" -p "${ZITI_PWD}" +"${ZITI_BIN_DIR}/ziti" controller edge init "${ZITI_HOME}/ziti-edge-controller.yaml" -u "${ZITI_USER}" -p "${ZITI_PWD}" # create a place for the internal db mkdir -p $ZITI_HOME/db -"${ZITI_BIN_DIR}/ziti-controller" run "${ZITI_HOME}/ziti-edge-controller.yaml" +"${ZITI_BIN_DIR}/ziti" controller run "${ZITI_HOME}/ziti-edge-controller.yaml" diff --git a/quickstart/docker/image/run-router.sh b/quickstart/docker/image/run-router.sh index 5ffe384c9..4e2df0fdf 100755 --- a/quickstart/docker/image/run-router.sh +++ b/quickstart/docker/image/run-router.sh @@ -5,60 +5,53 @@ sleep 5 . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" -if [[ "${ZITI_CONTROLLER_RAWNAME-}" == "" ]]; then export ZITI_CONTROLLER_RAWNAME="ziti-controller"; fi -if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_RAWNAME="ziti-edge-controller"; fi -if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then - export ZITI_EDGE_ROUTER_DESIRED_RAWNAME="${ZITI_NETWORK-}-edge-router" +if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="ziti-edge-controller"; fi +if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then + ZITI_EDGE_ROUTER_DESIRED_NAME="${ZITI_NETWORK-}-edge-router" else - ZITI_EDGE_ROUTER_DESIRED_RAWNAME="${ZITI_EDGE_ROUTER_RAWNAME}" + ZITI_EDGE_ROUTER_DESIRED_NAME="${ZITI_EDGE_ROUTER_NAME}" fi if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi -if [[ "${ZITI_EDGE_ROUTER_HOSTNAME}" == "" ]]; then export ZITI_EDGE_ROUTER_HOSTNAME="${ZITI_EDGE_ROUTER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi -if [[ "${ZITI_EDGE_ROUTER_ROLES}" == "" ]]; then export ZITI_EDGE_ROUTER_ROLES="${ZITI_EDGE_ROUTER_RAWNAME}"; fi +if [[ "${ZITI_ROUTER_ADVERTISED_ADDRESS}" == "" ]]; then export ZITI_ROUTER_ADVERTISED_ADDRESS="${ZITI_EDGE_ROUTER_NAME}${ZITI_DOMAIN_SUFFIX}"; fi +if [[ "${ZITI_EDGE_ROUTER_ROLES}" == "" ]]; then export ZITI_EDGE_ROUTER_ROLES="${ZITI_EDGE_ROUTER_NAME}"; fi . ${ZITI_HOME}/ziti.env # This is a unique situation due to the env file being shared among all routers so we need to explicitly set the router -export ZITI_EDGE_ROUTER_RAWNAME="${ZITI_EDGE_ROUTER_DESIRED_RAWNAME}" +export ZITI_EDGE_ROUTER_NAME="${ZITI_EDGE_ROUTER_DESIRED_NAME}" -# shellcheck disable=SC2091 -until $(curl -s -o /dev/null --fail -k "https://${ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT}"); do - echo "waiting for https://${ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT}" - sleep 2 -done - -createRouterPki "${ZITI_EDGE_ROUTER_RAWNAME}" +_wait_for_controller zitiLogin if [[ "$1" == "edge" ]]; then echo "CREATING EDGE ROUTER CONFIG" - createEdgeRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createEdgeRouterConfig "${ZITI_EDGE_ROUTER_NAME}" fi if [[ "$1" == "wss" ]]; then echo "CREATING EDGE ROUTER WSS CONFIG" - createEdgeRouterWssConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createEdgeRouterWssConfig "${ZITI_EDGE_ROUTER_NAME}" fi if [[ "$1" == "fabric" ]]; then echo "CREATING FABRIC ROUTER CONFIG" - createFabricRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createFabricRouterConfig "${ZITI_EDGE_ROUTER_NAME}" fi if [[ "$1" == "private" ]]; then echo "CREATING PRIVATE ROUTER CONFIG" - createPrivateRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createPrivateRouterConfig "${ZITI_EDGE_ROUTER_NAME}" fi -echo "---------- Creating edge-router ${ZITI_EDGE_ROUTER_HOSTNAME}...." -found=$(ziti edge list edge-routers 'name = "'"${ZITI_EDGE_ROUTER_HOSTNAME}"'"' | grep -c "${ZITI_EDGE_ROUTER_HOSTNAME}") +echo "---------- Creating edge-router ${ZITI_ROUTER_ADVERTISED_ADDRESS}...." +found=$(ziti edge list edge-routers 'name = "'"${ZITI_ROUTER_ADVERTISED_ADDRESS}"'"' | grep -c "${ZITI_ROUTER_ADVERTISED_ADDRESS}") if [[ found -gt 0 ]]; then - echo "---------- Found existing edge-router ${ZITI_EDGE_ROUTER_HOSTNAME}...." + echo "---------- Found existing edge-router ${ZITI_ROUTER_ADVERTISED_ADDRESS}...." else - "${ZITI_BIN_DIR}/ziti" edge create edge-router "${ZITI_EDGE_ROUTER_HOSTNAME}" -o "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.jwt" -t -a "${ZITI_EDGE_ROUTER_ROLES}" + "${ZITI_BIN_DIR}/ziti" edge create edge-router "${ZITI_ROUTER_ADVERTISED_ADDRESS}" -o "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.jwt" -t -a "${ZITI_EDGE_ROUTER_ROLES}" sleep 1 - echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_HOSTNAME}...." - "${ZITI_BIN_DIR}/ziti-router" enroll "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.yaml" --jwt "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.jwt" + echo "---------- Enrolling edge-router ${ZITI_ROUTER_ADVERTISED_ADDRESS}...." + "${ZITI_BIN_DIR}/ziti-router" enroll "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml" --jwt "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.jwt" echo "" fi -"${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${ZITI_HOME}/ziti-${ZITI_EDGE_ROUTER_HOSTNAME}.log" +"${ZITI_BIN_DIR}/ziti router" run "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml" > "${ZITI_HOME}/ziti-${ZITI_ROUTER_ADVERTISED_ADDRESS}.log" diff --git a/quickstart/docker/image/run-with-ziti-cli.sh b/quickstart/docker/image/run-with-ziti-cli.sh index 34cf0f0e1..6c10213a2 100755 --- a/quickstart/docker/image/run-with-ziti-cli.sh +++ b/quickstart/docker/image/run-with-ziti-cli.sh @@ -36,21 +36,16 @@ sleep 1 . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" -if [[ "${ZITI_CONTROLLER_RAWNAME-}" == "" ]]; then export export ZITI_CONTROLLER_RAWNAME="ziti-controller"; fi -if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" == "" ]]; then export export ZITI_EDGE_CONTROLLER_RAWNAME="ziti-edge-controller"; fi -if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then export export ZITI_EDGE_ROUTER_RAWNAME="${ZITI_NETWORK-}-edge-router"; fi +if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="ziti-edge-controller"; fi +if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then export ZITI_EDGE_ROUTER_NAME="${ZITI_NETWORK-}-edge-router"; fi if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi -if [[ "${ZITI_EDGE_ROUTER_HOSTNAME}" == "" ]]; then export ZITI_EDGE_ROUTER_HOSTNAME="${ZITI_EDGE_ROUTER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi -if [[ "${ZITI_EDGE_ROUTER_ROLES}" == "" ]]; then export ZITI_EDGE_ROUTER_ROLES="${ZITI_EDGE_ROUTER_RAWNAME}"; fi +if [[ "${ZITI_ROUTER_ADVERTISED_ADDRESS}" == "" ]]; then export ZITI_ROUTER_ADVERTISED_ADDRESS="${ZITI_EDGE_ROUTER_NAME}${ZITI_DOMAIN_SUFFIX}"; fi +if [[ "${ZITI_EDGE_ROUTER_ROLES}" == "" ]]; then export ZITI_EDGE_ROUTER_ROLES="${ZITI_EDGE_ROUTER_NAME}"; fi . "${ZITI_HOME}"/ziti.env # Wait for the controller -# shellcheck disable=SC2091 -until $(curl -s -o /dev/null --fail -k "https://${ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT}"); do - echo "waiting for https://${ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT}" - sleep 2 -done +_wait_for_controller echo " " echo "*****************************************************" diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh old mode 100755 new mode 100644 index 1520ba7bd..07cd5e992 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -2,291 +2,172 @@ set -uo pipefail -# the default ZITI_NETWORK (network name) is the short hostname -: "${DEFAULT_ZITI_NETWORK:="$(hostname -s)"}" - -# shellcheck disable=SC2155 -export DEFAULT_ZITI_HOME_LOCATION="${HOME}/.ziti/quickstart/${DEFAULT_ZITI_NETWORK}" - -export ZITI_QUICKSTART_ENVROOT="${HOME}/.ziti/quickstart" - +# Global Variables ASCI_WHITE='\033[01;37m' ASCI_RESTORE='\033[0m' ASCI_RED='\033[00;31m' ASCI_GREEN='\033[00;32m' ASCI_YELLOW='\033[00;33m' ASCI_BLUE='\033[00;34m' -#ASCI_MAGENTA='\033[00;35m' -#ASCI_PURPLE='\033[00;35m' -#ASCI_CYAN='\033[00;36m' -#ASCI_LIGHTGRAY='\033[00;37m' -#ASCI_LRED='\033[01;31m' -#ASCI_LGREEN='\033[01;32m' -#ASCI_LYELLOW='\033[01;33m' -#ASCI_LBLUE='\033[01;34m' -#ASCI_LMAGENTA='\033[01;35m' -#ASCI_LPURPLE='\033[01;35m' -#ASCI_LCYAN='\033[01;36m' +ASCI_PURPLE='\033[00;35m' +ZITIx_EXPRESS_COMPLETE="" function WHITE { echo "${ASCI_WHITE}${1-}${ASCI_RESTORE}" } -function RED { +function RED { # Generally used for ERROR echo "${ASCI_RED}${1-}${ASCI_RESTORE}" } -function GREEN { +function GREEN { # Generally used for SUCCESS messages echo "${ASCI_GREEN}${1-}${ASCI_RESTORE}" } -function YELLOW { +function YELLOW { # Generally used for WARNING messages echo "${ASCI_YELLOW}${1-}${ASCI_RESTORE}" } -function BLUE { +function BLUE { # Generally used for directory paths echo "${ASCI_BLUE}${1-}${ASCI_RESTORE}" } - -function zitiLogin { - "${ZITI_BIN_DIR-}/ziti" edge login "${ZITI_EDGE_CTRL_ADVERTISED}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -c "${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" -} -function cleanZitiController { - checkEnvVariable ZITI_HOME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - rm -rf "${ZITI_HOME}/db" - mkdir "${ZITI_HOME}/db" - initializeController -} -function initializeController { - log_file="${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}-init.log" - "${ZITI_BIN_DIR-}/ziti-controller" edge init "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" -u "${ZITI_USER-}" -p "${ZITI_PWD}" &> "${log_file}" - echo -e "ziti-controller initialized. see $(BLUE "${log_file}") for details" -} -function startController { - log_file="${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}.log" - # shellcheck disable=SC2034 - "${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" &> "${log_file}" & - ZITI_EXPRESS_CONTROLLER_PID=$! - echo -e "ziti-controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${log_file}")" +function PURPLE { # Generally used for Express Install milestones. + echo "${ASCI_PURPLE}${1-}${ASCI_RESTORE}" } -function stopController { - if [[ -n ${ZITI_EXPRESS_CONTROLLER_PID:-} ]]; then - kill "$ZITI_EXPRESS_CONTROLLER_PID" - # shellcheck disable=SC2181 - if [[ $? == 0 ]]; then - echo "Controller stopped." - return 0 - fi - else - echo "ERROR: you can only stop a controller process that was started with startController" >&2 - return 1 - fi -} - -function startRouter { - log_file="${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" - "${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${log_file}" 2>&1 & - ZITI_EXPRESS_EDGE_ROUTER_PID=$! - echo -e "Express Edge Router started as process id: $ZITI_EXPRESS_EDGE_ROUTER_PID. log located at: $(BLUE "${log_file}")" - -} - -function stopRouter { - if [[ -n ${ZITI_EXPRESS_EDGE_ROUTER_PID:-} ]]; then - # shellcheck disable=SC2015 - kill "${ZITI_EXPRESS_EDGE_ROUTER_PID}" && { - echo "INFO: stopped router" - } || { - echo "ERROR: something went wrong with stopping the router(s)" >&2 - return 1 - } - else - echo "ERROR: you can only stop a router process that was started with startRouter" >&2 - return 1 - fi -} - -function checkHostsFile { - ctrlexists=$(grep -c "${ZITI_CONTROLLER_HOSTNAME}" /etc/hosts) - edgectrlexists=$(grep -c "${ZITI_EDGE_CONTROLLER_HOSTNAME}" /etc/hosts) - erexists=$(grep -c "${ZITI_EDGE_ROUTER_HOSTNAME}" /etc/hosts) - - if [[ "0" = "${ctrlexists}" ]] || [[ "0" = "${edgectrlexists}" ]] || [[ "0" = "${erexists}" ]]; then - echo " " - echo -e "$(YELLOW "Ziti is generally used to create an overlay network. Generally speaking this will involve more than one host")" - echo -e "$(YELLOW "Since this is a script geared towards setting up a very minimal development environment it needs to make some")" - echo -e "$(YELLOW "assumptions. One of these assumptions is that the three specific entries are entered onto your hosts file.")" - echo -e "$(YELLOW "One or more of these are missing:")" - echo " " - if [[ "0" == "${ctrlexists}" ]]; then - echo -e " * $(RED "MISSING: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " - else - echo -e " * $(GREEN " FOUND: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " - fi - if [[ "0" == "${edgectrlexists}" ]]; then - echo -e " * $(RED "MISSING: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " - else - echo -e " * $(GREEN " FOUND: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " - fi - if [[ "0" == "${erexists}" ]]; then - echo -e " * $(RED "MISSING: ${ZITI_EDGE_ROUTER_HOSTNAME}") " - else - echo -e " * $(GREEN " FOUND: ${ZITI_EDGE_ROUTER_HOSTNAME}") " - fi - - echo " " - echo "The easiest way to correct this is to run the following command:" - echo " echo \"127.0.0.1 ${ZITI_CONTROLLER_HOSTNAME} ${ZITI_EDGE_CONTROLLER_HOSTNAME} ${ZITI_EDGE_ROUTER_HOSTNAME}\" | sudo tee -a /etc/hosts" - echo " " - echo "add these entries to your hosts file, and rerun the script when ready" - return 1 - else - echo -e "$(GREEN "Hosts file looks good")" - fi -} - -function verifyZitiVersionExists { - setupZitiHome - - if ! setOs; then - return 1 - fi - - detectArchitecture - - unset ZITI_BINARIES_VERSION - - ziticurl="$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/tags/"${ZITI_VERSION_OVERRIDE}")" - # shellcheck disable=SC2155 - export ZITI_BINARIES_FILE=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') - # shellcheck disable=SC2155 - export ZITI_BINARIES_VERSION=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.tag_name') - - # Check if there was an error while trying to get the requested version - if [[ "${ZITI_BINARIES_VERSION-}" == "null" ]]; then - echo "ERROR: response missing '.tag_name': ${ziticurl}" >&2 - return 1 - fi - - echo "ZITI_BINARIES_VERSION: ${ZITI_BINARIES_VERSION}" -} - -function detectArchitecture { - if [ -n "${ZITI_ARCH}" ]; then return; fi - ZITI_ARCH="amd64" - detected_arch="$(uname -m)" - # Apple M1 silicon - if [[ "${detected_arch}" == *"arm"* ]] && [[ "${ZITI_OSTYPE}" == "darwin" ]]; then - echo -e "$(YELLOW "WARN: It has been detected that you are using an Apple computer with ARM architecture. Deployment of Apple ARM architecture distributions is currently unsupported through git, the installer will pull darwin amd distribution instead.")" - # LLVM 64 bit backends have merged so some versions of *nix use aarch64 while others use arm64 for parity with Apple - elif [[ "${detected_arch}" == *"aarch64"* ]] || [[ "${detected_arch}" == *"arm64"* ]]; then - ZITI_ARCH="arm64" - elif [[ "${detected_arch}" == *"arm"* ]]; then - ZITI_ARCH="arm" - fi -} - -function getLatestZitiVersion { - setupZitiHome - - if ! setOs; then - return 1 - fi - - detectArchitecture - - unset ZITI_BINARIES_VERSION - - if [[ "${ZITI_BINARIES_VERSION-}" == "" ]]; then - zitilatest=$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/latest) - # shellcheck disable=SC2155 - export ZITI_BINARIES_FILE=$(echo "${zitilatest}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') - # shellcheck disable=SC2155 - export ZITI_BINARIES_VERSION=$(echo "${zitilatest}" | tr '\r\n' ' ' | jq -r '.tag_name') - fi - echo "ZITI_BINARIES_VERSION: ${ZITI_BINARIES_VERSION}" -} - -function getZiti { - setupZitiHome - checkEnvVariable ZITI_HOME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - ziti_bin_root="${ZITI_BIN_ROOT-}" - if [[ "${ziti_bin_root}" == "" ]]; then - ziti_bin_root="${ZITI_HOME-}/ziti-bin" - fi - export ZITI_BIN_ROOT="${ziti_bin_root}/ziti-bin" - - mkdir -p "${ziti_bin_root}" - - # Get the latest version unless a specific version is specified - if [[ "${ZITI_VERSION_OVERRIDE-}" == "" ]]; then - if ! getLatestZitiVersion; then - return 1 - fi - else - # Check if an error occurred while trying to pull desired version (happens with incorrect version or formatting issue) - if ! verifyZitiVersionExists; then - echo -e " * $(RED "ERROR: This version of ziti (${ZITI_VERSION_OVERRIDE}) could not be found. Please check the version and try again. The version should follow the format \"vx.x.x\".") " - return 1 - fi - fi - - if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ziti_bin_root}/ziti-${ZITI_BINARIES_VERSION}"; else echo "Using ZITI_BIN_DIR: ${ZITI_BIN_DIR}"; fi - - ZITI_BINARIES_FILE_ABSPATH="${ziti_bin_root}/${ZITI_BINARIES_FILE}" - if ! test -f "${ZITI_BINARIES_FILE_ABSPATH}"; then - zitidl="https://github.com/openziti/ziti/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}" - echo -e 'Downloading '"$(BLUE "${zitidl}")"' to '"$(BLUE "${ZITI_BINARIES_FILE_ABSPATH}")" - curl -Ls "${zitidl}" -o "${ZITI_BINARIES_FILE_ABSPATH}" - else - echo -e "$(YELLOW 'Already Downloaded ')""$(BLUE "${ZITI_BINARIES_FILE}")"' at: '"${ZITI_BINARIES_FILE_ABSPATH}" - fi - - echo -e 'UNZIPPING '"$(BLUE "${ZITI_BINARIES_FILE_ABSPATH}")"' into: '"$(GREEN "${ZITI_BIN_DIR}")" - rm -rf "${ziti_bin_root}/ziti-${ZITI_BINARIES_VERSION-}" - if [[ "${ZITI_OSTYPE}" == "windows" ]]; then - unzip "${ZITI_BINARIES_FILE_ABSPATH}" -d "${ZITI_BIN_DIR}" - mv "${ZITI_BIN_DIR}/ziti/"* "${ZITI_BIN_DIR}/" - rm -rf "${ZITI_BIN_DIR}/ziti/"* - rmdir "${ZITI_BIN_DIR}/ziti/" - chmod +x "${ZITI_BIN_DIR}/"* - else - tar -xf "${ZITI_BINARIES_FILE_ABSPATH}" --directory "${ziti_bin_root}" - mv "${ziti_bin_root}/ziti" "${ZITI_BIN_DIR}" - fi - - echo -e 'Marking executables at '"$(GREEN "${ZITI_BIN_DIR}")"' executable' - chmod +x "${ZITI_BIN_DIR}/"* - - if [[ "${1-}" == "yes" ]]; then - echo "Adding ${ZITI_BIN_DIR} to the path if necessary:" - if [[ "$(echo "$PATH"|grep -q "${ZITI_BIN_DIR}" && echo "yes")" == "yes" ]]; then - echo -e "$(GREEN "${ZITI_BIN_DIR}") is already on the path" - else - echo -e "adding $(RED "${ZITI_BIN_DIR}") to the path" - export PATH=$PATH:"${ZITI_BIN_DIR}" - fi - fi -} - -function checkPrereqs { - commands_to_test=(curl jq) - missing_requirements="" - # verify all the commands required in the automation exist before trying to run the full suite - for cmd in "${commands_to_test[@]}" - do - # checking all commands are on the path before continuing... - if ! [[ -x "$(command -v "${cmd}")" ]]; then - missing_requirements="${missing_requirements} * ${cmd}" - fi +function _wait_for_controller { + local advertised_host_port="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:${ZITI_CTRL_EDGE_ADVERTISED_PORT}" + while [[ "$(curl -w "%{http_code}" -m 1 -s -k -o /dev/null https://"${advertised_host_port}"/version)" != "200" ]]; do + echo "waiting for https://${advertised_host_port}" + sleep 3 done - # are requirements ? if yes, stop here and help 'em out +} + +function _setup_ziti_home { + _setup_ziti_network + if [[ "${ZITI_HOME-}" == "" ]]; then export ZITI_HOME="${HOME}/.ziti/quickstart/${ZITI_NETWORK-}"; else echo "ZITI_HOME overridden: ${ZITI_HOME}"; fi +} + +function _setup_ziti_network { + if [[ "${ZITI_NETWORK-}" == "" ]]; then ZITI_NETWORK="$(hostname -s)"; export ZITI_NETWORK; else echo "ZITI_NETWORK overridden: ${ZITI_NETWORK}"; fi +} + +function _get_file_overwrite_permission() { + local file_path="${1-}" + + if [[ -f "${file_path}" ]]; then + echo -en "This will overwrite the existing file, continue (y/N)? " + read -r + if [[ "${REPLY}" == [^Yy]* ]]; then + echo -e "$(RED " --- Cancelling overwrite ---")" + return 1 + fi + + return 0 + fi +} + +# removes duplicate strings in a list +function _dedupe_list { + local list delimiter retVal + list=${1-} + if [[ "${list}" == "" ]]; then + return 1 + fi + delimiter=${2-} + if [[ "${delimiter}" == "" ]]; then + delimiter="," + fi + + echo "${list}" | tr "'${delimiter}'" '\n' | sort -u | xargs | tr ' ' ',' +} + +function _pki_client_server { + local retVal dns_allow_list ZITI_CA_NAME_local ip_allow_list file_name + _check_env_variable ZITI_PKI ZITI_BIN_DIR + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + dns_allow_list=${1-} + ZITI_CA_NAME_local=$2 + ip_allow_list=$3 + file_name=$4 + + if [[ "${ip_allow_list}" == "" ]]; then + ip_allow_list="127.0.0.1" + fi + + # Dedupe the lists + dns_allow_list=$(_dedupe_list "${dns_allow_list}") + ip_allow_list=$(_dedupe_list "${ip_allow_list}") + + if ! test -f "${ZITI_PKI}/${ZITI_CA_NAME_local}/keys/${file_name}-server.key"; then + echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list} / ${ip_allow_list}" + "${ZITI_BIN_DIR-}/ziti" pki create server --pki-root="${ZITI_PKI}" --ca-name "${ZITI_CA_NAME_local}" \ + --server-file "${file_name}-server" \ + --dns "${dns_allow_list}" --ip "${ip_allow_list}" \ + --server-name "${file_name} server certificate" + else + echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list}" + echo "key exists" + fi + + if ! test -f "${ZITI_PKI}/${ZITI_CA_NAME_local}/keys/${file_name}-client.key"; then + echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list}" + "${ZITI_BIN_DIR-}/ziti" pki create client --pki-root="${ZITI_PKI}" --ca-name "${ZITI_CA_NAME_local}" \ + --client-file "${file_name}-client" \ + --key-file "${file_name}-server" \ + --client-name "${file_name}" + else + echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list}" + echo "key exists" + fi + echo " " +} + +function _pki_create_ca { + local cert retVal + _check_env_variable ZITI_PKI ZITI_BIN_DIR + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + cert="${1}" + + echo "Creating CA: ${cert}" + if ! test -f "${ZITI_PKI}/${cert}/keys/${cert}.key"; then + "${ZITI_BIN_DIR}/ziti" pki create ca --pki-root="${ZITI_PKI}" --ca-file="${cert}" --ca-name="${cert} Root CA" + else + echo "key exists" + fi + echo " " +} + +function _pki_create_intermediate { + local retVal + _check_env_variable ZITI_PKI ZITI_BIN_DIR + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + echo "Creating intermediate: ${1} ${2} ${3}" + if ! test -f "${ZITI_PKI}/${2}/keys/${2}.key"; then + "${ZITI_BIN_DIR}/ziti" pki create intermediate --pki-root "${ZITI_PKI}" --ca-name "${1}" \ + --intermediate-name "${2}" \ + --intermediate-file "${2}" --max-path-len "${3}" + else + echo "key exists" + fi + echo " " +} + +# Checks that a specific command or set of commands exist on the path +function _check_prereq { + local missing_requirements="" arg + for arg + do + if ! [[ -x "$(command -v "${arg}")" ]]; then + missing_requirements="${missing_requirements}\n* ${arg}" + fi + done + # Are requirements missing if yes, stop here and help 'em out if ! [[ "" = "${missing_requirements}" ]]; then echo " " echo "You're missing one or more commands that are used in this script." @@ -295,788 +176,100 @@ function checkPrereqs { echo " " echo " " return 1 - else - echo -e "$(GREEN "Prerequisites confirmed")" fi } -function _portCheck { - if [[ "${1-}" == "" ]] || [[ "${2-}" == "" ]]; then - echo -e "_portCheck Usage: _portCheck " - return 0 - fi - - envVar="${1-}" - if [[ -n "$ZSH_VERSION" ]]; then - envVarValue="${(P)envVar}" - elif [[ -n "$BASH_VERSION" ]]; then - envVarValue="${!envVar}" - else - echo -e "$(YELLOW "Unknown/Unsupported shell, cannot verify availability of ${2-}'s intended port, proceed with caution")" - return 0 - fi - - echo -e "Checking if ${2-}'s port (${envVarValue}) is available" - portCheckResult=$(lsof -w -i :"${envVarValue}" 2> /dev/null) - if [[ "${portCheckResult}" != "" ]]; then # Controller management plane - echo -e "$(RED " ")" - echo -e "$(RED "The intended ${2-} port (${envVarValue}) is currently being used, the process using this port should be closed or the port value should be changed.")" - echo -e "$(RED "To use a different port, set the port value in ${envVar}")" - echo -e "$(RED " ")" - echo -e "$(RED "Example:")" - echo -e "$(RED "export ${envVar}=1234")" - echo -e "$(RED " ")" +# Disable shellcheck for parameter expansion error, this function supports multiple shells +# shellcheck disable=SC2296 +# Check if an environment variable is set, if not, throw an error +function _check_env_variable() { + local _error=false arg + for arg + do + # Parameter expansion is different between shells + if [[ -n "$ZSH_VERSION" ]]; then + if [[ -z "${(P)arg}" ]]; then + echo -e " * ERROR: $(RED "${arg} is not set") " + _error=true + fi + elif [[ -n "$BASH_VERSION" ]]; then + if [[ -z "${!arg}" ]]; then + echo -e " * ERROR: $(RED "${arg} is not set") " + _error=true + fi + else + echo -e " * $(RED "Unsupported shell, supply a PR or log an issue on https://github.com/openziti/ziti") " return 1 - fi - return 0 -} + fi + done -function checkControllerName { - if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME}" == *['!'@#\$%^\&*\(\)_+]* ]]; then - echo -e "$(RED " - The provided Network name contains an invalid character: '!'@#\$%^\&*()_+")" + if [[ "true" == "${_error}" ]]; then return 1 - fi - return 0 -} - -function unsetZitiEnv { - if [[ "${1-}" == "-s" ]]; then - # Silent... - for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; unset "${envvar}"; done else - for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; echo unsetting "[${envvar}]${zEnvVar}"; unset "${envvar}"; done + return 0 fi - unset ZITIx_EXPRESS_COMPLETE } -function issueGreeting { - #echo "-------------------------------------------------------------" - echo " " - echo " _ _ _" - echo " ____ (_) | |_ (_)" - echo " |_ / | | | __| | |" - echo " / / | | | |_ | |" - echo " /___| |_| \__| |_|" - echo "-------------------------------------------------------------" - echo " " - echo "This script will make it trivial to setup a very simple environment locally which will allow you to start" +function _issue_preamble { + echo -e "$(PURPLE "-------------------------------------------------------------")" + echo -e "$(PURPLE " _ _ _")" + echo -e "$(PURPLE " ____ (_) | |_ (_)")" + echo -e "$(PURPLE " |_ / | | | __| | |")" + echo -e "$(PURPLE " / / | | | |_ | |")" + echo -e "$(PURPLE " /___| |_| \__| |_|")" + echo "" + echo -e "$(PURPLE "-------------------------------------------------------------")" + echo "" + echo "This script will make it trivial to set up a very simple environment locally which will allow you to start" echo "learning ziti. This environment is suitable for development work only and is not a decent representation of" echo "a fully redundant production-caliber network." echo "" - echo "Please note that this script will write files to your home directory into a directory named .ziti." - echo -n "For you this location will be: " - echo -e "$(BLUE "${ZITI_QUICKSTART_ENVROOT}")" - echo " " } -function setupZitiNetwork { - if [[ "${1-}" == "" ]]; then - echo " " - echo "Creating a controller is effectively creating a network. The name of the network will be used when writing" - echo "configuration files locally. Choose the name of your network now. The format of the network name should resemble" - echo -n "what a hostname looks like. A good choice is to actually use your system's hostname: " - echo -e "$(BLUE "${DEFAULT_ZITI_NETWORK}")" - echo " " - echo -en "$(echo -ne "Network Name [$(BLUE "${DEFAULT_ZITI_NETWORK}")]: ")" - read -r ZITI_NETWORK - echo " " - if checkControllerName; then - : #clear to continue - if [[ "${ZITI_NETWORK-}" == "" ]]; then - ZITI_NETWORK="${DEFAULT_ZITI_NETWORK}" - fi - echo "name: ${ZITI_NETWORK-}" - else - echo "" - echo "============ FAILED TO SETUP NETWORK ============" - return 1 - fi - echo " " - else - ZITI_NETWORK="${1-}" - fi -} - -function setupZitiHome { - if [[ "${ZITI_HOME-}" == "" ]]; then - export ZITI_HOME="${HOME}/.ziti/quickstart/${ZITI_NETWORK-}" - echo -e "using default ZITI_HOME: $(BLUE "${ZITI_HOME}")" - fi -} - -function generateEnvFile { - - echo -e "Generating new network with name: $(BLUE "${ZITI_NETWORK-}")" - - if [[ "${ZITI_CONTROLLER_RAWNAME-}" == "" ]]; then export ZITI_CONTROLLER_RAWNAME="${ZITI_NETWORK-}"; fi - if [[ "${ZITI_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_CONTROLLER_HOSTNAME="${ZITI_CONTROLLER_RAWNAME}"; fi - if [[ "${ZITI_CTRL_PORT-}" == "" ]]; then export ZITI_CTRL_PORT="6262"; fi - if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi - - if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_NETWORK-}"; fi - if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_HOSTNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}"; fi - - if [[ "${ZITI_ZAC_RAWNAME-}" == "" ]]; then export ZITI_ZAC_RAWNAME="${ZITI_NETWORK-}"; fi - if [[ "${ZITI_ZAC_HOSTNAME-}" == "" ]]; then export ZITI_ZAC_HOSTNAME="${ZITI_ZAC_RAWNAME}"; fi - - if [[ "${ZITI_BIN_ROOT-}" == "" ]]; then - export ZITI_BIN_ROOT="${ZITI_HOME-}/ziti-bin" - fi - - export ENV_FILE="${ZITI_HOME-}/${ZITI_NETWORK-}.env" - - if ! ziti_createEnvFile; then - return 1 - fi - - echo -e "environment file sourced from: $(BLUE "${ENV_FILE}")" -} - -function ziti_expressConfiguration { - if [[ "${ZITIx_EXPRESS_COMPLETE-}" != "" ]]; then - echo -e "$(RED " --- It looks like you've run an express install in this shell already. ---")" - echo -en "Would you like to clear existing Ziti variables and continue (y/N)? " - read -r - echo " " - if [[ "${REPLY}" == [Yy]* ]]; then - echo -e "$(GREEN "Clearing existing Ziti variables and continuing with express install")" - - # Check if the user chose a specific version - specifiedVersion="" - if [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]] && [[ "${ZITI_VERSION_OVERRIDE-}" != "${ZITI_BINARIES_VERSION-}" ]]; then - # Don't allow overriding the version if ziti quickstart was already run, the DB may not be compatible - echo -e "$(RED " --- Overriding the ziti version is not supported if the version differs from one already installed. ---")" - echo -en "Would you like to continue by using the latest version. (y/N)?" - read -r - echo " " - if [[ "${REPLY}" == [Yy]* ]]; then - unset ZITI_VERSION_OVERRIDE - else - return 1 - fi - elif [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]]; then - echo -e "$(RED " --- You have set the ZITI_VERSION_OVERRIDE value to ${ZITI_VERSION_OVERRIDE}. ---")" - echo -en "Would you like to use this version again, choosing no will pull the latest version. (y/N)?" - read -r - echo " " - if [[ "${REPLY}" == [Yy]* ]]; then - specifiedVersion="${ZITI_VERSION_OVERRIDE}" - fi - fi - - # Silently clear ziti variables - unsetZitiEnv "-s" - - if [[ "${specifiedVersion}" != "" ]]; then - export ZITI_VERSION_OVERRIDE="${specifiedVersion}" - fi - - # Stop any devices currently running to avoid port collisions - stopRouter - stopController - else - echo -e "$(RED " --- Exiting express install ---")" - return 1 - fi - fi - export ZITIx_EXPRESS_COMPLETE="true" - echo " " - echo "___________ _______________________________________^__" - echo " ___ ___ ||| ___ ___ ___ ___ ___ | __ ,----\ " - echo "| | | |||| | | | | | | | | | | | | |_____\ " - echo "|___| |___|||| |___| |___| |___| | O | O | | | | \ " - echo " ||| ===== EXPRESS ==== |___|___| | |__| )" - echo "___________|||______________________________|______________/" - echo " ||| /--------" - echo "-----------'''---------------------------------------'" +function _issue_greeting { + echo "Please note that, by default, this script will write files to your home directory into a directory named .ziti." + echo -n "The currently configured location for these files will be: " + echo -e "$(BLUE "${ZITI_HOME}")" echo "" - if [[ "${ZITI_CONTROLLER_RAWNAME-}" != "" ]]; then echo "ZITI_CONTROLLER_RAWNAME OVERRIDDEN: $ZITI_CONTROLLER_RAWNAME"; fi - if [[ "${ZITI_CONTROLLER_HOSTNAME-}" != "" ]]; then echo "ZITI_CONTROLLER_HOSTNAME OVERRIDDEN: $ZITI_CONTROLLER_HOSTNAME"; fi - if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" != "" ]]; then echo "ZITI_EDGE_CONTROLLER_RAWNAME OVERRIDDEN: $ZITI_EDGE_CONTROLLER_RAWNAME"; fi - if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" != "" ]]; then echo "ZITI_EDGE_CONTROLLER_HOSTNAME OVERRIDDEN: $ZITI_EDGE_CONTROLLER_HOSTNAME"; fi - if [[ "${ZITI_ZAC_RAWNAME-}" != "" ]]; then echo "ZITI_ZAC_RAWNAME OVERRIDDEN: $ZITI_ZAC_RAWNAME"; fi - if [[ "${ZITI_ZAC_HOSTNAME-}" != "" ]]; then echo "ZITI_ZAC_HOSTNAME OVERRIDDEN: $ZITI_ZAC_HOSTNAME"; fi - if [[ "${ZITI_EDGE_ROUTER_HOSTNAME-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_HOSTNAME OVERRIDDEN: $ZITI_EDGE_ROUTER_HOSTNAME"; fi - if [[ "${ZITI_EDGE_ROUTER_PORT-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_PORT OVERRIDDEN: $ZITI_EDGE_ROUTER_PORT"; fi - if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_RAWNAME OVERRIDDEN: $ZITI_EDGE_ROUTER_RAWNAME"; fi - - echo " " - echo " " - echo -e "******** Setting Up Environment ********" - if [[ "${1-}" == "" ]]; then - nw="${DEFAULT_ZITI_NETWORK}" - else - nw="${1-}" - fi - - setupZitiNetwork "${nw}" - setupZitiHome - echo -e "ZITI HOME SET TO: $(BLUE "${ZITI_HOME}")" - - if ! getZiti "no"; then - echo -e "$(RED "getZiti failed")" - return 1 - fi - if ! generateEnvFile; then - echo "Exiting as env file was not generated" - return 1 - fi - - # Check Ports - returnCnt=0 - _portCheck "ZITI_CTRL_PORT" "Controller" - returnCnt=$((returnCnt + $?)) - _portCheck "ZITI_EDGE_ROUTER_PORT" "Edge Router" - returnCnt=$((returnCnt + $?)) - _portCheck "ZITI_EDGE_CONTROLLER_PORT" "Edge Controller" - returnCnt=$((returnCnt + $?)) - _portCheck "ZITI_CTRL_MGMT_PORT" "Controller Management Plane" - returnCnt=$((returnCnt + $?)) - if [[ "${ZITI_EDGE_ROUTER_LISTENER_BIND_PORT-}" != "" ]]; then - # This port can be explicitly set but is not always, only check if set - _portCheck "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" "Router Listener Bind Port" - returnCnt=$((returnCnt + $?)) - fi - if [[ "returnCnt" -gt "0" ]]; then return 1; fi - - #checkHostsFile - - echo " " - echo " " - echo -e "******** Setting Up Public Key Infrastructure ********" - createPki - - echo " " - echo " " - echo -e "******** Setting Up Controller ********" - createControllerConfig - #createControllerSystemdFile - initializeController - startController - echo "waiting for the controller to come online to allow the edge router to enroll" - - waitForController - - zitiLogin - - echo " " - echo " " - echo -e "******** Setting Up Edge Routers ********" - echo -e "---------- Creating an edge router policy allowing all identities to connect to routers with a $(GREEN "#public") attribute" - "${ZITI_BIN_DIR-}/ziti" edge delete edge-router-policy allEdgeRouters > /dev/null - "${ZITI_BIN_DIR-}/ziti" edge create edge-router-policy allEdgeRouters --edge-router-roles '#public' --identity-roles '#all' > /dev/null - - echo -e "---------- Creating a service edge router policy allowing all services to use $(GREEN "#public") edge routers" - "${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcAllRouters > /dev/null - "${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcAllRouters --edge-router-roles '#all' --service-roles '#all' > /dev/null - - echo "USING ZITI_EDGE_ROUTER_RAWNAME: $ZITI_EDGE_ROUTER_RAWNAME" - - createRouterPki "${ZITI_EDGE_ROUTER_RAWNAME}" - - createEdgeRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" - #createRouterSystemdFile "${ZITI_EDGE_ROUTER_RAWNAME}" - - echo "---------- Creating edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." - "${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${ZITI_EDGE_ROUTER_RAWNAME}" > /dev/null - "${ZITI_BIN_DIR-}/ziti" edge create edge-router "${ZITI_EDGE_ROUTER_RAWNAME}" -o "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" -t -a "public"> /dev/null - sleep 1 - echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." - - "${ZITI_BIN_DIR-}/ziti-router" enroll "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" --jwt "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" &> "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.enrollment.log" echo "" - - stopController - echo "Edge Router enrolled. Controller stopped." - + echo " \----------------------------------\ " + echo " \ \ __ " + echo " \ Welcome To: \ | \ " + echo " > Ziti Express 2.0 >------| \ ______ " + echo " / / --- \_____/**|_|_\____ | " + echo " / / \_______ --------- __>-} " + echo " /----------------------------------/ / \_____|_____/ | " + echo " * | " + echo " {O} " echo "" - echo -e "$(GREEN "Congratulations. Express setup complete!")" - echo -e "Start your Ziti Controller by running the function: $(BLUE "startController")" - echo -e "Start your Ziti Edge Router by running : $(BLUE 'startRouter')" - echo "" -} - -function decideToUseDefaultZitiHome { - yn="" - while true - do - echo "ZITI_HOME has not been set. Do you want to use the default ZITI_HOME: ${DEFAULT_ZITI_HOME_LOCATION}" - echo " " - echo -en "Select an action: " - read -r yn - case $yn in - [yY]* ) - ZITI_HOME="${DEFAULT_ZITI_HOME_LOCATION}" - break;; - [Nn]* ) - echo "" - return 1;; - * ) - echo " " - echo "Answer $yn is not valid. Please answer yes or no. (y/n [yes/NO])";; - esac - yn= - done - echo " " -} - -function decideOperation { - yn="${1-}" - while true - do - if [[ "${yn}" == "" ]]; then - echo "What sort of operation are you looking to perform?" - echo " 1.) Express configuration - a simple overlay will be spawned containing one controller and two edge routers" - echo " 2.) Create Controller configuration - answer a few questions and a controller config will be emitted" - echo " 3.) Create Edge Router configuration - answer a few questions and an edge router config will be emitted" - echo " 4.) Start a network with the provided name" - echo " " - echo -en "Select an action: " - read -r yn - fi - case $yn in - [1]* ) - ziti_expressConfiguration "$2" - break;; - [2]* ) - generateEnvFile - - ;; - [3]* ) - echo "333 has been chosen" - echo " " - ;; - [4]* ) - echo "4444 has been chosen" - echo " " - ;; - [yYqQeE]* ) - break - ;; - [Nn]* ) - echo ""; echo "Ok - come back when you're ready." - exit;; - * ) echo "Please answer yes or no. (yes/NO)";; - esac - yn= - done - echo " " -} - -function expressInstall { - #greet the user with the banner and quick blurb about what to expect - issueGreeting - - #make sure the user has all the necessary commands to be successful - checkPrereqs - retval=$? - if [ $retval -ne 0 ]; then - return 1 - fi echo "Let's get started creating your local development network!" echo "" - echo "" - - #prompt the user for input and do what they want/need - decideOperation 1 "${1-}" } -function pki_client_server { - allow_list=${1-} - ZITI_CA_NAME_local=$2 - ip_local=$3 - file_name=$4 - - if [[ "${ip_local}" == "" ]]; then - ip_local="127.0.0.1" - fi - - if ! test -f "${ZITI_PKI}/${ZITI_CA_NAME_local}/keys/${file_name}-server.key"; then - echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${allow_list} / ${ip_local}" - "${ZITI_BIN_DIR-}/ziti" pki create server --pki-root="${ZITI_PKI_OS_SPECIFIC}" --ca-name "${ZITI_CA_NAME_local}" \ - --server-file "${file_name}-server" \ - --dns "${allow_list}" --ip "${ip_local}" \ - --server-name "${file_name} server certificate" - else - echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${allow_list}" - echo "key exists" - fi - - if ! test -f "${ZITI_PKI}/${ZITI_CA_NAME_local}/keys/${file_name}-client.key"; then - echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${allow_list}" - "${ZITI_BIN_DIR-}/ziti" pki create client --pki-root="${ZITI_PKI_OS_SPECIFIC}" --ca-name "${ZITI_CA_NAME_local}" \ - --client-file "${file_name}-client" \ - --key-file "${file_name}-server" \ - --client-name "${file_name}" - else - echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${allow_list}" - echo "key exists" - fi - echo " " +# Clear all environment variables prefixed with ZITI_ (use -s parameter to do so without any output) +function unsetZitiEnv { + local param1 zEnvVar envvar + param1="${1-}" + for zEnvVar in $(set | grep -e "^ZITI_" | sort); do + envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)" + if [[ "-s" != "${param1-}" ]]; then echo "unsetting [${envvar}] ${zEnvVar}"; fi + unset "${envvar}" + done + # Have to explicitly unset this one (no ZITI_ prefix) + unset ZITIx_EXPRESS_COMPLETE } -function pki_create_ca { - cert=$1 +# Checks for explicit environment variables or set as defaults, also creating directories as needed +function setupEnvironment { + local pwd_reply + echo "Populating environment variables" + # General Ziti Values + _setup_ziti_network + _setup_ziti_home - echo "Creating CA: ${cert}" - if ! test -f "${ZITI_PKI}/${cert}/keys/${cert}.key"; then - "${ZITI_BIN_DIR}/ziti" pki create ca --pki-root="${ZITI_PKI_OS_SPECIFIC}" --ca-file="${cert}" --ca-name="${cert} Root CA" - else - echo "key exists" - fi - echo " " -} - -function pki_create_intermediate { - echo "Creating intermediate: ${1} ${2} ${3}" - if ! test -f "${ZITI_PKI}/${2}/keys/${2}.key"; then - "${ZITI_BIN_DIR}/ziti" pki create intermediate --pki-root "${ZITI_PKI_OS_SPECIFIC}" --ca-name "${1}" \ - --intermediate-name "${2}" \ - --intermediate-file "${2}" --max-path-len "${3}" - else - echo "key exists" - fi - echo " " -} -function printUsage() { - echo "Usage: ${1-} [cert to test] [ca pool to use]" -} - -function verifyCertAgainstPool() { - if [[ "" == "${1-}" ]] - then - printUsage "verifyCertAgainstPool" - return 1 - fi - - if [[ "" == "$2" ]] - then - printUsage "verifyCertAgainstPool" - return 1 - fi - - echo " Verifying that this certificate:" - echo " - ${1-}" - echo " is valid for this ca pool:" - echo " - $2" - echo "" - openssl verify -partial_chain -CAfile "$2" "${1-}" - # shellcheck disable=SC2181 - if [ $? -eq 0 ]; then - echo "" - echo "============ SUCCESS! ============" - else - echo "" - echo "============ FAILED TO VALIDATE ============" - fi -} - -function showIssuerAndSubjectForPEM() { - echo "Displaying Issuer and Subject for cert pool:" - echo " ${1-}" - openssl crl2pkcs7 -nocrl -certfile "${1-}" | openssl pkcs7 -print_certs -text -noout | grep -E "(Subject|Issuer)" -} - -function createRouterPki { - # Allow router name to be passed in as arg - router_name="${1-}" - if [[ "${router_name}" == "" ]]; then - echo -e " * ERROR: $(RED "routerName needs to be supplied") " - return 1 - fi - mkdir -p "${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}" - export ZITI_ROUTER_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/client.cert" - export ZITI_ROUTER_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.cert" - export ZITI_ROUTER_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.key" - export ZITI_ROUTER_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/cas.cert" - pki_client_server "${router_name},localhost,127.0.0.1,${ZITI_NETWORK}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}" "${router_name}" -} - -function createPrivateRouterConfig { - # Allow router name to be passed in as arg - router_name="${1-}" - if [[ "${router_name}" == "" ]]; then - - # If router name is not passed as arg, prompt user for input - echo -e "$(YELLOW "createPrivateRouterConfig requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" - echo -en "Enter router name (${default_router_name}):" - read -r router_name - - # Accept the default if no name provided - if [[ "${router_name}" == "" ]]; then - # Check for overwrite of default file - router_name="${default_router_name}" - if [[ -f "${ZITI_HOME-}/${router_name}.yaml" ]]; then - echo -en "This will overwrite the existing file, continue (y/N)? " - read -r - echo " ${REPLY}" - if [[ "${REPLY}" == [^Yy]* ]]; then - echo -e "$(RED " --- Cancelling overwrite ---")" - return 1 - fi - fi - fi - fi - - # Make sure necessary env variables are set - checkEnvVariable ZITI_HOME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - output_file="${ZITI_HOME-}/${router_name}.yaml" - - getFileOverwritePermission "${output_file}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}" - echo -e "Router configuration file written to: $(BLUE "${output_file}")" -} - -function createPki { - echo "Generating PKI" - - pki_create_ca "${ZITI_CONTROLLER_ROOTCA_NAME}" - pki_create_ca "${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}" - pki_create_ca "${ZITI_SIGNING_ROOTCA_NAME}" - - ZITI_SPURIOUS_INTERMEDIATE="${ZITI_SIGNING_INTERMEDIATE_NAME}_spurious_intermediate" - pki_create_intermediate "${ZITI_CONTROLLER_ROOTCA_NAME}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" 1 - pki_create_intermediate "${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}" "${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}" 1 - pki_create_intermediate "${ZITI_SIGNING_ROOTCA_NAME}" "${ZITI_SPURIOUS_INTERMEDIATE}" 2 - pki_create_intermediate "${ZITI_SPURIOUS_INTERMEDIATE}" "${ZITI_SIGNING_INTERMEDIATE_NAME}" 1 - - echo " " - pki_allow_list_dns="${ZITI_CONTROLLER_HOSTNAME},localhost,${ZITI_NETWORK}" - if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME}" != "" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${ZITI_EDGE_CONTROLLER_HOSTNAME}"; fi - if [[ "${EXTERNAL_DNS}" != "" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${EXTERNAL_DNS}"; fi - pki_allow_list_ip="127.0.0.1" - if [[ "${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}"; fi - if [[ "${EXTERNAL_IP}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${EXTERNAL_IP}"; fi - - pki_client_server "${pki_allow_list_dns}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${pki_allow_list_ip}" "${ZITI_CONTROLLER_HOSTNAME}" - pki_client_server "${pki_allow_list_dns}" "${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}" "${pki_allow_list_ip}" "${ZITI_EDGE_CONTROLLER_HOSTNAME}" -} - - - -function createFabricRouterConfig { - # Allow router name to be passed in as arg - router_name="${1-}" - if [[ "${router_name}" == "" ]]; then - - # If router name is not passed as arg, prompt user for input - echo -e "$(YELLOW "createFabricRouterConfig requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" - echo -en "Enter router name (${default_router_name}):" - read -r router_name - - # Accept the default if no name provided - if [[ "${router_name}" == "" ]]; then - # Check for overwrite of default file - router_name="${default_router_name}" - fi - fi - - checkEnvVariable ZITI_HOME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - output_file="${ZITI_HOME}/${router_name}.yaml" - - getFileOverwritePermission "${output_file}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - "${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}" - echo -e "Fabric router configuration file written to: $(BLUE "${output_file}")" -} - -function createEdgeRouterWssConfig { - # Allow router name to be passed in as arg - router_name="${1-}" - if [[ "${router_name}" == "" ]]; then - - # If router name is not passed as arg, prompt user for input - echo -e "$(YELLOW "createEdgeRouterWssConfig requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" - echo -en "Enter router name (${default_router_name}):" - read -r router_name - - # Accept the default if no name provided - if [[ "${router_name}" == "" ]]; then - # Check for overwrite of default file - router_name="${default_router_name}" - getFileOverwritePermission "${ZITI_HOME-}/${router_name}.yaml" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - fi - fi - - # Make sure necessary env variables are set - checkEnvVariable ZITI_HOME ZITI_BIN_DIR - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - output_file="${ZITI_HOME-}/${router_name}.yaml" - - getFileOverwritePermission "${output_file}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - "${ZITI_BIN_DIR}/ziti" create config router edge --wss --routerName "${router_name}" > "${output_file}" - echo -e "WSS Edge router wss configuration file written to: $(BLUE "${output_file}")" -} - -# shellcheck disable=SC2120 -function createEdgeRouterConfig { - # Allow router name to be passed in as arg - router_name="${1-}" - if [[ "${router_name}" == "" ]]; then - - # If router name is not passed as arg, prompt user for input - echo -e "$(YELLOW "createEdgeRouterConfig requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" - echo -en "Enter router name (${default_router_name}):" - read -r router_name - - # Accept the default if no name provided - if [[ "${router_name}" == "" ]]; then - # Check for overwrite of default file - router_name="${default_router_name}" - getFileOverwritePermission "${ZITI_HOME-}/${router_name}.yaml" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - fi - fi - - # Make sure necessary env variables are set - checkEnvVariable ZITI_HOME ZITI_BIN_DIR - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - output_file="${ZITI_HOME}/${router_name}.yaml" - - getFileOverwritePermission "${output_file}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" > "${output_file}" - echo -e "edge router configuration file written to: $(BLUE "${output_file}")" -} - -# shellcheck disable=SC2120 -function createControllerConfig { - # Allow controller name to be passed in as arg - controller_name="${1-}" - # If no controller name provided and env var is not set, prompt user for a controller name - if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then - echo -e "$(YELLOW "createControllerConfig requires a controller name to be supplied") " - echo -en "Enter controller name: " - read -r controller_name - - # Quit if no name is provided - if [[ "${controller_name}" == "" ]]; then - echo -e "$(RED " --- Invalid controller name provided ---")" - return 1 - fi - # If no controller name provided and env var is set, use env var - elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then - controller_name="${ZITI_EDGE_CONTROLLER_RAWNAME}" - fi - - # Make sure necessary env variables are set - checkEnvVariable ZITI_HOME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - cat "${ZITI_CTRL_IDENTITY_SERVER_CERT}" > "${ZITI_CTRL_IDENTITY_CA}" - cat "${ZITI_SIGNING_CERT}" >> "${ZITI_CTRL_IDENTITY_CA}" - echo -e "wrote CA file to: $(BLUE "${ZITI_CTRL_IDENTITY_CA}")" - - output_file="${ZITI_HOME}/${controller_name}.yaml" - - getFileOverwritePermission "${output_file}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - "${ZITI_BIN_DIR}/ziti" create config controller > "${output_file}" - - echo -e "Controller configuration file written to: $(BLUE "${output_file}")" -} - -# shellcheck disable=SC2120 -function ziti_createEnvFile { - checkEnvVariable ZITI_HOME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - if decideToUseDefaultZitiHome; then - ZITI_HOME="${DEFAULT_ZITI_HOME_LOCATION}" - else - return 1 - fi - fi - - export ZITI_HOME="${ZITI_HOME}" - if [[ "${ZITI_OSTYPE}" == "windows" ]]; then - ZITI_HOME_OS_SPECIFIC="$(cygpath -m "${ZITI_HOME}")" - export ZITI_HOME_OS_SPECIFIC - else - export ZITI_HOME_OS_SPECIFIC="${ZITI_HOME}" - fi - export ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env" - export ZITI_SHARED="${ZITI_HOME}" - - checkEnvVariable ENV_FILE - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - if [[ "${network_name-}" != "" ]]; then - export ZITI_NETWORK="${network_name}" - fi - - if [[ "${ZITI_NETWORK-}" == "" ]]; then - if [[ "${1-}" != "" ]]; then - export ZITI_NETWORK="${1-}" - fi - if [[ "${ZITI_NETWORK-}" = "" ]]; then - echo -e "$(YELLOW "WARN: ZITI_NETWORK HAS NOT BEEN DECLARED! USING hostname: ${DEFAULT_ZITI_NETWORK}")" - # shellcheck disable=SC2155 - export ZITI_NETWORK="${DEFAULT_ZITI_NETWORK}" - fi - fi - - echo "ZITI_NETWORK set to: ${ZITI_NETWORK}" - - if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; fi - if [[ "${ZITI_PWD-}" == "" ]]; then + # Get Controller Credentials + if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; else echo "ZITI_USER overridden: ${ZITI_USER}"; fi + if [[ "${ZITI_PWD-}" == "" ]]; then ZITI_PWD="$(LC_ALL=C tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c32)" echo -en "Do you want to keep the generated admin password '$ZITI_PWD'? (Y/n) " # shellcheck disable=SC2162 @@ -1087,71 +280,94 @@ function ziti_createEnvFile { echo -en "Type the preferred admin password and press " read -r ZITI_PWD fi - fi - if [[ "${ZITI_DOMAIN_SUFFIX-}" == "" ]]; then export ZITI_DOMAIN_SUFFIX=""; fi - if [[ "${ZITI_ID-}" == "" ]]; then export ZITI_ID="${ZITI_HOME}/identities.yaml"; fi - - export ZITI_PKI="${ZITI_SHARED}/pki" - if [[ "${ZITI_OSTYPE}" == "windows" ]]; then - ZITI_PKI_OS_SPECIFIC="$(cygpath -m "${ZITI_PKI}")" - export ZITI_PKI_OS_SPECIFIC else - export ZITI_PKI_OS_SPECIFIC="${ZITI_PKI}" + echo "ZITI_PWD overridden: ${ZITI_PWD}" fi - if [[ "${ZITI_EDGE_CONTROLLER_PORT-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_PORT="1280"; fi - if [[ "${ZITI_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_CONTROLLER_HOSTNAME="${ZITI_CONTROLLER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi - if [[ "${ZITI_CTRL_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_ADVERTISED_ADDRESS="${ZITI_CONTROLLER_HOSTNAME}"; fi - if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_HOSTNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi - if [[ "${ZITI_ZAC_HOSTNAME-}" == "" ]]; then export ZITI_ZAC_HOSTNAME="${ZITI_ZAC_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi - if [[ "${ZITI_EDGE_CTRL_ADVERTISED-}" == "" ]]; then export ZITI_EDGE_CTRL_ADVERTISED="${ZITI_EDGE_CONTROLLER_HOSTNAME}:${ZITI_EDGE_CONTROLLER_PORT}"; fi + # PKI Values + if [[ "${ZITI_PKI-}" == "" ]]; then export ZITI_PKI="${ZITI_HOME}/pki"; else echo "ZITI_PKI overridden: ${ZITI_PKI}"; fi + if [[ "${ZITI_PKI_SIGNER_CERT_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_CERT_NAME="${ZITI_NETWORK}-signing"; else echo "ZITI_PKI_SIGNER_CERT_NAME overridden: ${ZITI_PKI_SIGNER_CERT_NAME}"; fi + if [[ "${ZITI_PKI_SIGNER_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_ROOTCA_NAME="${ZITI_PKI_SIGNER_CERT_NAME}-root-ca"; else echo "ZITI_PKI_SIGNER_ROOTCA_NAME overridden: ${ZITI_PKI_SIGNER_ROOTCA_NAME}"; fi + if [[ "${ZITI_PKI_SIGNER_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_INTERMEDIATE_NAME="${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}-intermediate"; else echo "ZITI_PKI_SIGNER_INTERMEDIATE_NAME overridden: ${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}"; fi + if [[ "${ZITI_PKI_SIGNER_CERT}" == "" ]]; then export ZITI_PKI_SIGNER_CERT="${ZITI_PKI}/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}/certs/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}.cert"; else echo "ZITI_PKI_SIGNER_CERT overridden: ${ZITI_PKI_SIGNER_CERT}"; fi + if [[ "${ZITI_PKI_SIGNER_KEY}" == "" ]]; then export ZITI_PKI_SIGNER_KEY="${ZITI_PKI}/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}/keys/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}.key"; else echo "ZITI_PKI_SIGNER_KEY overridden: ${ZITI_PKI_SIGNER_KEY}"; fi - export ZITI_SIGNING_CERT_NAME="${ZITI_NETWORK}-signing" + # Run these functions to populate other pertinent environment values + _detect_architecture # ZITI_ARCH + _detect_OS # ZITI_OSTYPE + getLatestZitiVersion # ZITI_BINARIES_FILE & ZITI_BINARIES_VERSION - export ZITI_CONTROLLER_ROOTCA_NAME="${ZITI_CONTROLLER_HOSTNAME}-root-ca" - export ZITI_CONTROLLER_INTERMEDIATE_NAME="${ZITI_CONTROLLER_HOSTNAME}-intermediate" + # Must run after the above (dependent on other variables) + if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}"; fi - export ZITI_EDGE_CONTROLLER_ROOTCA_NAME="${ZITI_EDGE_CONTROLLER_HOSTNAME}-root-ca" - export ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME="${ZITI_EDGE_CONTROLLER_HOSTNAME}-intermediate" + # Controller Values + if [[ "${ZITI_CTRL_NAME-}" == "" ]]; then export ZITI_CTRL_NAME="${ZITI_NETWORK}"; else echo "ZITI_CTRL_NAME overridden: ${ZITI_CTRL_NAME}"; fi + if [[ "${ZITI_CTRL_LISTENER_PORT-}" == "" ]]; then export ZITI_CTRL_LISTENER_PORT="6262"; else echo "ZITI_CTRL_LISTENER_PORT overridden: ${ZITI_CTRL_LISTENER_PORT}"; fi + if [[ "${ZITI_CTRL_EDGE_ADVERTISED_PORT-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT="1280"; else echo "ZITI_CTRL_EDGE_ADVERTISED_PORT overridden: ${ZITI_CTRL_EDGE_ADVERTISED_PORT}"; fi + if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_NETWORK-}"; else echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS overridden: ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}"; fi + if [[ "${ZITI_PKI_CTRL_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_ROOTCA_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-root-ca"; else echo "ZITI_PKI_CTRL_ROOTCA_NAME overridden: ${ZITI_PKI_CTRL_ROOTCA_NAME}"; fi + if [[ "${ZITI_PKI_CTRL_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_INTERMEDIATE_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-intermediate"; else echo "ZITI_PKI_CTRL_INTERMEDIATE_NAME overridden: ${ZITI_PKI_CTRL_INTERMEDIATE_NAME}"; fi + if [[ "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_EDGE_ROOTCA_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-root-ca"; else echo "ZITI_PKI_CTRL_EDGE_ROOTCA_NAME overridden: ${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}"; fi + if [[ "${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-intermediate"; else echo "ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME overridden: ${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}"; fi + if [[ "${ZITI_PKI_CTRL_SERVER_CERT-}" == "" ]]; then export ZITI_PKI_CTRL_SERVER_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.chain.pem"; else echo "ZITI_PKI_CTRL_SERVER_CERT overridden: ${ZITI_PKI_CTRL_SERVER_CERT}"; fi + if [[ "${ZITI_PKI_CTRL_KEY-}" == "" ]]; then export ZITI_PKI_CTRL_KEY="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.key"; else echo "ZITI_PKI_CTRL_KEY overridden: ${ZITI_PKI_CTRL_KEY}"; fi + if [[ "${ZITI_PKI_CTRL_CA-}" == "" ]]; then export ZITI_PKI_CTRL_CA="${ZITI_PKI}/cas.pem"; else echo "ZITI_PKI_CTRL_CA overridden: ${ZITI_PKI_CTRL_CA}"; fi + if [[ "${ZITI_PKI_CTRL_CERT-}" == "" ]]; then export ZITI_PKI_CTRL_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-client.cert"; else echo "ZITI_PKI_CTRL_CERT overridden: ${ZITI_PKI_CTRL_CERT}"; fi + if [[ "${ZITI_PKI_EDGE_CERT-}" == "" ]]; then export ZITI_PKI_EDGE_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-client.cert"; else echo "ZITI_PKI_EDGE_CERT overridden: ${ZITI_PKI_EDGE_CERT}"; fi + if [[ "${ZITI_PKI_EDGE_SERVER_CERT}" == "" ]]; then export ZITI_PKI_EDGE_SERVER_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.chain.pem"; else echo "ZITI_PKI_EDGE_SERVER_CERT overridden: ${ZITI_PKI_EDGE_SERVER_CERT}"; fi + if [[ "${ZITI_PKI_EDGE_KEY}" == "" ]]; then export ZITI_PKI_EDGE_KEY="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.key"; else echo "ZITI_PKI_EDGE_KEY overridden: ${ZITI_PKI_EDGE_KEY}"; fi + if [[ "${ZITI_PKI_EDGE_CA}" == "" ]]; then export ZITI_PKI_EDGE_CA="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}.cert"; else echo "ZITI_PKI_EDGE_CA overridden: ${ZITI_PKI_EDGE_CA}"; fi - export ZITI_SIGNING_ROOTCA_NAME="${ZITI_SIGNING_CERT_NAME}-root-ca" - export ZITI_SIGNING_INTERMEDIATE_NAME="${ZITI_SIGNING_CERT_NAME}-intermediate" + # Router Values + if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then ZITI_EDGE_ROUTER_NAME="${ZITI_NETWORK}-edge-router"; else echo "ZITI_EDGE_ROUTER_NAME overridden: ${ZITI_EDGE_ROUTER_NAME}"; fi + if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; else echo "ZITI_EDGE_ROUTER_PORT overridden: ${ZITI_EDGE_ROUTER_PORT}"; fi - if [[ "${ZITI_CTRL_MGMT_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_PORT="10000"; fi - if [[ "${ZITI_CTRL_MGMT_HOST_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_HOST_PORT="${ZITI_CONTROLLER_HOSTNAME}:${ZITI_CTRL_MGMT_PORT}"; fi - if [[ "${ZITI_CTRL_IDENTITY_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-client.cert"; fi - if [[ "${ZITI_CTRL_IDENTITY_SERVER_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-server.chain.pem"; fi - if [[ "${ZITI_CTRL_IDENTITY_KEY-}" == "" ]]; then export ZITI_CTRL_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/keys/${ZITI_CONTROLLER_HOSTNAME}-server.key"; fi - if [[ "${ZITI_CTRL_IDENTITY_CA-}" == "" ]]; then export ZITI_CTRL_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/cas.pem"; fi - if [[ "${ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT}" == "" ]]; then export ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT="${ZITI_EDGE_CONTROLLER_HOSTNAME}:${ZITI_EDGE_CONTROLLER_PORT}"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_CERT}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME}-client.cert"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.chain.pem"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_KEY}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/keys/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.key"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_CA}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert"; fi - - if [[ "${ZITI_SIGNING_CERT}" == "" ]]; then export ZITI_SIGNING_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_SIGNING_INTERMEDIATE_NAME}/certs/${ZITI_SIGNING_INTERMEDIATE_NAME}.cert"; fi - if [[ "${ZITI_SIGNING_KEY}" == "" ]]; then export ZITI_SIGNING_KEY="${ZITI_PKI_OS_SPECIFIC}/${ZITI_SIGNING_INTERMEDIATE_NAME}/keys/${ZITI_SIGNING_INTERMEDIATE_NAME}.key"; fi - - if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then ZITI_EDGE_ROUTER_RAWNAME="${ZITI_NETWORK}-edge-router"; fi - - mkdir -p "${ZITI_BIN_ROOT}" + # Set up directories + mkdir -p "${ZITI_HOME}" mkdir -p "${ZITI_HOME}/db" mkdir -p "${ZITI_PKI}" - echo "" > "${ENV_FILE}" - for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; envval="$(echo "${zEnvVar}" | cut -d '=' -f2-100)"; echo "export ${envvar}=\"${envval}\"" >> "${ENV_FILE}"; done + if [[ "${ENV_FILE-}" == "" ]]; then export ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env"; else echo "ENV_FILE overridden: ${ENV_FILE}"; fi + + echo -e "$(GREEN "Your OpenZiti environment has been set up successfully.")" + echo "" +} + +# Stores environment variables prefixed with ZITI_ to a .env file +function persistEnvironmentValues { + local filepath retVal envval envvar zEnvVar + # Get the file path + filepath="${1-}" + if [[ "" == "${filepath}" ]]; then + _check_env_variable ENV_FILE + retVal=$? + if [[ "${retVal}" != 0 ]]; then + echo -e "$(RED " --- persistEnvironment must take a parameter or have ENV_FILE set ---")" + return 1 + else + filepath="${ENV_FILE}" + fi + fi + + # Store all ZITI_ variables in the environment file, creating the directory if necessary + mkdir -p "$(dirname "${filepath}")" && echo "" > "${filepath}" + for zEnvVar in $(set | grep -e "^ZITI_" | sort); do + envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)" + envval="$(echo "${zEnvVar}" | cut -d '=' -f2-100)" + echo "export ${envvar}=\"${envval}\"" >> "${filepath}" + done export PFXLOG_NO_JSON=true # shellcheck disable=SC2129 - echo "export PFXLOG_NO_JSON=true" >> "${ENV_FILE}" + echo "export PFXLOG_NO_JSON=true" >> "${filepath}" - echo "alias zec='ziti edge'" >> "${ENV_FILE}" - echo "alias zlogin='ziti edge login \"\${ZITI_EDGE_CTRL_ADVERTISED}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/\${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert\"'" >> "${ENV_FILE}" - echo "alias zitiLogin='ziti edge login \"\${ZITI_EDGE_CTRL_ADVERTISED}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/\${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert\"'" >> "${ENV_FILE}" - echo "alias psz='ps -ef | grep ziti'" >> "${ENV_FILE}" + echo "alias zec='ziti edge'" >> "${filepath}" + echo "alias zlogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" + echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" + echo "alias psz='ps -ef | grep ziti'" >> "${filepath}" #when sourcing the emitted file add the bin folder to the path - tee -a "${ENV_FILE}" > /dev/null <<'heredoc' + tee -a "${filepath}" > /dev/null <<'heredoc' echo " " if [[ ! "$(echo "$PATH"|grep -q "${ZITI_BIN_DIR}" && echo "yes")" == "yes" ]]; then echo "adding ${ZITI_BIN_DIR} to the path" @@ -1163,30 +379,631 @@ echo " " fi heredoc -echo -e "env file written to: $(BLUE "${ENV_FILE}")" + echo -e "A file with all pertinent environment values was created here: $(BLUE "${filepath}")" + echo "" } -function waitForController { - #devnull="/dev/null" - #if [[ "${ZITI_OSTYPE}" == "windows" ]]; then - # devnull="nul" - #fi - # shellcheck disable=SC2091 - #until $(curl -o /dev/null -sk /dev/null --fail "https://${ZITI_EDGE_CTRL_ADVERTISED}"); do - # echo "waiting for https://${ZITI_EDGE_CTRL_ADVERTISED}" - # sleep 2 - #done - while [[ "$(curl -w "%{http_code}" -m 1 -s -k -o /dev/null https://"${ZITI_EDGE_CTRL_ADVERTISED}"/version)" != "200" ]]; do - echo "waiting for https://${ZITI_EDGE_CTRL_ADVERTISED}" - sleep 3 - done +# Clears environment variables prefixed with ZITI_, and removes ziti environment directories +function removeZitiEnvironment { + local specifiedVersion="" + # No need to `_check_env_variable ZITI_VERSION_OVERRIDE ZITI_BINARIES_VERSION` as this will still run if they're blank + echo -e "$(GREEN "Clearing existing Ziti variables and continuing with express install")" + + # Check if the user chose a specific version + if [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]] && [[ "${ZITI_VERSION_OVERRIDE-}" != "${ZITI_BINARIES_VERSION-}" ]]; then + # Don't allow overriding the version if ziti quickstart was already run, the DB may not be compatible + echo -e "$(RED " --- Overriding the ziti version is not supported if the version differs from one already installed. ---")" + echo -en "Would you like to continue by using the latest version. (y/N)?" + read -r + echo " " + if [[ "${REPLY}" == [Yy]* ]]; then + unset ZITI_VERSION_OVERRIDE + else + return 1 + fi + elif [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]]; then + echo -e "$(RED " --- You have set the ZITI_VERSION_OVERRIDE value to ${ZITI_VERSION_OVERRIDE}. ---")" + echo -en "Would you like to use this version again, choosing no will pull the latest version. (y/N)?" + read -r + echo " " + if [[ "${REPLY}" == [Yy]* ]]; then + specifiedVersion="${ZITI_VERSION_OVERRIDE}" + fi + fi + + if [[ "${specifiedVersion}" != "" ]]; then + export ZITI_VERSION_OVERRIDE="${specifiedVersion}" + fi + + # Stop any devices currently running to avoid port collisions + stopRouter + stopController + + # Silently clear ziti variables (must be done after stopRouter and stopController) + unsetZitiEnv "-s" } -function createControllerSystemdFile { +function startController { + local retVal log_file pid + _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_CTRL_NAME + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + log_file="${ZITI_HOME-}/${ZITI_CTRL_NAME}.log" + "${ZITI_BIN_DIR-}/ziti" controller run "${ZITI_HOME}/${ZITI_CTRL_NAME}.yaml" &> "${log_file}" 2>&1 & + pid=$! + echo -e "ziti-controller started as process id: ${pid}. log located at: $(BLUE "${log_file}")" +} + +# Disable unused args shellcheck, the arg is optional +#shellcheck disable=SC2120 +function stopController { + local pid retVal + pid=${1-} + if [[ "${pid}" == "" ]]; then + _check_env_variable ZITI_CTRL_LISTENER_PORT + retVal=$? + if [[ "${retVal}" != 0 ]]; then + echo "You will need to source the ziti env file first so that the controller process can be found" + return 1 + fi + + # Get the pid listening on the controller port + pid=$(lsof -ti:"${ZITI_CTRL_LISTENER_PORT}") + fi + + if [[ -n ${pid:-} ]]; then + kill "${pid}" > /dev/null 2>&1 + if [[ $? == 0 ]]; then + echo "Controller stopped." + return 0 + else + echo "ERROR: Something went wrong while trying to stop the controller." + return 1 + fi + else + echo "No process found." + fi +} + +function startRouter { + local pid retVal log_file + _check_env_variable ZITI_HOME ZITI_EDGE_ROUTER_NAME ZITI_BIN_DIR + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + log_file="${ZITI_HOME}/${ZITI_EDGE_ROUTER_NAME}.log" + "${ZITI_BIN_DIR}/ziti" router run "${ZITI_HOME}/${ZITI_EDGE_ROUTER_NAME}.yaml" > "${log_file}" 2>&1 & + pid=$! + echo -e "Express Edge Router started as process id: ${pid}. log located at: $(BLUE "${log_file}")" +} + +# Disable unused args shellcheck, the arg is optional +#shellcheck disable=SC2120 +function stopRouter { + local pid retVal + pid=${1-} + if [[ "${pid}" == "" ]]; then + _check_env_variable ZITI_EDGE_ROUTER_PORT + retVal=$? + if [[ "${retVal}" != 0 ]]; then + echo "You will need to source the ziti env file first so that the router process can be found" + return 1 + fi + + # Get the pid listening on the controller port + pid=$(lsof -ti:"${ZITI_EDGE_ROUTER_PORT}") + fi + + if [[ -n ${pid:-} ]]; then + kill "${pid}" > /dev/null 2>&1 + if [[ $? == 0 ]]; then + echo "Router stopped." + return 0 + else + echo "ERROR: Something went wrong while trying to stop the router." >&2 + return 1 + fi + else + echo "No process found." + fi +} + +# Checks all ports intended to be used in the Ziti network +function checkZitiPorts { + local returnCnt=0 + _portCheck "ZITI_CTRL_LISTENER_PORT" "Controller" + returnCnt=$((returnCnt + $?)) + _portCheck "ZITI_EDGE_ROUTER_PORT" "Edge Router" + returnCnt=$((returnCnt + $?)) + _portCheck "ZITI_CTRL_EDGE_ADVERTISED_PORT" "Edge Controller" + returnCnt=$((returnCnt + $?)) + if [[ "${ZITI_EDGE_ROUTER_LISTENER_BIND_PORT-}" != "" ]]; then + # This port can be explicitly set but is not always, only check if set + _portCheck "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" "Router Listener Bind Port" + returnCnt=$((returnCnt + $?)) + fi + if [[ "returnCnt" -gt "0" ]]; then return 1; fi + echo -e "$(GREEN "Expected ports are all available")" + echo "" +} + +# Detect which OS the script is running on and store it in a variable +function _detect_OS { + if [ -n "${ZITI_OSTYPE}" ]; then return; fi + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + export ZITI_OSTYPE="linux" + elif [[ "$OSTYPE" == "darwin"* ]]; then + export ZITI_OSTYPE="darwin" + elif [[ "$OSTYPE" == "cygwin" ]]; then + export ZITI_OSTYPE="windows" + elif [[ "$OSTYPE" == "msys" ]]; then + export ZITI_OSTYPE="windows" + elif [[ "$OSTYPE" == "win32" ]]; then + export ZITI_OSTYPE="windows" + elif [[ "$OSTYPE" == "freebsd"* ]]; then + echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " + return 1 + else + echo -e " * ERROR: $(RED "\$OSTYPE is not set or is unknown: [$OSTYPE]. Cannot continue") " + return 1 + fi + return 0 +} + +# Detect which architecture the script is running on and store it in a variable +function _detect_architecture { + local detected_arch + if [ -n "${ZITI_ARCH}" ]; then return; fi + _detect_OS + ZITI_ARCH="amd64" + detected_arch="$(uname -m)" + # Apple M1 silicon + if [[ "${detected_arch}" == *"arm"* ]] && [[ "${ZITI_OSTYPE}" == "darwin" ]]; then + echo -e "$(YELLOW "WARN: It has been detected that you are using an Apple computer with ARM architecture. Deployment of Apple ARM architecture distributions is currently unsupported through git, the installer will pull darwin amd distribution instead.")" + # LLVM 64 bit backends have merged so some versions of *nix use aarch64 while others use arm64 for parity with Apple + elif [[ "${detected_arch}" == *"aarch64"* ]] || [[ "${detected_arch}" == *"arm64"* ]]; then + ZITI_ARCH="arm64" + elif [[ "${detected_arch}" == *"arm"* ]]; then + ZITI_ARCH="arm" + fi +} + +# Downloads and extracts ziti binaries onto the system. The latest version is used unless ZITI_VERSION_OVERRIDE is set. +function getZiti { + local retVal default_path ziti_binaries_file_abspath zitidl reply + _check_env_variable ZITI_BIN_DIR + retVal=$? + if [[ "${retVal}" != 0 ]]; then + # Prompt user for input or use default + _setup_ziti_home + getLatestZitiVersion # sets ZITI_BINARIES_FILE & ZITI_BINARIES_VERSION + default_path="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}" + echo -en "The path for ziti binaries has not been set, use the default (${default_path})? (Y/n) " + read -r reply + if [[ -z "${reply}" || ${reply} =~ [yY] ]]; then + echo "INFO: using the default path ${default_path}" + ZITI_BIN_DIR="${default_path}" + else + echo -en "Enter the preferred path and press (the path will be created if necessary)" + read -r ZITI_BIN_DIR + fi + fi + + echo -e "Getting OpenZiti binaries" + echo "" + + # Get the latest version unless a specific version is specified + if [[ "${ZITI_VERSION_OVERRIDE-}" == "" ]]; then + # If not overriding the version, determine the latest and populate ZITI_BINARIES_FILE ZITI_BINARIES_VERSION + if ! getLatestZitiVersion; then + return 1 + fi + else + _check_env_variable ZITI_BINARIES_FILE ZITI_BINARIES_VERSION + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + # Check if an error occurred while trying to pull desired version (happens with incorrect version or formatting issue) + if ! _verify_ziti_version_exists; then + echo -e " * $(RED "ERROR: This version of ziti (${ZITI_VERSION_OVERRIDE}) could not be found. Please check the version and try again. The version should follow the format \"vx.x.x\".") " + return 1 + fi + fi + + # Where to store the ziti binaries zip + ziti_binaries_file_abspath="${ZITI_BIN_DIR}/${ZITI_BINARIES_FILE}" + # Check if they're already downloaded or maybe the user explicitly pointed ZITI_BIN_DIR to their local bins + if ! test -f "${ZITI_BIN_DIR}/ziti"; then + # Make the directory + mkdir -p "${ZITI_BIN_DIR}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR}")" + return 1 + fi + + # Get the download link + zitidl="https://github.com/openziti/ziti/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}" + echo -e 'Downloading '"$(BLUE "${zitidl}")"' to '"$(BLUE "${ziti_binaries_file_abspath}")" + curl -Ls "${zitidl}" -o "${ziti_binaries_file_abspath}" + else + echo -e "$(YELLOW 'Binaries already exist, using existing binaries at ')$(BLUE "${ZITI_BIN_DIR}")" + return 0 + fi + + # Unzip the files + tar -xf "${ziti_binaries_file_abspath}" --directory "${ZITI_BIN_DIR}" + + # Files unzip to a /ziti subdirectory, move them into ZITI_BIN_DIR + # Have to rename the directory first since 'ziti' matches the filename for the 'ziti' binary + mv "${ZITI_BIN_DIR}/ziti" "${ZITI_BIN_DIR}/ziti-extract" + mv "${ZITI_BIN_DIR}/ziti-extract"/* "${ZITI_BIN_DIR}" + + # Cleanup + rm "${ziti_binaries_file_abspath}" # Remove zip + rm -rf "${ZITI_BIN_DIR}/ziti-extract" # Remove extract folder + + # Mark the files executable + chmod +x "${ZITI_BIN_DIR}/"* + + echo -e "$(GREEN "OpenZiti binaries ${ZITI_BINARIES_VERSION} successfully extracted to $(BLUE "${ZITI_BIN_DIR}")")" + echo "" +} + +# Create a custom PKI +function createPki { + local retVal pki_allow_list_dns pki_allow_list_ip ZITI_SPURIOUS_INTERMEDIATE + _check_env_variable ZITI_PKI_CTRL_ROOTCA_NAME ZITI_PKI_CTRL_EDGE_ROOTCA_NAME ZITI_PKI_SIGNER_ROOTCA_NAME \ + ZITI_PKI_SIGNER_INTERMEDIATE_NAME ZITI_PKI_CTRL_INTERMEDIATE_NAME \ + ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + echo "Generating PKI" + + _pki_create_ca "${ZITI_PKI_CTRL_ROOTCA_NAME}" + _pki_create_ca "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}" + _pki_create_ca "${ZITI_PKI_SIGNER_ROOTCA_NAME}" + + ZITI_SPURIOUS_INTERMEDIATE="${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}_spurious_intermediate" + _pki_create_intermediate "${ZITI_PKI_CTRL_ROOTCA_NAME}" "${ZITI_PKI_CTRL_INTERMEDIATE_NAME}" 1 + _pki_create_intermediate "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}" "${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}" 1 + _pki_create_intermediate "${ZITI_PKI_SIGNER_ROOTCA_NAME}" "${ZITI_SPURIOUS_INTERMEDIATE}" 2 + _pki_create_intermediate "${ZITI_SPURIOUS_INTERMEDIATE}" "${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}" 1 + + pki_allow_list_dns="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS},localhost,${ZITI_NETWORK}" + if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" != "" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}"; fi + if [[ "${EXTERNAL_DNS}" != "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${EXTERNAL_DNS}"; fi + pki_allow_list_ip="127.0.0.1" + if [[ "${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}"; fi + if [[ "${EXTERNAL_IP}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${EXTERNAL_IP}"; fi + + pki_allow_list_dns="${pki_allow_list_dns},${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS},localhost,${ZITI_NETWORK}" + _pki_client_server "${pki_allow_list_dns}" "${ZITI_PKI_CTRL_INTERMEDIATE_NAME}" "${pki_allow_list_ip}" "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + echo -e "$(GREEN "PKI generated successfully")" + echo -e "" +} + +# Disable shellcheck un-passed arguments (arguments are optional) +# shellcheck disable=SC2120 +# Creates a controller config file +function createControllerConfig { + local controller_name retVal file_path output_file + # TODO: allow passing in of env file # Allow controller name to be passed in as arg controller_name="${1-}" # If no controller name provided and env var is not set, prompt user for a controller name - if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then + if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_CTRL_NAME}" ]]; then + echo -e "$(YELLOW "createControllerConfig requires a controller name to be supplied") " + echo -en "Enter controller name: " + read -r controller_name + + # Quit if no name is provided + if [[ "${controller_name}" == "" ]]; then + echo -e "$(RED " --- Invalid controller name provided ---")" + return 1 + fi + # If no controller name provided and env var is set, use env var + elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_CTRL_NAME}" ]]; then + controller_name="${ZITI_CTRL_NAME}" + fi + + # Make sure necessary env variables are set + # The following are used by ziti bin to generate the config so they need to be checked: + # ZITI_PKI_SIGNER_KEY ZITI_PKI_EDGE_CERT ZITI_PKI_EDGE_SERVER_CERT ZITI_PKI_EDGE_KEY ZITI_PKI_EDGE_CA + _check_env_variable ZITI_PKI_CTRL_SERVER_CERT ZITI_PKI_CTRL_CA ZITI_PKI_SIGNER_CERT ZITI_PKI_SIGNER_KEY ZITI_BIN_DIR \ + ZITI_PKI_EDGE_CERT ZITI_PKI_EDGE_SERVER_CERT ZITI_PKI_EDGE_KEY ZITI_PKI_EDGE_CA + retVal=$? + if [ $retVal -ne 0 ]; then + return 1 + fi + + # Use the current directory if none is set + file_path="${ZITI_HOME}" + if [[ "${ZITI_HOME-}" == "" ]]; then file_path="."; fi + + cat "${ZITI_PKI_CTRL_SERVER_CERT}" >"${ZITI_PKI_CTRL_CA}" + cat "${ZITI_PKI_SIGNER_CERT}" >>"${ZITI_PKI_CTRL_CA}" + echo -e "wrote CA file to: $(BLUE "${ZITI_PKI_CTRL_CA}")" + + output_file="${file_path}/${controller_name}.yaml" + + _get_file_overwrite_permission "${output_file}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + "${ZITI_BIN_DIR}/ziti" create config controller >"${output_file}" + + echo -e "Controller configuration file written to: $(BLUE "${output_file}")" +} + +# Helper function to create a private edge router +function createPrivateRouterConfig { + _create_router_config "${1-}" "private" +} + +# Helper function to create a public edge router +function createEdgeRouterConfig { + _create_router_config "${1-}" "public" +} + +function createEdgeRouterWssConfig { + _create_router_config "${1-}" "wss" +} + +# Helper function to create a fabric router +function createFabricRouterConfig { + _create_router_config "${1-}" "fabric" +} + +# The main create router config function, all others point to this +function _create_router_config { + local router_name router_type output_file retVal default_router_name file_path + # Allow router name and type to be passed in as arg + router_name="${1-}" + router_type="${2-}" + if [[ "${router_name}" == "" ]]; then + + # If router name is not passed as arg, prompt user for input + echo -e "$(YELLOW "createEdgeRouterConfig requires a router name to be supplied") " + default_router_name="${ZITI_EDGE_ROUTER_NAME}" + echo -en "Enter router name (${default_router_name}):" + read -r router_name + + # Accept the default if no name provided + if [[ "${router_name}" == "" ]]; then + # Check for overwrite of default file + router_name="${default_router_name}" + _get_file_overwrite_permission "${ZITI_HOME-}/${router_name}.yaml" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + fi + fi + # Get router type or set as default + if [[ "${router_type}" == "" ]]; then + router_type="private" + elif [[ "private" != "${router_type}" ]] && [[ "public" != "${router_type}" ]]; then + echo -e "Unknown router type parameter provided, use 'public', 'private', 'fabric', or 'wss'" + fi + + # Make sure necessary env variables are set + # The following are used by ziti bin to generate the config so they need to be checked: + # ZITI_CTRL_EDGE_ADVERTISED_ADDRESS ZITI_CTRL_LISTENER_PORT + _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_CTRL_EDGE_ADVERTISED_ADDRESS ZITI_CTRL_LISTENER_PORT + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + # Use the current directory if none is set + file_path="${ZITI_HOME}" + if [[ "${ZITI_HOME-}" == "" ]]; then file_path="."; fi + + output_file="${file_path}/${router_name}.yaml" + + _get_file_overwrite_permission "${output_file}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + if [[ "public" == "${router_type}" ]]; then + "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" > "${output_file}" + elif [[ "private" == "${router_type}" ]]; then + "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}" + elif [[ "fabric" == "${router_type}" ]]; then + "${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}" + elif [[ "wss" == "${router_type}" ]]; then + "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --wss > "${output_file}" + fi + echo -e "${router_type} router configuration file written to: $(BLUE "${output_file}")" +} + +# Used to create a router, router config, then enroll the router. +function addRouter { + local router_name router_type retVal + # Allow router name and type to be passed in as arg + router_name="${1-}" + router_type="${2-}" + # If no router name provided and env var is not set, prompt user for a router name + if [[ "${router_name}" == "" ]] && [[ -z "${ZITI_EDGE_ROUTER_NAME}" ]]; then + echo -e "$(YELLOW "addRouter requires a router name to be supplied") " + echo -en "Enter router name: " + read -r router_name + + # Quit if no name is provided + if [[ "${router_name}" == "" ]]; then + echo -e "$(RED " --- Invalid router name provided ---")" + return 1 + fi + # If no router name provided and env var is set, use env var + elif [[ "${router_name}" == "" ]] && [[ -n "${ZITI_EDGE_ROUTER_NAME}" ]]; then + router_name="${ZITI_EDGE_ROUTER_NAME}" + fi + + # Make sure necessary env variables are set + _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_USER ZITI_PWD + retVal=$? + if [ $retVal -ne 0 ]; then + return 1 + fi + + # Create router + # TODO: Add prompt to user to delete an existing router if it exists + zitiLogin + "${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${router_name}" + "${ZITI_BIN_DIR-}/ziti" edge create edge-router "${router_name}" -o "${ZITI_HOME}/${router_name}.jwt" -t -a "${router_type}" + + # Create router config + _create_router_config "${router_name}" "${router_type}" + + # Enroll the router + "${ZITI_BIN_DIR-}/ziti" router enroll "${ZITI_HOME}/${router_name}.yaml" --jwt "${ZITI_HOME}/${router_name}.jwt" &> "${ZITI_HOME}/${router_name}.enrollment.log" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + echo -e "$(RED " --- There was an error during router enrollment ---")" + return 1 + else + echo -e "$(GREEN "Enrollment successful")" + fi +} + +function initializeController { + local retVal log_file + # TODO: Update this to possibly take a controller name as an argument, possibly check pwd for controller file, then default to env var values + _setup_ziti_home + # Make sure necessary env variables are set + _check_env_variable ZITI_HOME ZITI_CTRL_NAME ZITI_USER ZITI_PWD ZITI_PKI_CTRL_CA ZITI_BIN_DIR + retVal=$? + if [ $retVal -ne 0 ]; then + return 1 + fi + + log_file="${ZITI_HOME-}/${ZITI_CTRL_NAME}-init.log" + "${ZITI_BIN_DIR-}/ziti" controller edge init "${ZITI_HOME}/${ZITI_CTRL_NAME}.yaml" -u "${ZITI_USER-}" -p "${ZITI_PWD}" &> "${log_file}" + echo -e "${ZITI_CTRL_NAME} initialized. See $(BLUE "${log_file}") for details" +} + +function zitiLogin { + local advertised_host_port="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:${ZITI_CTRL_EDGE_ADVERTISED_PORT}" + "${ZITI_BIN_DIR-}/ziti" edge login "${advertised_host_port}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -y 2>&1 +} + +function expressInstall { + local retVal + # Check if expressInstall has been run before + if [[ "" != "${ZITIx_EXPRESS_COMPLETE-}" ]]; then + echo -e "$(RED " --- It looks like you've run an express install in this shell already. ---")" + echo -en "Would you like to clear existing Ziti variables and continue (y/N)? " + read -r + echo " " + if [[ "${REPLY}" == [Yy]* ]]; then + removeZitiEnvironment + else + echo -e "$(RED " --- Exiting express install ---")" + return 1 + fi + fi + export ZITIx_EXPRESS_COMPLETE="true" + _issue_preamble + + # This is redundant but better to check here to prevent going any further + _check_prereq curl jq + retVal=$? + if [ $retVal -ne 0 ]; then + return 1 + fi + _issue_greeting + + echo -e "$(PURPLE "******** Setting Up Your OpenZiti Environment ********")" + # If a parameter was provided, set the network name to this value + if [[ "${1-}" != "" ]]; then + ZITI_NETWORK="${1-}" + fi + setupEnvironment + persistEnvironmentValues "" + + echo -e "$(PURPLE "******** Getting OpenZiti Binaries ********")" + if ! getZiti "no"; then + echo -e "$(RED "getZiti failed")" + return 1 + fi + + # Check Ports + echo -e "$(PURPLE "******** Ensure the Necessary Ports Are Open ********")" + if ! checkZitiPorts; then + echo "Please clear the unavailable ports or change their values and try again." + return 1 + fi + + # Create PKI + echo -e "$(PURPLE "******** Generating Public Key Infrastructure ********")" + createPki + + echo -e "$(PURPLE "******** Setting Up Controller ********")" + createControllerConfig + initializeController + startController + echo "waiting for the controller to come online to allow the edge router to enroll" + _wait_for_controller + echo "" + + echo -e "$(PURPLE "******** Setting Up Edge Router ********")" + zitiLogin + echo "" + echo -e "---------- Creating an edge router policy allowing all identities to connect to routers with a $(GREEN "#public") attribute" + "${ZITI_BIN_DIR-}/ziti" edge delete edge-router-policy allEdgeRouters > /dev/null + "${ZITI_BIN_DIR-}/ziti" edge create edge-router-policy allEdgeRouters --edge-router-roles '#public' --identity-roles '#all' > /dev/null + + echo -e "---------- Creating a service edge router policy allowing all services to use $(GREEN "#public") edge routers" + "${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcAllRouters > /dev/null + "${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcAllRouters --edge-router-roles '#all' --service-roles '#all' > /dev/null + echo "" + + echo "USING ZITI_EDGE_ROUTER_NAME: $ZITI_EDGE_ROUTER_NAME" + + addRouter "${ZITI_EDGE_ROUTER_NAME}" "public" + echo "" + + stopController + echo "Edge Router enrolled." + + echo "" + echo -e "$(GREEN "Congratulations. Express setup complete!")" + echo -e "Start your Ziti Controller by running the function: $(BLUE "startController")" + echo -e "Start your Ziti Edge Router by running : $(BLUE 'startRouter')" + echo "" +} + +# Gets the latest Ziti binary (the process is different for latest vs older so unfortunately two functions are needed) +function getLatestZitiVersion { + local ziti_latest + if ! _detect_OS; then + return 1 + fi + + _detect_architecture + + ziti_latest=$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/latest) + ZITI_BINARIES_FILE=$(echo "${ziti_latest}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') + ZITI_BINARIES_VERSION=$(echo "${ziti_latest}" | tr '\r\n' ' ' | jq -r '.tag_name') +} + +function createControllerSystemdFile { + local controller_name retVal output_file + # Allow controller name to be passed in as an arg + controller_name="${1-}" + # If no controller name provided and env var is not set, prompt user for a controller name + if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_CTRL_NAME}" ]]; then echo -e "$(YELLOW "createControllerSystemdFile requires a controller name to be supplied") " echo -en "Enter controller name:" read -r controller_name @@ -1197,12 +1014,12 @@ function createControllerSystemdFile { return 1 fi # If no controller name provided and env var is set, use env var - elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then - controller_name="${ZITI_EDGE_CONTROLLER_RAWNAME}" + elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_CTRL_NAME}" ]]; then + controller_name="${ZITI_CTRL_NAME}" fi # Make sure necessary env variables are set - checkEnvVariable ZITI_HOME ZITI_BIN_DIR + _check_env_variable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1237,13 +1054,14 @@ HeredocForSystemd } function createRouterSystemdFile { - # Allow router name to be passed in as arg + local router_name default_router_name retVal output_file + # Allow router name to be passed in as an arg router_name="${1-}" if [[ "${router_name}" == "" ]]; then # If router name is not passed as arg, prompt user for input echo -e "$(YELLOW "createRouterSystemdFile requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + default_router_name="${ZITI_EDGE_ROUTER_NAME}" echo -en "Enter router name (${default_router_name}):" read -r router_name @@ -1259,7 +1077,7 @@ function createRouterSystemdFile { fi fi - checkEnvVariable ZITI_HOME ZITI_BIN_DIR + _check_env_variable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1294,10 +1112,11 @@ HeredocForSystemd } function createControllerLaunchdFile { + local controller_name retVal output_file # Allow controller name to be passed in as arg controller_name="${1-}" # If no controller name provided and env var is not set, prompt user for a controller name - if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then + if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_CTRL_NAME}" ]]; then echo -e "$(YELLOW "createControllerLaunchdFile requires a controller name to be supplied") " echo -en "Enter controller name: " read -r controller_name @@ -1308,12 +1127,12 @@ function createControllerLaunchdFile { return 1 fi # If no controller name provided and env var is set, use env var - elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then - controller_name="${ZITI_EDGE_CONTROLLER_RAWNAME}" + elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_CTRL_NAME}" ]]; then + controller_name="${ZITI_CTRL_NAME}" fi # Make sure necessary env variables are set - checkEnvVariable ZITI_HOME ZITI_BIN_DIR + _check_env_variable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1329,7 +1148,7 @@ function createControllerLaunchdFile { cat > "${output_file}" < - + Label @@ -1363,13 +1182,14 @@ HeredocForLaunchd } function createRouterLaunchdFile { + local router_name default_router_name retVal output_file # Allow router name to be passed in as arg router_name="${1-}" if [[ "${router_name}" == "" ]]; then # If router name is not passed as arg, prompt user for input echo -e "$(YELLOW "createRouterLaunchdFile requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + default_router_name="${ZITI_EDGE_ROUTER_NAME}" echo -en "Enter router name (${default_router_name}):" read -r router_name @@ -1386,7 +1206,7 @@ function createRouterLaunchdFile { fi # Make sure necessary env variables are set - checkEnvVariable ZITI_HOME ZITI_BIN_DIR + _check_env_variable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1402,7 +1222,7 @@ function createRouterLaunchdFile { cat > "${output_file}" < - + Label @@ -1444,8 +1264,8 @@ function showLaunchdMessage { } function createZacSystemdFile { - - checkEnvVariable ZITI_HOME + local retVal output_file node_bin + _check_env_variable ZITI_HOME retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1461,7 +1281,7 @@ function createZacSystemdFile { if which node >/dev/null; then # store the absolute path to the node executable because it's required by systemd on Amazon Linux, at least - NODE_BIN=$(readlink -f "$(which node)") + node_bin=$(readlink -f "$(which node)") else echo "ERROR: missing executable 'node'" >&2 return 1 @@ -1475,7 +1295,7 @@ After=network.target [Service] User=root WorkingDirectory=${ZITI_HOME}/ziti-console -ExecStart=${NODE_BIN} "${ZITI_HOME}/ziti-console/server.js" +ExecStart=${node_bin} "${ZITI_HOME}/ziti-console/server.js" Restart=always RestartSec=2 LimitNOFILE=65536 @@ -1487,69 +1307,78 @@ HeredocForSystemd echo -e "ziti-console systemd file written to: $(BLUE "${output_file}")" } -function setOs { - if [ -n "${ZITI_OSTYPE}" ]; then return; fi - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - export ZITI_OSTYPE="linux" - elif [[ "$OSTYPE" == "darwin"* ]]; then - export ZITI_OSTYPE="darwin" - elif [[ "$OSTYPE" == "cygwin" ]]; then - export ZITI_OSTYPE="windows" - #echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " - #return 1 - elif [[ "$OSTYPE" == "msys" ]]; then - export ZITI_OSTYPE="windows" - #echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " - #return 1 - elif [[ "$OSTYPE" == "win32" ]]; then - export ZITI_OSTYPE="windows" - elif [[ "$OSTYPE" == "freebsd"* ]]; then - echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " - return 1 - else - echo -e " * ERROR: $(RED "\$OSTYPE is not set or is unknown: [$OSTYPE]. Cannot continue") " - return 1 +# Ensure that the version desired as specified by ZITI_VERSION_OVERRIDE exists, this returns an error in cases where +# the version doesn't exist or possibly just the version format provided in ZITI_VERSION_OVERRIDE is incorrect. +function _verify_ziti_version_exists { + local ziticurl + + if ! setOs; then + return 1 fi - return 0 + + _detect_architecture + + ziticurl="$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/tags/"${ZITI_VERSION_OVERRIDE}")" + ZITI_BINARIES_FILE=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') + ZITI_BINARIES_VERSION=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.tag_name') + + # Check if there was an error while trying to get the requested version + if [[ "${ZITI_BINARIES_VERSION-}" == "null" ]]; then + echo "ERROR: response missing '.tag_name': ${ziticurl}" >&2 + return 1 + fi + + echo "The ziti version requested (${ZITI_BINARIES_VERSION}) was verified and has been stored in ZITI_BINARIES_VERSION" } -function checkEnvVariable() { - - for arg - do - # Parameter expansion is different between shells - if [[ -n "$ZSH_VERSION" ]]; then - # shellcheck disable=SC2296 - if [[ -z "${(P)arg}" ]]; then - echo -e " * ERROR: $(RED "${arg} is not set") " - return 1 - fi - elif [[ -n "$BASH_VERSION" ]]; then - if [[ -z "${!arg}" ]]; then - echo -e " * ERROR: $(RED "${arg} is not set") " - return 1 - fi - else - echo -e " * $(RED "Unsupported shell, supply a PR or log an issue on https://github.com/openziti/ziti") " - return 1 - fi - done - return 0 -} - -function getFileOverwritePermission() { - file_path="${1-}" - - if [[ -f "${file_path}" ]]; then - echo -en "This will overwrite the existing file, continue (y/N)? " - read -r - if [[ "${REPLY}" == [^Yy]* ]]; then - echo -e "$(RED " --- Cancelling overwrite ---")" - return 1 - fi +# Disable shellcheck for parameter expansion error, this function supports multiple shells +# shellcheck disable=SC2296 +# Check to ensure the expected ports are available +function _portCheck { + local portCheckResult envVar envVarValue + if [[ "${1-}" == "" ]] || [[ "${2-}" == "" ]]; then + echo -e "_portCheck Usage: _portCheck " return 0 fi + + envVar="${1-}" + if [[ -n "$ZSH_VERSION" ]]; then + envVarValue="${(P)envVar}" + elif [[ -n "$BASH_VERSION" ]]; then + envVarValue="${!envVar}" + else + echo -e "$(YELLOW "Unknown/Unsupported shell, cannot verify availability of ${2-}'s intended port, proceed with caution")" + return 0 + fi + + echo -e "Checking ${2-}'s port (${envVarValue}) $(GREEN "Open")" + portCheckResult=$(lsof -w -i :"${envVarValue}" 2>&1) + if [[ "${portCheckResult}" != "" ]]; then + echo -e "$(RED " ")" + echo -e "$(RED "The intended ${2-} port (${envVarValue}) is currently being used, the process using this port should be closed or the port value should be changed.")" + echo -e "$(RED "To use a different port, set the port value in ${envVar}")" + echo -e "$(RED " ")" + echo -e "$(RED "Example:")" + echo -e "$(RED "export ${envVar}=1234")" + echo -e "$(RED " ")" + return 1 + fi + return 0 } -set +uo pipefail +# ******* Deprecated functions, refer to new functions ********** +function deprecationMessage { + echo -e "$(YELLOW "WARNING The ${1} function has been deprecated, please use ${2} going forward")" +} + +function generateEnvFile { + deprecationMessage generateEnvFile persistEnvironmentValues + persistEnvironmentValues +} +function waitForController { + deprecationMessage waitForController _wait_for_controller + _wait_for_controller +} + +set +uo pipefail \ No newline at end of file diff --git a/quickstart/docker/simplified-docker-compose.yml b/quickstart/docker/simplified-docker-compose.yml index 407beb3eb..6cee5fe7a 100644 --- a/quickstart/docker/simplified-docker-compose.yml +++ b/quickstart/docker/simplified-docker-compose.yml @@ -5,8 +5,8 @@ services: env_file: - ./.env ports: - - ${ZITI_EDGE_CONTROLLER_PORT:-1280}:${ZITI_EDGE_CONTROLLER_PORT:-1280} - - ${ZITI_CTRL_PORT:-6262}:${ZITI_CTRL_PORT:-6262} + - ${ZITI_CTRL_EDGE_ADVERTISED_PORT:-1280}:${ZITI_CTRL_EDGE_ADVERTISED_PORT:-1280} + - ${ZITI_CTRL_LISTENER_PORT:-6262}:${ZITI_CTRL_LISTENER_PORT:-6262} environment: - ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION=${ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION} - ZITI_EDGE_ROUTER_ENROLLMENT_DURATION=${ZITI_EDGE_ROUTER_ENROLLMENT_DURATION} @@ -27,8 +27,8 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + - ZITI_CTRL_EDGE_ADVERTISED_PORT="${ZITI_CTRL_EDGE_ADVERTISED_PORT}" env_file: - ./.env networks: @@ -50,9 +50,8 @@ services: depends_on: - ziti-controller environment: - - ZITI_CONTROLLER_RAWNAME="${ZITI_CONTROLLER_RAWNAME}" - - ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}" - - ZITI_EDGE_ROUTER_RAWNAME=${ZITI_EDGE_ROUTER_RAWNAME:-ziti-edge-router} + - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + - ZITI_EDGE_ROUTER_NAME=${ZITI_EDGE_ROUTER_NAME:-ziti-edge-router} - ZITI_EDGE_ROUTER_ROLES=public ports: - ${ZITI_EDGE_ROUTER_PORT:-3022}:${ZITI_EDGE_ROUTER_PORT:-3022} @@ -68,8 +67,8 @@ services: image: openziti/zac working_dir: /usr/src/app environment: - - ZAC_SERVER_CERT_CHAIN=/persistent/pki/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-intermediate/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-server.cert - - ZAC_SERVER_KEY=/persistent/pki/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-intermediate/keys/${ZITI_EDGE_CONTROLLER_HOSTNAME:-ziti-controller}-server.key + - ZAC_SERVER_CERT_CHAIN=/persistent/pki/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-intermediate/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-server.cert + - ZAC_SERVER_KEY=/persistent/pki/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-intermediate/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS:-ziti-controller}-server.key - PORTTLS=8443 depends_on: - ziti-controller diff --git a/quickstart/local/add-zcat.sh b/quickstart/local/add-zcat.sh index 22cf2ecd7..eb2933b78 100644 --- a/quickstart/local/add-zcat.sh +++ b/quickstart/local/add-zcat.sh @@ -5,6 +5,6 @@ ziti edge delete config zcatconfig ziti edge create config zcatconfig ziti-tunneler-client.v1 '{ "hostname" : "zcat.ziti", "port" : 7256 }' ziti edge create service zcatsvc --configs zcatconfig -ziti edge create terminator zcatsvc "${ZITI_EDGE_ROUTER_HOSTNAME}" tcp:localhost:7256 +ziti edge create terminator zcatsvc "${ZITI_ROUTER_ADVERTISED_ADDRESS}" tcp:localhost:7256 diff --git a/quickstart/local/restart-ziti.sh b/quickstart/local/restart-ziti.sh index 21dfb963e..fcf521d86 100755 --- a/quickstart/local/restart-ziti.sh +++ b/quickstart/local/restart-ziti.sh @@ -22,6 +22,6 @@ DIRNAME=$(dirname $0) sleep 1 ziti-router -v run "${ZITI_HOME}/${ZITI_ROUTER_RED_NAME}.yaml" > "${ZITI_HOME}/ziti-${ZITI_ROUTER_RED_NAME}.log" 2>&1 & # sleep 1 -# ziti-router run "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.yaml" > "${ZITI_HOME}/ziti-${ZITI_EDGE_ROUTER_HOSTNAME}.log" 2>&1 & +# ziti-router run "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml" > "${ZITI_HOME}/ziti-${ZITI_ROUTER_ADVERTISED_ADDRESS}.log" 2>&1 & sleep 1 ziti-router -v run "${ZITI_HOME}/${ZITI_EDGE_WSS_ROUTER_HOSTNAME}.yaml" > "${ZITI_HOME}/ziti-${ZITI_EDGE_WSS_ROUTER_HOSTNAME}.log" 2>&1 & diff --git a/quickstart/local/run-dns.sh b/quickstart/local/run-dns.sh deleted file mode 100755 index 4bd51e110..000000000 --- a/quickstart/local/run-dns.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/dev/null -# -# blame(ken) -# -# source this after sourcing env.sh to append required domain names to the dnsmasq.conf in the same dir which is mounted on dnsmasq server by docker-compose.yml - -# DIRNAME defined by init.sh before sourcing this because it's problematic to determine the value of the sourced file in a shell-portable manner -[[ ! -z ${DIRNAME:-} ]] || { - echo "ERROR: not configuring dnsmasq because DIRNAME is not defined." >&2 -} - -# expected in same directory as docker-compose.yml -[[ -s ${DIRNAME}/docker-compose.yml ]] || { - echo "ERROR: missing ${DIRNAME}/docker-compose" -} - -DNSCONF=${DIRNAME}/dnsmasq.conf -[[ -s ${DNSCONF} ]] && { - echo "WARN: clobbered ${DNSCONF}" >&2 -} || { - echo "INFO: created ${DNSCONF}" -} - -cat <| ${DNSCONF} -port=53 -listen-address=${NAMESERVER1:-127.0.0.123} -bind-interfaces -#log all dns queries -log-queries -#don't use host's nameservers in /etc/resolv.conf, only use upstreams define in this conf -no-resolv -# don't forward plain names, only FQDNs -domain-needed -#use google as default nameservers -server=1.1.1.1 -server=8.8.8.8 -#explicitly defines host-ip mappings appended by init.sh -EOF - -for DOMAIN_NAME in ${ZITI_CONTROLLER_HOSTNAME} ${ZITI_EDGE_CONTROLLER_HOSTNAME} ${ZITI_ZAC_HOSTNAME} ${ZITI_EDGE_ROUTER_HOSTNAME} ${ZITI_EDGE_WSS_ROUTER_HOSTNAME} ${ZITI_ROUTER_BR_HOSTNAME} ${ZITI_ROUTER_BLUE_HOSTNAME} ${ZITI_ROUTER_RED_HOSTNAME}; do - echo "address=/${DOMAIN_NAME}/127.0.0.1" >> ${DNSCONF} -done - -docker-compose --file ${DIRNAME}/docker-compose.yml up --detach dns \ No newline at end of file diff --git a/quickstart/local/test-ziti.sh b/quickstart/local/test-ziti.sh index cb8ac4f9a..62254f97e 100755 --- a/quickstart/local/test-ziti.sh +++ b/quickstart/local/test-ziti.sh @@ -12,19 +12,19 @@ ziti edge controller delete config iperfsvcconfig ziti edge controller create config httpbinsvcconfig ziti-tunneler-client.v1 '{ "hostname" : "httpbin.ziti", "port" : 8000 }' ziti edge controller create service httpbinsvc --configs httpbinsvcconfig -ziti edge controller create terminator httpbinsvc "${ZITI_EDGE_ROUTER_HOSTNAME}" tcp:localhost:80 +ziti edge controller create terminator httpbinsvc "${ZITI_ROUTER_ADVERTISED_ADDRESS}" tcp:localhost:80 ziti edge controller create config netcatconfig ziti-tunneler-client.v1 '{ "hostname" : "localhost", "port" : 7256 }' ziti edge controller create service netcatsvc --configs netcatconfig -ziti edge controller create terminator netcatsvc "${ZITI_EDGE_ROUTER_HOSTNAME}" tcp:localhost:7256 +ziti edge controller create terminator netcatsvc "${ZITI_ROUTER_ADVERTISED_ADDRESS}" tcp:localhost:7256 ziti edge controller create config zcatconfig ziti-tunneler-client.v1 '{ "hostname" : "zcat.ziti", "port" : 7256 }' ziti edge controller create service zcatsvc --configs zcatconfig -ziti edge controller create terminator zcatsvc "${ZITI_EDGE_ROUTER_HOSTNAME}" tcp:localhost:7256 +ziti edge controller create terminator zcatsvc "${ZITI_ROUTER_ADVERTISED_ADDRESS}" tcp:localhost:7256 ziti edge controller create config iperfsvcconfig ziti-tunneler-client.v1 '{ "hostname" : "iperf3.ziti", "port" : 15000 }' ziti edge controller create service iperfsvc --configs iperfsvcconfig -ziti edge controller create terminator iperfsvc "${ZITI_EDGE_ROUTER_HOSTNAME}" tcp:localhost:5201 +ziti edge controller create terminator iperfsvc "${ZITI_ROUTER_ADVERTISED_ADDRESS}" tcp:localhost:5201 ziti edge controller delete identity "test_identity" ziti edge controller create identity device "test_identity" -o "${ZITI_HOME}/test_identity".jwt diff --git a/quickstart/test/quickstart_test.go b/quickstart/test/quickstart_test.go index f0e2a8883..909ce3b56 100644 --- a/quickstart/test/quickstart_test.go +++ b/quickstart/test/quickstart_test.go @@ -221,15 +221,13 @@ quickstart script is run. */ func TestQuickStartEnvFile(t *testing.T) { expectedValues := []string{ - "export ZITI_EDGE_ROUTER_RAWNAME=\"localhost-edge-router\"", - "export ZITI_EDGE_CONTROLLER_RAWNAME=\"localhost\"", - "export ZITI_HOME_OS_SPECIFIC=\"/persistent\"", + "export ZITI_EDGE_ROUTER_NAME=\"localhost-edge-router\"", + "export ZITI_CTRL_EDGE_ADVERTISED_PORT=\"localhost\"", "export ZITI_HOME=\"/persistent\"", "export ZITI_BIN_DIR=\"/var/openziti/ziti-bin\"", - "export ZITI_EDGE_CTRL_ADVERTISED=\"localhost:1280\"", "export ZITI_USER=\"admin\"", "export ZITI_PWD=\"admin\"", - "export ZITI_PKI_OS_SPECIFIC=\"/persistent/pki\"", + "export ZITI_PKI=\"/persistent/pki\"", "export ZITI_EDGE_CONTROLLER_ROOTCA_NAME=\"localhost-root-ca\"", "export ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME=\"localhost-intermediate\"", } diff --git a/quickstart/ziti-cli-functions.sh b/quickstart/ziti-cli-functions.sh deleted file mode 120000 index 50707f689..000000000 --- a/quickstart/ziti-cli-functions.sh +++ /dev/null @@ -1 +0,0 @@ -docker/image/ziti-cli-functions.sh \ No newline at end of file diff --git a/ziti/cmd/config_templates/controller.yml b/ziti/cmd/config_templates/controller.yml index 06ebe8210..edd148269 100644 --- a/ziti/cmd/config_templates/controller.yml +++ b/ziti/cmd/config_templates/controller.yml @@ -1,7 +1,7 @@ v: 3 #trace: -# path: "{{ .Controller.Name }}.trace" +# path: "{{ .Controller.Web.BindPoints.AddressAddress }}.trace" #profile: # memory: @@ -10,10 +10,10 @@ v: 3 db: "{{ .ZitiHome }}/db/ctrl.db" identity: - cert: "{{ .Controller.IdentityCert }}" - server_cert: "{{ .Controller.IdentityServerCert }}" - key: "{{ .Controller.IdentityKey }}" - ca: "{{ .Controller.IdentityCA }}" + cert: "{{ .Controller.Identity.Cert }}" + server_cert: "{{ .Controller.Identity.ServerCert }}" + key: "{{ .Controller.Identity.Key }}" + ca: "{{ .Controller.Identity.Ca }}" # Network Configuration # @@ -69,25 +69,13 @@ identity: ctrl: #options: # (optional) settings - # set the maximum number of connect requests that are buffered and waiting to be acknowledged ({{ .Controller.MinQueuedConnects }} to {{ .Controller.MaxQueuedConnects }}, default {{ .Controller.DefaultQueuedConnects }}) - #maxQueuedConnects: {{ .Controller.DefaultQueuedConnects }} - # the maximum number of connects that have begun hello synchronization ({{ .Controller.MinOutstandingConnects }} to {{ .Controller.MaxOutstandingConnects }}, default {{ .Controller.DefaultOutstandingConnects }}) - #maxOutstandingConnects: {{ .Controller.DefaultOutstandingConnects }} - # the number of milliseconds to wait before a hello synchronization fails and closes the connection ({{ .Controller.MinConnectTimeout.Milliseconds }}ms to {{ .Controller.MaxConnectTimeout.Milliseconds }}ms, default: {{ .Controller.DefaultConnectTimeout.Milliseconds }}ms) - #connectTimeoutMs: {{ .Controller.DefaultConnectTimeout.Milliseconds }} - listener: tls:{{ .Controller.ListenerAddress }}:{{ .Controller.Port }} - -# the endpoint that management tools connect to the controller over. -mgmt: - #options: - # (optional) settings - # set the maximum number of connect requests that are buffered and waiting to be acknowledged ({{ .Controller.MinQueuedConnects }} to {{ .Controller.MaxQueuedConnects }}, default {{ .Controller.DefaultQueuedConnects }}) - #maxQueuedConnects: {{ .Controller.DefaultQueuedConnects }} - # the maximum number of connects that have begun hello synchronization ({{ .Controller.MinOutstandingConnects }} to {{ .Controller.MaxOutstandingConnects }}, default {{ .Controller.DefaultOutstandingConnects }}) - #maxOutstandingConnects: {{ .Controller.DefaultOutstandingConnects }} - # the number of milliseconds to wait before a hello synchronization fails and closes the connection ({{ .Controller.MinConnectTimeout.Milliseconds }}ms to {{ .Controller.MaxConnectTimeout.Milliseconds }}ms, default: {{ .Controller.DefaultConnectTimeout.Milliseconds }}ms) - #connectTimeoutMs: {{ .Controller.DefaultConnectTimeout.Milliseconds }} - listener: tls:{{ .Controller.ListenerAddress }}:10000 + # set the maximum number of connect requests that are buffered and waiting to be acknowledged ({{ .Controller.Ctrl.MinQueuedConnects }} to {{ .Controller.Ctrl.MaxQueuedConnects }}, default {{ .Controller.Ctrl.DefaultQueuedConnects }}) + #maxQueuedConnects: {{ .Controller.Ctrl.DefaultQueuedConnects }} + # the maximum number of connects that have begun hello synchronization ({{ .Controller.Ctrl.MinOutstandingConnects }} to {{ .Controller.Ctrl.MaxOutstandingConnects }}, default {{ .Controller.Ctrl.DefaultOutstandingConnects }}) + #maxOutstandingConnects: {{ .Controller.Ctrl.DefaultOutstandingConnects }} + # the number of milliseconds to wait before a hello synchronization fails and closes the connection ({{ .Controller.Ctrl.MinConnectTimeout.Milliseconds }}ms to {{ .Controller.Ctrl.MaxConnectTimeout.Milliseconds }}ms, default: {{ .Controller.Ctrl.DefaultConnectTimeout.Milliseconds }}ms) + #connectTimeoutMs: {{ .Controller.Ctrl.DefaultConnectTimeout.Milliseconds }} + listener: tls:{{ .Controller.Ctrl.ListenerAddress }}:{{ .Controller.Ctrl.ListenerPort }} #metrics: # influxdb: @@ -102,30 +90,30 @@ mgmt: healthChecks: boltCheck: - # How often to try entering a bolt read tx. Defaults to {{ .Controller.HealthCheck.Interval.Seconds }} seconds - interval: {{ .Controller.HealthCheck.Interval.Seconds }}s - # When to time out the check. Defaults to {{ .Controller.HealthCheck.Timeout.Seconds }} seconds - timeout: {{ .Controller.HealthCheck.Timeout.Seconds }}s - # How long to wait before starting the check. Defaults to {{ .Controller.HealthCheck.InitialDelay.Seconds }} seconds - initialDelay: {{ .Controller.HealthCheck.InitialDelay.Seconds }}s + # How often to try entering a bolt read tx. Defaults to {{ .Controller.HealthChecks.Interval.Seconds }} seconds + interval: {{ .Controller.HealthChecks.Interval.Seconds }}s + # When to time out the check. Defaults to {{ .Controller.HealthChecks.Timeout.Seconds }} seconds + timeout: {{ .Controller.HealthChecks.Timeout.Seconds }}s + # How long to wait before starting the check. Defaults to {{ .Controller.HealthChecks.InitialDelay.Seconds }} seconds + initialDelay: {{ .Controller.HealthChecks.InitialDelay.Seconds }}s # By having an 'edge' section defined, the ziti-controller will attempt to parse the edge configuration. Removing this # section, commenting out, or altering the name of the section will cause the edge to not run. edge: # This section represents the configuration of the Edge API that is served over HTTPS api: - #(optional, default {{ .Controller.Edge.APIActivityUpdateInterval.Seconds }}s) Alters how frequently heartbeat and last activity values are persisted - # activityUpdateInterval: {{ .Controller.Edge.APIActivityUpdateInterval.Seconds }}s - #(optional, default {{ .Controller.Edge.APIActivityUpdateBatchSize }}) The number of API Sessions updated for last activity per transaction - # activityUpdateBatchSize: {{ .Controller.Edge.APIActivityUpdateBatchSize }} - # sessionTimeout - optional, default {{ .Controller.Edge.APISessionTimeout.Minutes }}m + #(optional, default {{ .Controller.EdgeApi.APIActivityUpdateInterval.Seconds }}s) Alters how frequently heartbeat and last activity values are persisted + # activityUpdateInterval: {{ .Controller.EdgeApi.APIActivityUpdateInterval.Seconds }}s + #(optional, default {{ .Controller.EdgeApi.APIActivityUpdateBatchSize }}) The number of API Sessions updated for last activity per transaction + # activityUpdateBatchSize: {{ .Controller.EdgeApi.APIActivityUpdateBatchSize }} + # sessionTimeout - optional, default {{ .Controller.EdgeApi.SessionTimeout.Minutes }}m # The number of minutes before an Edge API session will time out. Timeouts are reset by # API requests and connections that are maintained to Edge Routers - sessionTimeout: {{ .Controller.Edge.APISessionTimeout.Minutes }}m + sessionTimeout: {{ .Controller.EdgeApi.SessionTimeout.Minutes }}m # address - required # The default address (host:port) to use for enrollment for the Client API. This value must match one of the addresses # defined in this Controller.WebListener.'s bindPoints. - address: {{ .Controller.Edge.AdvertisedHostPort }} + address: {{ .Controller.EdgeApi.Address }}:{{ .Controller.EdgeApi.Port }} # This section is used to define option that are used during enrollment of Edge Routers, Ziti Edge Identities. enrollment: # signingCert - required @@ -133,22 +121,22 @@ edge: # a signing certificate from the PKI that the Ziti environment is using to sign certificates. The signingCert.cert # will be added to the /.well-known CA store that is used to bootstrap trust with the Ziti Controller. signingCert: - cert: {{ .Controller.Edge.ZitiSigningCert }} - key: {{ .Controller.Edge.ZitiSigningKey }} + cert: {{ .Controller.EdgeEnrollment.SigningCert }} + key: {{ .Controller.EdgeEnrollment.SigningCertKey }} # edgeIdentity - optional # A section for identity enrollment specific settings edgeIdentity: - # duration - optional, default {{ .Controller.DefaultEdgeIdentityDuration.Minutes }}m + # duration - optional, default {{ .Controller.EdgeEnrollment.DefaultEdgeIdentityDuration.Minutes }}m # The length of time that a Ziti Edge Identity enrollment should remain valid. After # this duration, the enrollment will expire and no longer be usable. - duration: {{ .Controller.EdgeIdentityDuration.Minutes }}m + duration: {{ .Controller.EdgeEnrollment.EdgeIdentityDuration.Minutes }}m # edgeRouter - Optional # A section for edge router enrollment specific settings. edgeRouter: - # duration - optional, default {{ .Controller.DefaultEdgeRouterDuration.Minutes }}m + # duration - optional, default {{ .Controller.EdgeEnrollment.DefaultEdgeRouterDuration.Minutes }}m # The length of time that a Ziti Edge Router enrollment should remain valid. After # this duration, the enrollment will expire and no longer be usable. - duration: {{ .Controller.EdgeRouterDuration.Minutes }}m + duration: {{ .Controller.EdgeEnrollment.EdgeRouterDuration.Minutes }}m # web # Defines webListeners that will be hosted by the controller. Each webListener can host many APIs and be bound to many @@ -165,43 +153,43 @@ web: bindPoints: #interface - required # A host:port string on which network interface to listen on. 0.0.0.0 will listen on all interfaces - - interface: {{ .Controller.Edge.ListenerHostPort }} + - interface: {{ .Controller.Web.BindPoints.InterfaceAddress }}:{{ .Controller.Web.BindPoints.InterfacePort }} # address - required # The public address that external incoming requests will be able to resolve. Used in request processing and # response content that requires full host:port/path addresses. - address: {{ .Controller.Edge.AdvertisedHostPort }} + address: {{ .Controller.Web.BindPoints.AddressAddress }}:{{ .Controller.Web.BindPoints.AddressPort }} # identity - optional # Allows the webListener to have a specific identity instead of defaulting to the root 'identity' section. identity: - ca: "{{ .Controller.Edge.IdentityCA }}" - key: "{{ .Controller.Edge.IdentityKey }}" - server_cert: "{{ .Controller.Edge.IdentityServerCert }}" - cert: "{{ .Controller.Edge.IdentityCert }}" + ca: "{{ .Controller.Web.Identity.Ca }}" + key: "{{ .Controller.Web.Identity.Key }}" + server_cert: "{{ .Controller.Web.Identity.ServerCert }}" + cert: "{{ .Controller.Web.Identity.Cert }}" # options - optional # Allows the specification of webListener level options - mainly dealing with HTTP/TLS settings. These options are # used for all http servers started by the current webListener. options: - # idleTimeoutMs - optional, default {{ .Controller.WebListener.IdleTimeout.Milliseconds }}ms + # idleTimeoutMs - optional, default {{ .Controller.Web.Options.IdleTimeout.Milliseconds }}ms # The maximum amount of idle time in milliseconds allowed for pipelined HTTP requests. Setting this too high # can cause resources on the host to be consumed as clients remain connected and idle. Lowering this value # will cause clients to reconnect on subsequent HTTPs requests. - idleTimeout: {{ .Controller.WebListener.IdleTimeout.Milliseconds }}ms #http timeouts, new - # readTimeoutMs - optional, default {{ .Controller.WebListener.ReadTimeout.Milliseconds }}ms + idleTimeout: {{ .Controller.Web.Options.IdleTimeout.Milliseconds }}ms #http timeouts, new + # readTimeoutMs - optional, default {{ .Controller.Web.Options.ReadTimeout.Milliseconds }}ms # The maximum amount of time in milliseconds http servers will wait to read the first incoming requests. A higher # value risks consuming resources on the host with clients that are acting bad faith or suffering from high latency # or packet loss. A lower value can risk losing connections to high latency/packet loss clients. - readTimeout: {{ .Controller.WebListener.ReadTimeout.Milliseconds }}ms - # writeTimeoutMs - optional, default {{ .Controller.WebListener.WriteTimeout.Milliseconds }}ms + readTimeout: {{ .Controller.Web.Options.ReadTimeout.Milliseconds }}ms + # writeTimeoutMs - optional, default {{ .Controller.Web.Options.WriteTimeout.Milliseconds }}ms # The total maximum time in milliseconds that the http server will wait for a single requests to be received and # responded too. A higher value can allow long-running requests to consume resources on the host. A lower value # can risk ending requests before the server has a chance to respond. - writeTimeout: {{ .Controller.WebListener.WriteTimeout.Milliseconds }}ms - # minTLSVersion - optional, default {{ .Controller.WebListener.MinTLSVersion }} + writeTimeout: {{ .Controller.Web.Options.WriteTimeout.Milliseconds }}ms + # minTLSVersion - optional, default {{ .Controller.Web.Options.MinTLSVersion }} # The minimum version of TSL to support - minTLSVersion: {{ .Controller.WebListener.MinTLSVersion }} - # maxTLSVersion - optional, default {{ .Controller.WebListener.MaxTLSVersion }} + minTLSVersion: {{ .Controller.Web.Options.MinTLSVersion }} + # maxTLSVersion - optional, default {{ .Controller.Web.Options.MaxTLSVersion }} # The maximum version of TSL to support - maxTLSVersion: {{ .Controller.WebListener.MaxTLSVersion }} + maxTLSVersion: {{ .Controller.Web.Options.MaxTLSVersion }} # apis - required # Allows one or more APIs to be bound to this webListener apis: diff --git a/ziti/cmd/config_templates/router.yml b/ziti/cmd/config_templates/router.yml index da216eba7..f30c7c6c4 100644 --- a/ziti/cmd/config_templates/router.yml +++ b/ziti/cmd/config_templates/router.yml @@ -13,7 +13,7 @@ identity: ca: "{{ .Router.IdentityCA }}" ctrl: - endpoint: tls:{{ .Controller.AdvertisedAddress }}:{{ .Controller.Port }} + endpoint: tls:{{ .Controller.Web.BindPoints.AddressAddress }}:{{ .Controller.Ctrl.ListenerPort }} link: dialers: diff --git a/ziti/cmd/create_config.go b/ziti/cmd/create_config.go index 2dd5635fd..c2c170dcb 100644 --- a/ziti/cmd/create_config.go +++ b/ziti/cmd/create_config.go @@ -58,50 +58,64 @@ type ConfigTemplateValues struct { Router RouterTemplateValues } -type ControllerTemplateValues struct { - Name string - Port string - AdvertisedAddress string - ListenerAddress string - IdentityCert string - IdentityServerCert string - IdentityKey string - IdentityCA string - MinQueuedConnects int - MaxQueuedConnects int - DefaultQueuedConnects int - MinOutstandingConnects int - MaxOutstandingConnects int - DefaultOutstandingConnects int - MinConnectTimeout time.Duration - MaxConnectTimeout time.Duration - DefaultConnectTimeout time.Duration +type CtrlValues struct { + MinQueuedConnects int + MaxQueuedConnects int + DefaultQueuedConnects int + MinOutstandingConnects int + MaxOutstandingConnects int + DefaultOutstandingConnects int + MinConnectTimeout time.Duration + MaxConnectTimeout time.Duration + DefaultConnectTimeout time.Duration + ListenerAddress string + ListenerPort string +} + +type HealthChecksValues struct { + Interval time.Duration + Timeout time.Duration + InitialDelay time.Duration +} + +type EdgeApiValues struct { + APIActivityUpdateBatchSize int + APIActivityUpdateInterval time.Duration + SessionTimeout time.Duration + Address string + Port string +} + +type EdgeEnrollmentValues struct { + SigningCert string + SigningCertKey string EdgeIdentityDuration time.Duration EdgeRouterDuration time.Duration DefaultEdgeIdentityDuration time.Duration DefaultEdgeRouterDuration time.Duration - Edge EdgeControllerValues - WebListener ControllerWebListenerValues - HealthCheck ControllerHealthCheckValues } -type EdgeControllerValues struct { - AdvertisedPort string - ZitiSigningCert string - ZitiSigningKey string - - APIActivityUpdateBatchSize int - APIActivityUpdateInterval time.Duration - APISessionTimeout time.Duration - ListenerHostPort string - AdvertisedHostPort string - IdentityCert string - IdentityServerCert string - IdentityKey string - IdentityCA string +type WebValues struct { + BindPoints BindPointsValues + Identity IdentityValues + Options WebOptionsValues } -type ControllerWebListenerValues struct { +type BindPointsValues struct { + InterfaceAddress string + InterfacePort string + AddressAddress string + AddressPort string +} + +type IdentityValues struct { + Ca string + Key string + ServerCert string + Cert string +} + +type WebOptionsValues struct { IdleTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration @@ -109,10 +123,13 @@ type ControllerWebListenerValues struct { MaxTLSVersion string } -type ControllerHealthCheckValues struct { - Interval time.Duration - Timeout time.Duration - InitialDelay time.Duration +type ControllerTemplateValues struct { + Identity IdentityValues + Ctrl CtrlValues + HealthChecks HealthChecksValues + EdgeApi EdgeApiValues + EdgeEnrollment EdgeEnrollmentValues + Web WebValues } type RouterTemplateValues struct { @@ -170,16 +187,7 @@ var workingDir string var data = &ConfigTemplateValues{} func init() { - zh := os.Getenv("ZITI_HOME") - if zh == "" { - wd, err := os.Getwd() - if wd == "" || err != nil { - //on error just use "." - workingDir = "." - } - } - - workingDir = cmdHelper.NormalizePath(zh) + workingDir, _ = cmdHelper.GetZitiHome() } // NewCmdCreateConfig creates a command object for the "config" command @@ -206,7 +214,7 @@ func (options *CreateConfigOptions) addCreateFlags(cmd *cobra.Command) { cmd.PersistentFlags().StringVarP(&options.Output, optionOutput, "o", defaultOutput, outputDescription) } -func (data *ConfigTemplateValues) populateEnvVars() { +func (data *ConfigTemplateValues) populateConfigValues() { // Get and add hostname to the params hostname, err := os.Hostname() @@ -216,89 +224,92 @@ func (data *ConfigTemplateValues) populateEnvVars() { zitiHome, err := cmdHelper.GetZitiHome() handleVariableError(err, constants.ZitiHomeVarName) - // Get Ziti Controller Name - zitiCtrlHostname, err := cmdHelper.GetZitiCtrlName() - handleVariableError(err, constants.ZitiCtrlNameVarName) + // Get Ziti Controller ctrl:listener address and port + ctrlListenerAddress, err := cmdHelper.GetCtrlListenerAddress() + handleVariableError(err, constants.CtrlListenerAddressVarName) + ctrlListenerPort, err := cmdHelper.GetCtrlListenerPort() + handleVariableError(err, constants.CtrlListenerPortVarName) + + // Get Ziti Controller edge:api address and port + ctrlEdgeApiAddress, err := cmdHelper.GetCtrlEdgeApiAddress() + handleVariableError(err, constants.CtrlEdgeApiAddressVarName) + ctrlEdgeApiPort, err := cmdHelper.GetCtrlEdgeApiPort() + handleVariableError(err, constants.CtrlEdgeApiPortVarName) + + // Get Ziti Controller Identity edge:enrollment duration + ctrlEdgeIdentityEnrollmentDuration, err := cmdHelper.GetCtrlEdgeIdentityEnrollmentDuration() + handleVariableError(err, constants.CtrlEdgeIdentityEnrollmentDurationVarName) + + // Get Ziti Controller Router edge:enrollment enrollment duration + ctrlEdgeRouterEnrollmentDuration, err := cmdHelper.GetCtrlEdgeRouterEnrollmentDuration() + handleVariableError(err, constants.CtrlEdgeRouterEnrollmentDurationVarName) + + // Get Ziti Controller web:bindPoints interface address and port + ctrlEdgeInterfaceAddress, err := cmdHelper.GetCtrlEdgeInterfaceAddress() + handleVariableError(err, constants.CtrlEdgeInterfaceAddressVarName) + ctrlEdgeInterfacePort, err := cmdHelper.GetCtrlEdgeInterfacePort() + handleVariableError(err, constants.CtrlEdgeInterfacePortVarName) + + // Get Ziti Controller web:bindPoints address address and port + ctrlEdgeAdvertisedAddress, err := cmdHelper.GetCtrlEdgeAdvertisedAddress() + handleVariableError(err, constants.CtrlEdgeAdvertisedAddressVarName) + ctrlEdgeAdvertisedPort, err := cmdHelper.GetCtrlEdgeAdvertisedPort() + handleVariableError(err, constants.CtrlEdgeAdvertisedPortVarName) // Get Ziti Edge Router Port zitiEdgeRouterPort, err := cmdHelper.GetZitiEdgeRouterPort() handleVariableError(err, constants.ZitiEdgeRouterPortVarName) - // Get Ziti Controller Listener Address - zitiCtrlListenerAddress, err := cmdHelper.GetZitiCtrlListenerAddress() - handleVariableError(err, constants.ZitiCtrlListenerAddressVarName) - - // Get Ziti Controller Advertised Address - zitiCtrlAdvertisedAddress, err := cmdHelper.GetZitiCtrlAdvertisedAddress() - handleVariableError(err, constants.ZitiCtrlAdvertisedAddressVarName) - - // Get Ziti Controller Port - zitiCtrlPort, err := cmdHelper.GetZitiCtrlPort() - handleVariableError(err, constants.ZitiCtrlPortVarName) - - // Get Ziti Edge Controller Listener Host and Port - zitiEdgeCtrlListenerHostPort, err := cmdHelper.GetZitiEdgeCtrlListenerHostPort() - handleVariableError(err, constants.ZitiEdgeCtrlListenerHostPortVarName) - - // Get Ziti Edge Controller Advertised Host and Port - zitiEdgeCtrlAdvertisedHostPort, err := cmdHelper.GetZitiEdgeCtrlAdvertisedHostPort() - handleVariableError(err, constants.ZitiEdgeCtrlAdvertisedHostPortVarName) - - // Get Ziti Edge Controller Advertised Port - zitiEdgeCtrlAdvertisedPort, err := cmdHelper.GetZitiEdgeCtrlAdvertisedPort() - handleVariableError(err, constants.ZitiEdgeCtrlAdvertisedPortVarName) - - // Get Ziti edge Identity enrollment duration - zitiEdgeIdentityEnrollmentDuration, err := cmdHelper.GetZitiEdgeIdentityEnrollmentDuration() - handleVariableError(err, constants.ZitiEdgeIdentityEnrollmentDurationVarName) - - // Get Ziti edge Router enrollment duration - zitiEdgeRouterEnrollmentDuration, err := cmdHelper.GetZitiEdgeRouterEnrollmentDuration() - handleVariableError(err, constants.ZitiEdgeRouterEnrollmentDurationVarName) - zitiEdgeRouterListenerBindPort, err := cmdHelper.GetZitiEdgeRouterListenerBindPort() handleVariableError(err, constants.ZitiEdgeRouterListenerBindPortVarName) data.ZitiHome = zitiHome data.Hostname = hostname - data.Controller.Name = zitiCtrlHostname - data.Controller.ListenerAddress = zitiCtrlListenerAddress - data.Controller.AdvertisedAddress = zitiCtrlAdvertisedAddress - data.Controller.Port = zitiCtrlPort - data.Controller.Edge.ListenerHostPort = zitiEdgeCtrlListenerHostPort - data.Controller.Edge.AdvertisedHostPort = zitiEdgeCtrlAdvertisedHostPort + // ************* Controller Values ************ + // Identities are handled in create_config_controller + // ctrl: + data.Controller.Ctrl.MinQueuedConnects = channel.MinQueuedConnects + data.Controller.Ctrl.MaxQueuedConnects = channel.MaxQueuedConnects + data.Controller.Ctrl.DefaultQueuedConnects = channel.DefaultQueuedConnects + data.Controller.Ctrl.MinOutstandingConnects = channel.MinOutstandingConnects + data.Controller.Ctrl.MaxOutstandingConnects = channel.MaxOutstandingConnects + data.Controller.Ctrl.DefaultOutstandingConnects = channel.DefaultOutstandingConnects + data.Controller.Ctrl.MinConnectTimeout = channel.MinConnectTimeout + data.Controller.Ctrl.MaxConnectTimeout = channel.MaxConnectTimeout + data.Controller.Ctrl.DefaultConnectTimeout = channel.DefaultConnectTimeout + data.Controller.Ctrl.ListenerAddress = ctrlListenerAddress + data.Controller.Ctrl.ListenerPort = ctrlListenerPort + // healthChecks: + data.Controller.HealthChecks.Interval = fabCtrl.DefaultHealthChecksBoltCheckInterval + data.Controller.HealthChecks.Timeout = fabCtrl.DefaultHealthChecksBoltCheckTimeout + data.Controller.HealthChecks.InitialDelay = fabCtrl.DefaultHealthChecksBoltCheckInitialDelay + // edge: + data.Controller.EdgeApi.APIActivityUpdateBatchSize = edge.DefaultEdgeApiActivityUpdateBatchSize + data.Controller.EdgeApi.APIActivityUpdateInterval = edge.DefaultEdgeAPIActivityUpdateInterval + data.Controller.EdgeApi.SessionTimeout = edge.DefaultEdgeSessionTimeout + data.Controller.EdgeApi.Address = ctrlEdgeApiAddress + data.Controller.EdgeApi.Port = ctrlEdgeApiPort + data.Controller.EdgeEnrollment.EdgeIdentityDuration = ctrlEdgeIdentityEnrollmentDuration + data.Controller.EdgeEnrollment.EdgeRouterDuration = ctrlEdgeRouterEnrollmentDuration + data.Controller.EdgeEnrollment.DefaultEdgeIdentityDuration = edge.DefaultEdgeEnrollmentDuration + data.Controller.EdgeEnrollment.DefaultEdgeRouterDuration = edge.DefaultEdgeEnrollmentDuration + // web: + data.Controller.Web.BindPoints.InterfaceAddress = ctrlEdgeInterfaceAddress + data.Controller.Web.BindPoints.InterfacePort = ctrlEdgeInterfacePort + data.Controller.Web.BindPoints.AddressAddress = ctrlEdgeAdvertisedAddress + data.Controller.Web.BindPoints.AddressPort = ctrlEdgeAdvertisedPort + // Web Identities are handled in create_config_controller + data.Controller.Web.Options.IdleTimeout = edge.DefaultHttpIdleTimeout + data.Controller.Web.Options.ReadTimeout = edge.DefaultHttpReadTimeout + data.Controller.Web.Options.WriteTimeout = edge.DefaultHttpWriteTimeout + data.Controller.Web.Options.MinTLSVersion = fabXweb.ReverseTlsVersionMap[fabXweb.MinTLSVersion] + data.Controller.Web.Options.MaxTLSVersion = fabXweb.ReverseTlsVersionMap[fabXweb.MaxTLSVersion] + + // ************* Router Values ************ data.Router.Edge.Port = zitiEdgeRouterPort data.Router.Edge.ListenerBindPort = zitiEdgeRouterListenerBindPort - data.Controller.Edge.AdvertisedPort = zitiEdgeCtrlAdvertisedPort - data.Controller.EdgeIdentityDuration = zitiEdgeIdentityEnrollmentDuration - data.Controller.EdgeRouterDuration = zitiEdgeRouterEnrollmentDuration - data.Controller.DefaultEdgeIdentityDuration = edge.DefaultEdgeEnrollmentDuration - data.Controller.DefaultEdgeRouterDuration = edge.DefaultEdgeEnrollmentDuration -} - -func (data *ConfigTemplateValues) populateDefaults() { data.Router.Listener.GetSessionTimeout = constants.DefaultGetSessionTimeout - data.Controller.MinQueuedConnects = channel.MinQueuedConnects - data.Controller.MaxQueuedConnects = channel.MaxQueuedConnects - data.Controller.DefaultQueuedConnects = channel.DefaultQueuedConnects - data.Controller.MinOutstandingConnects = channel.MinOutstandingConnects - data.Controller.MaxOutstandingConnects = channel.MaxOutstandingConnects - data.Controller.DefaultOutstandingConnects = channel.DefaultOutstandingConnects - data.Controller.MinConnectTimeout = channel.MinConnectTimeout - data.Controller.MaxConnectTimeout = channel.MaxConnectTimeout - data.Controller.DefaultConnectTimeout = channel.DefaultConnectTimeout - data.Controller.HealthCheck.Timeout = fabCtrl.DefaultHealthChecksBoltCheckTimeout - data.Controller.HealthCheck.Interval = fabCtrl.DefaultHealthChecksBoltCheckInterval - data.Controller.HealthCheck.InitialDelay = fabCtrl.DefaultHealthChecksBoltCheckInitialDelay - data.Controller.Edge.APIActivityUpdateBatchSize = edge.DefaultEdgeApiActivityUpdateBatchSize - data.Controller.Edge.APIActivityUpdateInterval = edge.DefaultEdgeAPIActivityUpdateInterval - data.Controller.Edge.APISessionTimeout = edge.DefaultEdgeSessionTimeout - data.Controller.WebListener.IdleTimeout = edge.DefaultHttpIdleTimeout - data.Controller.WebListener.ReadTimeout = edge.DefaultHttpReadTimeout - data.Controller.WebListener.WriteTimeout = edge.DefaultHttpWriteTimeout - data.Controller.WebListener.MinTLSVersion = fabXweb.ReverseTlsVersionMap[fabXweb.MinTLSVersion] - data.Controller.WebListener.MaxTLSVersion = fabXweb.ReverseTlsVersionMap[fabXweb.MaxTLSVersion] data.Router.Wss.WriteTimeout = foundation.DefaultWsWriteTimeout data.Router.Wss.ReadTimeout = foundation.DefaultWsReadTimeout data.Router.Wss.IdleTimeout = foundation.DefaultWsIdleTimeout diff --git a/ziti/cmd/create_config_controller.go b/ziti/cmd/create_config_controller.go index da4c7619f..04fb44b21 100644 --- a/ziti/cmd/create_config_controller.go +++ b/ziti/cmd/create_config_controller.go @@ -72,7 +72,6 @@ type CreateConfigControllerOptions struct { CreateConfigOptions CtrlPort string - MgmtListener string EdgeIdentityEnrollmentDuration time.Duration EdgeRouterEnrollmentDuration time.Duration } @@ -101,19 +100,18 @@ func NewCmdCreateConfigController() *cobra.Command { logrus.SetOutput(logOut) } - data.populateEnvVars() - data.populateDefaults() + data.populateConfigValues() // Update controller specific values with configOptions passed in if the argument was provided or the value is currently blank - if data.Controller.Port == "" || controllerOptions.CtrlPort != constants.DefaultZitiControllerPort { - data.Controller.Port = controllerOptions.CtrlPort + if data.Controller.Ctrl.ListenerPort == "" || controllerOptions.CtrlPort != constants.DefaultCtrlListenerPort { + data.Controller.Ctrl.ListenerPort = controllerOptions.CtrlPort } // Update with the passed in arg if it's not the default (CLI flag should override other methods of modifying these values) if controllerOptions.EdgeIdentityEnrollmentDuration != edge.DefaultEdgeEnrollmentDuration { - data.Controller.EdgeIdentityDuration = controllerOptions.EdgeIdentityEnrollmentDuration + data.Controller.EdgeEnrollment.EdgeIdentityDuration = controllerOptions.EdgeIdentityEnrollmentDuration } if controllerOptions.EdgeRouterEnrollmentDuration != edge.DefaultEdgeEnrollmentDuration { - data.Controller.EdgeRouterDuration = controllerOptions.EdgeRouterEnrollmentDuration + data.Controller.EdgeEnrollment.EdgeRouterDuration = controllerOptions.EdgeRouterEnrollmentDuration } // process identity information @@ -140,7 +138,7 @@ func NewCmdCreateConfigController() *cobra.Command { } func (options *CreateConfigControllerOptions) addFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&options.CtrlPort, optionCtrlPort, constants.DefaultZitiControllerPort, "port used for the router to controller communication") + cmd.Flags().StringVar(&options.CtrlPort, optionCtrlPort, constants.DefaultCtrlListenerPort, "port used for the router to controller communication") cmd.Flags().StringVar(&options.DatabaseFile, optionDatabaseFile, "ctrl.db", "location of the database file") cmd.Flags().DurationVar(&options.EdgeIdentityEnrollmentDuration, optionEdgeIdentityEnrollmentDuration, edge.DefaultEdgeEnrollmentDuration, "the edge identity enrollment duration, use 0h0m0s format") cmd.Flags().DurationVar(&options.EdgeRouterEnrollmentDuration, optionEdgeRouterEnrollmentDuration, edge.DefaultEdgeEnrollmentDuration, "the edge router enrollment duration, use 0h0m0s format") @@ -181,18 +179,6 @@ func (options *CreateConfigControllerOptions) run(data *ConfigTemplateValues) er return nil } -func hostnameOrNetworkName() string { - val := os.Getenv("ZITI_NETWORK_NAME") - if val == "" { - h, err := os.Hostname() - if err != nil { - return "localhost" - } - return h - } - return val -} - func SetControllerIdentity(data *ControllerTemplateValues) { SetControllerIdentityCert(data) SetControllerIdentityServerCert(data) @@ -200,32 +186,32 @@ func SetControllerIdentity(data *ControllerTemplateValues) { SetControllerIdentityCA(data) } func SetControllerIdentityCert(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiCtrlIdentityCertVarName) + val := os.Getenv(constants.PkiCtrlCertVarName) if val == "" { - val = workingDir + "/" + hostnameOrNetworkName() + ".cert" // default + val = workingDir + "/" + helpers2.HostnameOrNetworkName() + ".cert" // default } - c.IdentityCert = helpers2.NormalizePath(val) + c.Identity.Cert = helpers2.NormalizePath(val) } func SetControllerIdentityServerCert(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiCtrlIdentityServerCertVarName) + val := os.Getenv(constants.PkiCtrlServerCertVarName) if val == "" { - val = workingDir + "/" + hostnameOrNetworkName() + ".server.chain.cert" // default + val = workingDir + "/" + helpers2.HostnameOrNetworkName() + ".server.chain.cert" // default } - c.IdentityServerCert = helpers2.NormalizePath(val) + c.Identity.ServerCert = helpers2.NormalizePath(val) } func SetControllerIdentityKey(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiCtrlIdentityKeyVarName) + val := os.Getenv(constants.PkiCtrlKeyVarName) if val == "" { - val = workingDir + "/" + hostnameOrNetworkName() + ".key" // default + val = workingDir + "/" + helpers2.HostnameOrNetworkName() + ".key" // default } - c.IdentityKey = helpers2.NormalizePath(val) + c.Identity.Key = helpers2.NormalizePath(val) } func SetControllerIdentityCA(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiCtrlIdentityCAVarName) + val := os.Getenv(constants.PkiCtrlCAVarName) if val == "" { - val = workingDir + "/" + hostnameOrNetworkName() + ".ca" // default + val = workingDir + "/" + helpers2.HostnameOrNetworkName() + ".ca" // default } - c.IdentityCA = helpers2.NormalizePath(val) + c.Identity.Ca = helpers2.NormalizePath(val) } func SetEdgeConfig(data *ControllerTemplateValues) { @@ -233,18 +219,19 @@ func SetEdgeConfig(data *ControllerTemplateValues) { SetEdgeSigningKey(data) } func SetEdgeSigningCert(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiSigningCertVarName) + val := os.Getenv(constants.PkiSignerCertVarName) if val == "" { - val = workingDir + "/" + hostnameOrNetworkName() + ".signing.cert" // default + val = workingDir + "/" + helpers2.HostnameOrNetworkName() + ".signing.cert" // default } - c.Edge.ZitiSigningCert = helpers2.NormalizePath(val) + c.EdgeEnrollment.SigningCert = helpers2.NormalizePath(val) + } func SetEdgeSigningKey(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiSigningKeyVarName) + val := os.Getenv(constants.PkiSignerKeyVarName) if val == "" { - val = workingDir + "/" + hostnameOrNetworkName() + ".signing.key" // default + val = workingDir + "/" + helpers2.HostnameOrNetworkName() + ".signing.key" // default } - c.Edge.ZitiSigningKey = helpers2.NormalizePath(val) + c.EdgeEnrollment.SigningCertKey = helpers2.NormalizePath(val) } func SetWebConfig(data *ControllerTemplateValues) { @@ -254,30 +241,30 @@ func SetWebConfig(data *ControllerTemplateValues) { SetWebIdentityCA(data) } func SetWebIdentityCert(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiEdgeCtrlIdentityCertVarName) + val := os.Getenv(constants.CtrlPkiEdgeCertVarName) if val == "" { - val = c.IdentityCert //default + val = c.Identity.Cert //default } - c.Edge.IdentityCert = helpers2.NormalizePath(val) + c.Web.Identity.Cert = helpers2.NormalizePath(val) } func SetWebIdentityServerCert(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiEdgeCtrlIdentityServerCertVarName) + val := os.Getenv(constants.CtrlPkiEdgeServerCertVarName) if val == "" { - val = c.IdentityServerCert //default + val = c.Identity.ServerCert //default } - c.Edge.IdentityServerCert = helpers2.NormalizePath(val) + c.Web.Identity.ServerCert = helpers2.NormalizePath(val) } func SetWebIdentityKey(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiEdgeCtrlIdentityKeyVarName) + val := os.Getenv(constants.CtrlPkiEdgeKeyVarName) if val == "" { - val = c.IdentityKey //default + val = c.Identity.Key //default } - c.Edge.IdentityKey = helpers2.NormalizePath(val) + c.Web.Identity.Key = helpers2.NormalizePath(val) } func SetWebIdentityCA(c *ControllerTemplateValues) { - val := os.Getenv(constants.ZitiEdgeCtrlIdentityCAVarName) + val := os.Getenv(constants.CtrlPkiEdgeCAVarName) if val == "" { - val = c.IdentityCA //default + val = c.Identity.Ca //default } - c.Edge.IdentityCA = helpers2.NormalizePath(val) + c.Web.Identity.Ca = helpers2.NormalizePath(val) } diff --git a/ziti/cmd/create_config_controller_test.go b/ziti/cmd/create_config_controller_test.go index 491100b4c..94ac411ed 100644 --- a/ziti/cmd/create_config_controller_test.go +++ b/ziti/cmd/create_config_controller_test.go @@ -2,9 +2,11 @@ package cmd import ( "fmt" + cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" "os" + "strings" "testing" "time" ) @@ -16,27 +18,22 @@ type ControllerConfig struct { Db string `yaml:"db"` Identity Identity `yaml:"identity"` Ctrl Ctrl `yaml:"ctrl"` - Mgmt Mgmt `yaml:"mgmt"` HealthChecks HealthChecks `yaml:"healthChecks"` Edge Edge `yaml:"edge"` Web []Web `yaml:"web"` } type Identity struct { - Cert string `yaml:"cert"` - Server_cert string `yaml:"server_cert"` - Key string `yaml:"key"` - Ca string `yaml:"ca"` + Cert string `yaml:"cert"` + ServerCert string `yaml:"server_cert"` + Key string `yaml:"key"` + Ca string `yaml:"ca"` } type Ctrl struct { Listener string `yaml:"listener"` } -type Mgmt struct { - Listener string `yaml:"listener"` -} - type HealthChecks struct { BoltCheck BoltCheck `yaml:"boltCheck"` } @@ -108,6 +105,8 @@ type ApiOptions struct { /* END Controller config template structure */ +var controllerOptions = CreateConfigControllerOptions{} + func TestControllerOutputPathDoesNotExist(t *testing.T) { expectedErrorMsg := "stat /IDoNotExist: no such file or directory" @@ -121,16 +120,109 @@ func TestControllerOutputPathDoesNotExist(t *testing.T) { } func TestCreateConfigControllerTemplateValues(t *testing.T) { - expectedNonEmptyStringFields := []string{".Controller.Name", ".ZitiHome", ".Controller.IdentityCert", ".Controller.IdentityServerCert", ".Controller.IdentityKey", ".Controller.IdentityCA", ".Controller.ListenerAddress", ".Controller.Port", ".Controller.Edge.AdvertisedHostPort", ".Controller.Edge.ZitiSigningCert", ".Controller.Edge.ZitiSigningKey", ".Controller.Edge.ListenerHostPort", ".Controller.Edge.IdentityCA", ".Controller.Edge.IdentityKey", ".Controller.Edge.IdentityServerCert", ".Controller.Edge.IdentityCert", ".Controller.WebListener.MinTLSVersion", ".Controller.WebListener.MaxTLSVersion"} - expectedNonEmptyStringValues := []*string{&data.Controller.Name, &data.ZitiHome, &data.Controller.IdentityCert, &data.Controller.IdentityServerCert, &data.Controller.IdentityKey, &data.Controller.IdentityCA, &data.Controller.ListenerAddress, &data.Controller.Port, &data.Controller.Edge.AdvertisedHostPort, &data.Controller.Edge.ZitiSigningCert, &data.Controller.Edge.ZitiSigningKey, &data.Controller.Edge.ListenerHostPort, &data.Controller.Edge.IdentityCA, &data.Controller.Edge.IdentityKey, &data.Controller.Edge.IdentityServerCert, &data.Controller.Edge.IdentityCert, &data.Controller.WebListener.MinTLSVersion, &data.Controller.WebListener.MaxTLSVersion} - expectedNonEmptyTimeFields := []string{".Controller.HealthCheck.Interval", ".Controller.HealthCheck.Timeout", ".Controller.HealthCheck.InitialDelay", ".Controller.Edge.APISessionTimeout", ".Controller.EdgeIdentityDuration", ".Controller.EdgeRouterDuration", ".Controller.WebListener.IdleTimeout", ".Controller.WebListener.ReadTimeout", ".Controller.WebListener.WriteTimeout"} - expectedNonEmptyTimeValues := []*time.Duration{&data.Controller.HealthCheck.Interval, &data.Controller.HealthCheck.Timeout, &data.Controller.HealthCheck.InitialDelay, &data.Controller.Edge.APISessionTimeout, &data.Controller.EdgeIdentityDuration, &data.Controller.EdgeRouterDuration, &data.Controller.WebListener.IdleTimeout, &data.Controller.WebListener.ReadTimeout, &data.Controller.WebListener.WriteTimeout} // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - _ = captureOutput(func() { - _ = cmd.Execute() - }) + // This must run first, otherwise the addresses used later won't be correct; this command re-allocates the `data` struct + _ = execCreateConfigControllerCommand(nil, nil) + + expectedNonEmptyStringFields := []string{ + ".ZitiHome", + ".Controller.Identity.Cert", + ".Controller.Identity.ServerCert", + ".Controller.Identity.Key", + ".Controller.Identity.Ca", + ".Controller.Ctrl.ListenerAddress", + ".Controller.Ctrl.ListenerPort", + ".Controller.EdgeApi.Address", + ".Controller.EdgeApi.Port", + ".Controller.EdgeEnrollment.SigningCert", + ".Controller.EdgeEnrollment.SigningCertKey", + ".Controller.Web.BindPoints.InterfaceAddress", + ".Controller.Web.BindPoints.InterfacePort", + ".Controller.Web.BindPoints.AddressAddress", + ".Controller.Web.BindPoints.AddressPort", + ".Controller.Web.Identity.Ca", + ".Controller.Web.Identity.Key", + ".Controller.Web.Identity.ServerCert", + ".Controller.Web.Identity.Cert", + ".Controller.Web.Options.MinTLSVersion", + ".Controller.Web.Options.MaxTLSVersion", + } + expectedNonEmptyStringValues := []*string{ + &data.ZitiHome, + &data.Controller.Identity.Cert, + &data.Controller.Identity.ServerCert, + &data.Controller.Identity.Key, + &data.Controller.Identity.Ca, + &data.Controller.Ctrl.ListenerAddress, + &data.Controller.Ctrl.ListenerPort, + &data.Controller.EdgeApi.Address, + &data.Controller.EdgeApi.Port, + &data.Controller.EdgeEnrollment.SigningCert, + &data.Controller.EdgeEnrollment.SigningCertKey, + &data.Controller.Web.BindPoints.InterfaceAddress, + &data.Controller.Web.BindPoints.InterfacePort, + &data.Controller.Web.BindPoints.AddressAddress, + &data.Controller.Web.BindPoints.AddressPort, + &data.Controller.Web.Identity.Ca, + &data.Controller.Web.Identity.Key, + &data.Controller.Web.Identity.ServerCert, + &data.Controller.Web.Identity.Cert, + &data.Controller.Web.Options.MinTLSVersion, + &data.Controller.Web.Options.MaxTLSVersion, + } + + expectedNonZeroTimeFields := []string{ + ".Controller.Ctrl.MinConnectTimeout", + ".Controller.Ctrl.MaxConnectTimeout", + ".Controller.Ctrl.DefaultConnectTimeout", + ".Controller.HealthChecks.Interval", + ".Controller.HealthChecks.Timeout", + ".Controller.HealthChecks.InitialDelay", + ".Controller.EdgeApi.APIActivityUpdateInterval", + ".Controller.EdgeApi.SessionTimeout", + ".Controller.EdgeEnrollment.DefaultEdgeIdentityDuration", + ".Controller.EdgeEnrollment.EdgeIdentityDuration", + ".Controller.EdgeEnrollment.DefaultEdgeRouterDuration", + ".Controller.EdgeEnrollment.EdgeRouterDuration", + ".Controller.Web.Options.IdleTimeout", + ".Controller.Web.Options.ReadTimeout", + ".Controller.Web.Options.WriteTimeout", + } + + expectedNonZeroTimeValues := []*time.Duration{ + &data.Controller.Ctrl.MinConnectTimeout, + &data.Controller.Ctrl.MaxConnectTimeout, + &data.Controller.Ctrl.DefaultConnectTimeout, + &data.Controller.HealthChecks.Interval, + &data.Controller.HealthChecks.Timeout, + &data.Controller.HealthChecks.InitialDelay, + &data.Controller.EdgeApi.APIActivityUpdateInterval, + &data.Controller.EdgeApi.SessionTimeout, + &data.Controller.EdgeEnrollment.DefaultEdgeIdentityDuration, + &data.Controller.EdgeEnrollment.EdgeIdentityDuration, + &data.Controller.EdgeEnrollment.DefaultEdgeRouterDuration, + &data.Controller.EdgeEnrollment.EdgeRouterDuration, + &data.Controller.Web.Options.IdleTimeout, + &data.Controller.Web.Options.ReadTimeout, + &data.Controller.Web.Options.WriteTimeout, + } + + expectedNonZeroIntFields := []string{ + ".Controller.Ctrl.DefaultQueuedConnects", + ".Controller.Ctrl.MinOutstandingConnects", + ".Controller.Ctrl.MaxOutstandingConnects", + ".Controller.Ctrl.DefaultOutstandingConnects", + ".Controller.EdgeApi.APIActivityUpdateBatchSize", + } + + expectedNonZeroIntValues := []*int{ + &data.Controller.Ctrl.DefaultQueuedConnects, + &data.Controller.Ctrl.MinOutstandingConnects, + &data.Controller.Ctrl.MaxOutstandingConnects, + &data.Controller.Ctrl.DefaultOutstandingConnects, + &data.Controller.EdgeApi.APIActivityUpdateBatchSize, + } // Check that the expected string template values are not blank for field, value := range expectedNonEmptyStringValues { @@ -138,292 +230,599 @@ func TestCreateConfigControllerTemplateValues(t *testing.T) { } // Check that the expected time.Duration template values are not zero - for field, value := range expectedNonEmptyTimeValues { - assert.NotZero(t, *value, expectedNonEmptyTimeFields[field]+" should be a non-zero value") + for field, value := range expectedNonZeroTimeValues { + assert.NotZero(t, *value, expectedNonZeroTimeFields[field]+" should be a non-zero value") + } + + // Check that the expected integer template values are not zero + for field, value := range expectedNonZeroIntValues { + assert.NotZero(t, *value, expectedNonZeroIntFields[field]+" should be a non-zero value") } } -// Edge Ctrl Listener address and port should use default values if env vars are not set -func TestDefaultListenerAddress(t *testing.T) { - expectedListenerAddress := "0.0.0.0:1280" +func TestCtrlConfigDefaultsWhenUnset(t *testing.T) { + // Clears template data and unsets all env vars + clearControllerOptionsAndTemplateData() - // Make sure the related env vars are unset - _ = os.Unsetenv("ZITI_EDGE_CONTROLLER_PORT") - _ = os.Unsetenv("ZITI_CTRL_EDGE_LISTENER_HOST_PORT") + ctrlConfig := execCreateConfigControllerCommand(nil, nil) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - _ = captureOutput(func() { - _ = cmd.Execute() + // identity: + t.Run("TestPKICert", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".cert" + + assert.Equal(t, expectedValue, data.Controller.Identity.Cert) + assert.Equal(t, expectedValue, ctrlConfig.Identity.Cert) + }) + t.Run("TestPKIServerCert", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".server.chain.cert" + + assert.Equal(t, expectedValue, data.Controller.Identity.ServerCert) + assert.Equal(t, expectedValue, ctrlConfig.Identity.ServerCert) + }) + t.Run("TestPKIKey", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".key" + + assert.Equal(t, expectedValue, data.Controller.Identity.Key) + assert.Equal(t, expectedValue, ctrlConfig.Identity.Key) + }) + t.Run("TestPKICA", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".ca" + + assert.Equal(t, expectedValue, data.Controller.Identity.Ca) + assert.Equal(t, expectedValue, ctrlConfig.Identity.Ca) }) - assert.Equal(t, expectedListenerAddress, data.Controller.Edge.ListenerHostPort) + // ctrl: + t.Run("TestListenerAddress", func(t *testing.T) { + expectedValue := testDefaultCtrlListenerAddress + + assert.Equal(t, expectedValue, data.Controller.Ctrl.ListenerAddress) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Ctrl.Listener, ":")[1]) + }) + t.Run("TestListenerPort", func(t *testing.T) { + expectedValue := testDefaultCtrlListenerPort + + assert.Equal(t, expectedValue, data.Controller.Ctrl.ListenerPort) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Ctrl.Listener, ":")[2]) + }) + + // healthChecks: + t.Run("TestBoltCheckInterval", func(t *testing.T) { + expectedValue := testDefaultBoltCheckInterval + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.HealthChecks.Interval.Seconds(), "s")) + assert.Equal(t, expectedValue, ctrlConfig.HealthChecks.BoltCheck.Interval) + }) + t.Run("TestBoltCheckTimeout", func(t *testing.T) { + expectedValue := testDefaultBoltCheckTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.HealthChecks.Timeout.Seconds(), "s")) + assert.Equal(t, expectedValue, ctrlConfig.HealthChecks.BoltCheck.Timeout) + }) + t.Run("TestBoltCheckInitialDelay", func(t *testing.T) { + expectedValue := testDefaultBoltCheckInitialDelay + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.HealthChecks.InitialDelay.Seconds(), "s")) + assert.Equal(t, expectedValue, ctrlConfig.HealthChecks.BoltCheck.InitialDelay) + }) + + // edge + t.Run("TestEdgeAPIAddress", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Address + expectedValue := data.Controller.Web.BindPoints.AddressAddress + + assert.Equal(t, expectedValue, data.Controller.EdgeApi.Address) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Edge.Api.Address, ":")[0]) + }) + t.Run("TestEdgeAPIPort", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := data.Controller.Web.BindPoints.AddressPort + + assert.Equal(t, expectedValue, data.Controller.EdgeApi.Port) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Edge.Api.Address, ":")[1]) + }) + t.Run("TestEdgeEnrollmentSigningCert", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".signing.cert" + + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.SigningCert) + assert.Equal(t, expectedValue, ctrlConfig.Edge.Enrollment.SigningCert.Cert) + }) + t.Run("TestEdgeEnrollmentSigningKey", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".signing.key" + + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.SigningCertKey) + assert.Equal(t, expectedValue, ctrlConfig.Edge.Enrollment.SigningCert.Key) + }) + + // web:bindPoints + t.Run("TestEdgeBindpointInterfaceAddress", func(t *testing.T) { + // Should default to the value of Ctrl Listener Address + expectedValue := data.Controller.Ctrl.ListenerAddress + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.InterfaceAddress) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].BpInterface, ":")[0]) + }) + t.Run("TestEdgeBindpointInterfacePort", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := data.Controller.Web.BindPoints.AddressPort + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.InterfacePort) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].BpInterface, ":")[1]) + }) + t.Run("TestEdgeAdvertisedAddress", func(t *testing.T) { + // Should default to hostname + expectedValue, _ := os.Hostname() + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.AddressAddress) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[0]) + }) + t.Run("TestEdgeAdvertisedPort", func(t *testing.T) { + // Should default to the Const value + expectedValue := testDefaultCtrlEdgeAdvertisedPort + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.AddressPort) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[1]) + }) + t.Run("TestEdgeIdentityEnrollmentDuration", func(t *testing.T) { + assert.Equal(t, testDefaultEdgeIdentityEnrollmentDuration, data.Controller.EdgeEnrollment.EdgeIdentityDuration) + assert.Equal(t, testDefaultEdgeIdentityEnrollmentStr, ctrlConfig.Edge.Enrollment.EdgeIdentity.Duration) + }) + t.Run("TestEdgeRouterEnrollmentDuration", func(t *testing.T) { + assert.Equal(t, testDefaultEdgeRouterEnrollmentDuration, data.Controller.EdgeEnrollment.EdgeRouterDuration) + assert.Equal(t, testDefaultEdgeRouterEnrollmentStr, ctrlConfig.Edge.Enrollment.EdgeRouter.Duration) + }) + + // web:identity + t.Run("TestEdgePKICert", func(t *testing.T) { + // Defaults to the Controller identity ca + expectedValue := data.Controller.Identity.Ca + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.Ca) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.Ca) + }) + t.Run("TestEdgePKIServerCert", func(t *testing.T) { + // Defaults to the Controller identity key + expectedValue := data.Controller.Identity.Key + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.Key) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.Key) + }) + t.Run("TestEdgePKIKey", func(t *testing.T) { + // Defaults to the Controller identity server cert + expectedValue := data.Controller.Identity.ServerCert + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.ServerCert) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.ServerCert) + }) + t.Run("TestEdgePKICA", func(t *testing.T) { + // Defaults to the Controller identity cert + expectedValue := data.Controller.Identity.Cert + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.Cert) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.Cert) + }) + + // web:options + t.Run("TestEdgeOptionsIdleTimeout", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsIdleTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.Web.Options.IdleTimeout.Milliseconds(), "ms")) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.IdleTimeout) + }) + t.Run("TestEdgeOptionsReadTimeout", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsReadTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.Web.Options.ReadTimeout.Milliseconds(), "ms")) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.ReadTimeout) + }) + t.Run("TestEdgeOptionsWriteTimeout", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsWriteTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.Web.Options.WriteTimeout.Milliseconds(), "ms")) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.WriteTimeout) + }) + t.Run("TestEdgeOptionsMinTLS", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsMinTLSVersion + + assert.Equal(t, expectedValue, data.Controller.Web.Options.MinTLSVersion) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.MinTLSVersion) + }) + t.Run("TestEdgeOptionsMaxTLS", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsMaxTLSVersion + + assert.Equal(t, expectedValue, data.Controller.Web.Options.MaxTLSVersion) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.MaxTLSVersion) + }) } -// Edge Ctrl Listener port should use ZITI_EDGE_CONTROLLER_PORT if it is set -func TestListenerAddressWhenEdgeCtrlPortAndListenerHostPortNotSet(t *testing.T) { - myPort := "1234" - expectedListenerAddress := "0.0.0.0:" + myPort +func TestCtrlConfigDefaultsWhenBlank(t *testing.T) { + keys := map[string]string{ + "ZITI_PKI_CTRL_CERT": "", + "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS": "", + "ZITI_HOME": "", + } + // run the config + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Make sure the related env vars are unset - _ = os.Unsetenv("ZITI_CTRL_EDGE_LISTENER_HOST_PORT") + // identity: + t.Run("TestPKICert", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".cert" - // Set the edge controller port - _ = os.Setenv("ZITI_EDGE_CONTROLLER_PORT", myPort) + assert.Equal(t, expectedValue, data.Controller.Identity.Cert) + assert.Equal(t, expectedValue, ctrlConfig.Identity.Cert) + }) + t.Run("TestPKIServerCert", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".server.chain.cert" - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - _ = captureOutput(func() { - _ = cmd.Execute() + assert.Equal(t, expectedValue, data.Controller.Identity.ServerCert) + assert.Equal(t, expectedValue, ctrlConfig.Identity.ServerCert) + }) + t.Run("TestPKIKey", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".key" + + assert.Equal(t, expectedValue, data.Controller.Identity.Key) + assert.Equal(t, expectedValue, ctrlConfig.Identity.Key) + }) + t.Run("TestPKICA", func(t *testing.T) { + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".ca" + + assert.Equal(t, expectedValue, data.Controller.Identity.Ca) + assert.Equal(t, expectedValue, ctrlConfig.Identity.Ca) }) - assert.Equal(t, expectedListenerAddress, data.Controller.Edge.ListenerHostPort) + // ctrl: + t.Run("TestListenerAddress", func(t *testing.T) { + expectedValue := testDefaultCtrlListenerAddress + + assert.Equal(t, expectedValue, data.Controller.Ctrl.ListenerAddress) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Ctrl.Listener, ":")[1]) + }) + t.Run("TestListenerPort", func(t *testing.T) { + expectedValue := testDefaultCtrlListenerPort + + assert.Equal(t, expectedValue, data.Controller.Ctrl.ListenerPort) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Ctrl.Listener, ":")[2]) + }) + + // healthChecks: + t.Run("TestBoltCheckInterval", func(t *testing.T) { + expectedValue := testDefaultBoltCheckInterval + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.HealthChecks.Interval.Seconds(), "s")) + assert.Equal(t, expectedValue, ctrlConfig.HealthChecks.BoltCheck.Interval) + }) + t.Run("TestBoltCheckTimeout", func(t *testing.T) { + expectedValue := testDefaultBoltCheckTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.HealthChecks.Timeout.Seconds(), "s")) + assert.Equal(t, expectedValue, ctrlConfig.HealthChecks.BoltCheck.Timeout) + }) + t.Run("TestBoltCheckInitialDelay", func(t *testing.T) { + expectedValue := testDefaultBoltCheckInitialDelay + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.HealthChecks.InitialDelay.Seconds(), "s")) + assert.Equal(t, expectedValue, ctrlConfig.HealthChecks.BoltCheck.InitialDelay) + }) + + // edge + t.Run("TestEdgeAPIAddress", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Address + expectedValue := data.Controller.Web.BindPoints.AddressAddress + + assert.Equal(t, expectedValue, data.Controller.EdgeApi.Address) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Edge.Api.Address, ":")[0]) + }) + t.Run("TestEdgeAPIPort", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := data.Controller.Web.BindPoints.AddressPort + + assert.Equal(t, expectedValue, data.Controller.EdgeApi.Port) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Edge.Api.Address, ":")[1]) + }) + t.Run("TestEdgeEnrollmentSigningCert", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".signing.cert" + + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.SigningCert) + assert.Equal(t, expectedValue, ctrlConfig.Edge.Enrollment.SigningCert.Cert) + }) + t.Run("TestEdgeEnrollmentSigningKey", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := workingDir + "/" + cmdhelper.HostnameOrNetworkName() + ".signing.key" + + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.SigningCertKey) + assert.Equal(t, expectedValue, ctrlConfig.Edge.Enrollment.SigningCert.Key) + }) + t.Run("TestEdgeIdentityEnrollmentDuration", func(t *testing.T) { + assert.Equal(t, testDefaultEdgeIdentityEnrollmentDuration, data.Controller.EdgeEnrollment.EdgeIdentityDuration) + assert.Equal(t, testDefaultEdgeIdentityEnrollmentStr, ctrlConfig.Edge.Enrollment.EdgeIdentity.Duration) + }) + t.Run("TestEdgeRouterEnrollmentDuration", func(t *testing.T) { + assert.Equal(t, testDefaultEdgeRouterEnrollmentDuration, data.Controller.EdgeEnrollment.EdgeRouterDuration) + assert.Equal(t, testDefaultEdgeRouterEnrollmentStr, ctrlConfig.Edge.Enrollment.EdgeRouter.Duration) + }) + + // web:bindPoints + t.Run("TestEdgeBindpointInterfaceAddress", func(t *testing.T) { + // Should default to the value of Ctrl Listener Address + expectedValue := data.Controller.Ctrl.ListenerAddress + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.InterfaceAddress) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].BpInterface, ":")[0]) + }) + t.Run("TestEdgeBindpointInterfacePort", func(t *testing.T) { + // Should default to the value of Ctrl Edge Advertised Port + expectedValue := data.Controller.Web.BindPoints.AddressPort + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.InterfacePort) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].BpInterface, ":")[1]) + }) + t.Run("TestEdgeAdvertisedAddress", func(t *testing.T) { + // Should default to hostname + expectedValue, _ := os.Hostname() + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.AddressAddress) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[0]) + }) + t.Run("TestEdgeAdvertisedPort", func(t *testing.T) { + // Should default to the Const value + expectedValue := testDefaultCtrlEdgeAdvertisedPort + + assert.Equal(t, expectedValue, data.Controller.Web.BindPoints.AddressPort) + assert.Equal(t, expectedValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[1]) + }) + + // web:identity + t.Run("TestEdgePKICert", func(t *testing.T) { + // Defaults to the Controller identity ca + expectedValue := data.Controller.Identity.Ca + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.Ca) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.Ca) + }) + t.Run("TestEdgePKIServerCert", func(t *testing.T) { + // Defaults to the Controller identity key + expectedValue := data.Controller.Identity.Key + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.Key) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.Key) + }) + t.Run("TestEdgePKIKey", func(t *testing.T) { + // Defaults to the Controller identity server cert + expectedValue := data.Controller.Identity.ServerCert + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.ServerCert) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.ServerCert) + }) + t.Run("TestEdgePKICA", func(t *testing.T) { + // Defaults to the Controller identity cert + expectedValue := data.Controller.Identity.Cert + + assert.Equal(t, expectedValue, data.Controller.Web.Identity.Cert) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Identity.Cert) + }) + + // web:options + t.Run("TestEdgeOptionsIdleTimeout", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsIdleTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.Web.Options.IdleTimeout.Milliseconds(), "ms")) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.IdleTimeout) + }) + t.Run("TestEdgeOptionsReadTimeout", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsReadTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.Web.Options.ReadTimeout.Milliseconds(), "ms")) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.ReadTimeout) + }) + t.Run("TestEdgeOptionsWriteTimeout", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsWriteTimeout + + assert.Equal(t, expectedValue, fmt.Sprint(data.Controller.Web.Options.WriteTimeout.Milliseconds(), "ms")) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.WriteTimeout) + }) + t.Run("TestEdgeOptionsMinTLS", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsMinTLSVersion + + assert.Equal(t, expectedValue, data.Controller.Web.Options.MinTLSVersion) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.MinTLSVersion) + }) + t.Run("TestEdgeOptionsMaxTLS", func(t *testing.T) { + expectedValue := testDefaultEdgeOptionsMaxTLSVersion + + assert.Equal(t, expectedValue, data.Controller.Web.Options.MaxTLSVersion) + assert.Equal(t, expectedValue, ctrlConfig.Web[0].Options.MaxTLSVersion) + }) } -// Edge Ctrl Listener address and port should always use ZITI_EDGE_CTRL_LISTENER_HOST_PORT value if it is set -func TestListenerAddressWhenEdgeCtrlPortAndListenerHostPortSet(t *testing.T) { - myPort := "1234" - expectedListenerAddress := "0.0.0.0:4321" // Expecting a different port even when edge ctrl port is set +func TestZitiCtrlIdentitySection(t *testing.T) { + certPath := "/var/test/custom/path/file.cert" + serverCertPath := "/var/test/custom/path/file.chain.pem" + keyPath := "/var/test/custom/path/file.key" + caPath := "/var/test/custom/path/file.pem" + keys := map[string]string{ + "ZITI_PKI_CTRL_CERT": certPath, + "ZITI_PKI_CTRL_SERVER_CERT": serverCertPath, + "ZITI_PKI_CTRL_KEY": keyPath, + "ZITI_PKI_CTRL_CA": caPath, + } - // Set a custom value for the host and port - _ = os.Setenv("ZITI_CTRL_EDGE_LISTENER_HOST_PORT", expectedListenerAddress) + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Set the edge controller port (this should not show up in the end resulting listener address) - _ = os.Setenv("ZITI_EDGE_CONTROLLER_PORT", myPort) - - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - _ = captureOutput(func() { - _ = cmd.Execute() - }) - - assert.Equal(t, expectedListenerAddress, data.Controller.Edge.ListenerHostPort) + assert.Equal(t, certPath, data.Controller.Identity.Cert) + assert.Equal(t, certPath, ctrlConfig.Identity.Cert) + assert.Equal(t, serverCertPath, data.Controller.Identity.ServerCert) + assert.Equal(t, serverCertPath, ctrlConfig.Identity.ServerCert) + assert.Equal(t, keyPath, data.Controller.Identity.Key) + assert.Equal(t, keyPath, ctrlConfig.Identity.Key) + assert.Equal(t, caPath, data.Controller.Identity.Ca) + assert.Equal(t, caPath, ctrlConfig.Identity.Ca) } -// Edge Ctrl Advertised Port should update the edge ctrl port to the default when ZITI_EDGE_CONTROLLER_PORT is not set -func TestDefaultEdgeCtrlAdvertisedPort(t *testing.T) { - expectedPort := "1280" // Expecting the default port of 1280 +func TestCtrlListenerAddress(t *testing.T) { + customValue := "123.456.7.8" + keys := map[string]string{ + "ZITI_CTRL_LISTENER_ADDRESS": customValue, + } - // Set a custom value for the host and port - _ = os.Unsetenv("ZITI_EDGE_CONTROLLER_PORT") + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - _ = captureOutput(func() { - _ = cmd.Execute() - }) - - assert.Equal(t, expectedPort, data.Controller.Edge.AdvertisedPort) + assert.Equal(t, customValue, data.Controller.Ctrl.ListenerAddress) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Ctrl.Listener, ":")[1]) } -// Edge Ctrl Advertised Port should update the edge ctrl port to the custom value when ZITI_EDGE_CONTROLLER_PORT is set -func TestEdgeCtrlAdvertisedPortValueWhenSet(t *testing.T) { - expectedPort := "1234" // Setting a custom port which is not the default value +func TestCtrlListenerPort(t *testing.T) { + customValue := "9999" + keys := map[string]string{ + "ZITI_CTRL_LISTENER_PORT": customValue, + } - // Set a custom value for the host and port - _ = os.Setenv("ZITI_EDGE_CONTROLLER_PORT", expectedPort) + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - _ = captureOutput(func() { - _ = cmd.Execute() - }) - - assert.Equal(t, expectedPort, data.Controller.Edge.AdvertisedPort) + assert.Equal(t, customValue, data.Controller.Ctrl.ListenerPort) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Ctrl.Listener, ":")[2]) } -func TestDefaultEdgeIdentityEnrollmentDuration(t *testing.T) { - // Expect the default (3 hours) - expectedDuration := time.Duration(180) * time.Minute - expectedConfigValue := "180m" +func TestCtrlEdgeAPIAddress(t *testing.T) { + customValue := "123.456.7.8" + keys := map[string]string{ + "ZITI_CTRL_EDGE_API_ADDRESS": customValue, + } - // Unset the env var so the default is used - _ = os.Unsetenv("ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION") + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) + assert.Equal(t, customValue, data.Controller.EdgeApi.Address) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Edge.Api.Address, ":")[0]) - assert.Equal(t, expectedDuration, data.Controller.EdgeIdentityDuration) - - // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeIdentity.Duration) + // Ensure that the web listener was also set to this value (web listener must match the edge API address) + assert.Equal(t, customValue, data.Controller.Web.BindPoints.AddressAddress) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[0]) } -func TestEdgeIdentityEnrollmentDurationWhenEnvVarSet(t *testing.T) { - expectedDuration := 5 * time.Minute // Setting a custom duration which is not the default value - expectedConfigValue := "5m" +func TestCtrlEdgeAPIPort(t *testing.T) { + customValue := "9999" + keys := map[string]string{ + "ZITI_CTRL_EDGE_API_PORT": customValue, + } - // Set a custom value for the enrollment duration - _ = os.Setenv("ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION", fmt.Sprintf("%.0f", expectedDuration.Minutes())) + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) - - assert.Equal(t, expectedDuration, data.Controller.EdgeIdentityDuration) - - // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeIdentity.Duration) + assert.Equal(t, customValue, data.Controller.EdgeApi.Port) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Edge.Api.Address, ":")[1]) } -func TestEdgeIdentityEnrollmentDurationWhenEnvVarSetToBlank(t *testing.T) { - // Expect the default (3 hours) - expectedDuration := time.Duration(180) * time.Minute - expectedConfigValue := "180m" +func TestCtrlEdgeAPIEnrollmentSignerCert(t *testing.T) { + certPath := "/var/test/custom/path/file.cert" + keyPath := "/var/test/custom/path/file.key" + keys := map[string]string{ + "ZITI_PKI_SIGNER_CERT": certPath, + "ZITI_PKI_SIGNER_KEY": keyPath, + } - // Set a custom value for the enrollment duration - _ = os.Setenv("ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION", "") + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) + assert.Equal(t, certPath, data.Controller.EdgeEnrollment.SigningCert) + assert.Equal(t, certPath, ctrlConfig.Edge.Enrollment.SigningCert.Cert) + assert.Equal(t, keyPath, data.Controller.EdgeEnrollment.SigningCertKey) + assert.Equal(t, keyPath, ctrlConfig.Edge.Enrollment.SigningCert.Key) +} - assert.Equal(t, expectedDuration, data.Controller.EdgeIdentityDuration) +func TestEdgeIdentityEnrollmentDurationEnvVar(t *testing.T) { + customDuration := time.Duration(5) * time.Minute + customValue := "5" + expectedValue := customValue + "m" // Env Var int is converted to minutes format + keys := map[string]string{ + "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION": customValue, + } - // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeIdentity.Duration) + ctrlConfig := execCreateConfigControllerCommand(nil, keys) + + assert.Equal(t, customDuration, data.Controller.EdgeEnrollment.EdgeIdentityDuration) + assert.Equal(t, expectedValue, ctrlConfig.Edge.Enrollment.EdgeIdentity.Duration) } func TestEdgeIdentityEnrollmentDurationCLITakesPriority(t *testing.T) { - envVarValue := 5 * time.Minute // Setting a custom duration which is not the default value - cliValue := "10m" // Setting a CLI custom duration which is also not the default value - expectedConfigValue := "10m" + envVarValue := "5" // Setting a custom duration which is not the default value + cliValue := "10m" // Setting a CLI custom duration which is also not the default value + expectedConfigValue := cliValue + keys := map[string]string{ + "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION": envVarValue, + } + args := []string{"--identityEnrollmentDuration", cliValue} - // Set a custom value for the enrollment duration - _ = os.Setenv("ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION", fmt.Sprintf("%.0f", envVarValue.Minutes())) - - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - cmd.SetArgs([]string{"--identityEnrollmentDuration", cliValue}) - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) + ctrlConfig := execCreateConfigControllerCommand(args, keys) // Expect that the CLI value was used over the environment variable expectedValue, _ := time.ParseDuration(cliValue) - assert.Equal(t, expectedValue, data.Controller.EdgeIdentityDuration) + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.EdgeIdentityDuration) // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeIdentity.Duration) + assert.Equal(t, expectedConfigValue, ctrlConfig.Edge.Enrollment.EdgeIdentity.Duration) } -func TestDefaultEdgeRouterEnrollmentDuration(t *testing.T) { - expectedDuration := time.Duration(180) * time.Minute - expectedConfigValue := "180m" +func TestEdgeIdentityEnrollmentDurationCLIConvertsToMin(t *testing.T) { + cliValue := "1h" // Setting a CLI custom duration which is also not the default value + expectedConfigValue := "60m" // Config value representation should be in minutes - // Unset the env var so the default is used - _ = os.Unsetenv("ZITI_EDGE_ROUTER_ENROLLMENT_DURATION") + args := []string{"--identityEnrollmentDuration", cliValue} + ctrlConfig := execCreateConfigControllerCommand(args, nil) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) - - assert.Equal(t, expectedDuration, data.Controller.EdgeRouterDuration) + // Expect that the CLI value was used over the environment variable + expectedValue, _ := time.ParseDuration(cliValue) + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.EdgeIdentityDuration) // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeRouter.Duration) + assert.Equal(t, expectedConfigValue, ctrlConfig.Edge.Enrollment.EdgeIdentity.Duration) } -func TestEdgeRouterEnrollmentDurationWhenEnvVarSet(t *testing.T) { - expectedDuration := 5 * time.Minute // Setting a custom duration which is not the default value - expectedConfigValue := "5m" +func TestEdgeRouterEnrollmentDurationEnvVar(t *testing.T) { + customDuration := time.Duration(5) * time.Minute + customValue := "5" + expectedValue := customValue + "m" // Env Var int is converted to minutes format + keys := map[string]string{ + "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION": customValue, + } - // Set a custom value for the enrollment duration - _ = os.Setenv("ZITI_EDGE_ROUTER_ENROLLMENT_DURATION", fmt.Sprintf("%.0f", expectedDuration.Minutes())) + ctrlConfig := execCreateConfigControllerCommand(nil, keys) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) - - assert.Equal(t, expectedDuration, data.Controller.EdgeRouterDuration) - - // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeRouter.Duration) -} - -func TestEdgeRouterEnrollmentDurationWhenEnvVarSetToBlank(t *testing.T) { - // Expect the default (3 hours) - expectedDuration := time.Duration(180) * time.Minute - expectedConfigValue := "180m" - - // Set a custom value for the enrollment duration - _ = os.Setenv("ZITI_EDGE_ROUTER_ENROLLMENT_DURATION", "") - - // Create and run the CLI command - cmd := NewCmdCreateConfigController() - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) - - assert.Equal(t, expectedDuration, data.Controller.EdgeRouterDuration) - - // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeRouter.Duration) + assert.Equal(t, customDuration, data.Controller.EdgeEnrollment.EdgeRouterDuration) + assert.Equal(t, expectedValue, ctrlConfig.Edge.Enrollment.EdgeRouter.Duration) } func TestEdgeRouterEnrollmentDurationCLITakesPriority(t *testing.T) { - envVarValue := 5 * time.Minute // Setting a custom duration which is not the default value - cliValue := "10m" // Setting a CLI custom duration which is also not the default value - expectedConfigValue := "10m" // Config value representation should be in minutes + envVarValue := "5" // Setting a custom duration which is not the default value + cliValue := "10m" // Setting a CLI custom duration which is also not the default value + expectedConfigValue := cliValue + keys := map[string]string{ + "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION": envVarValue, + } + args := []string{"--routerEnrollmentDuration", cliValue} - // Set a custom value for the enrollment duration - _ = os.Setenv("ZITI_EDGE_ROUTER_ENROLLMENT_DURATION", fmt.Sprintf("%.0f", envVarValue.Minutes())) - - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigController() - cmd.SetArgs([]string{"--routerEnrollmentDuration", cliValue}) - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) + ctrlConfig := execCreateConfigControllerCommand(args, keys) // Expect that the CLI value was used over the environment variable expectedValue, _ := time.ParseDuration(cliValue) - assert.Equal(t, expectedValue, data.Controller.EdgeRouterDuration) + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.EdgeRouterDuration) // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeRouter.Duration) + assert.Equal(t, expectedConfigValue, ctrlConfig.Edge.Enrollment.EdgeRouter.Duration) } func TestEdgeRouterEnrollmentDurationCLIConvertsToMin(t *testing.T) { cliValue := "1h" // Setting a CLI custom duration which is also not the default value expectedConfigValue := "60m" // Config value representation should be in minutes - // Make sure the env var is not set - _ = os.Unsetenv("ZITI_EDGE_ROUTER_ENROLLMENT_DURATION") - - // Create and run the CLI command - cmd := NewCmdCreateConfigController() - cmd.SetArgs([]string{"--routerEnrollmentDuration", cliValue}) - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) + args := []string{"--routerEnrollmentDuration", cliValue} + ctrlConfig := execCreateConfigControllerCommand(args, nil) // Expect that the CLI value was used over the environment variable expectedValue, _ := time.ParseDuration(cliValue) - assert.Equal(t, expectedValue, data.Controller.EdgeRouterDuration) + assert.Equal(t, expectedValue, data.Controller.EdgeEnrollment.EdgeRouterDuration) // Expect that the config value is represented correctly - configStruct := configToStruct(configOutput) - assert.Equal(t, expectedConfigValue, configStruct.Edge.Enrollment.EdgeRouter.Duration) + assert.Equal(t, expectedConfigValue, ctrlConfig.Edge.Enrollment.EdgeRouter.Duration) } func TestEdgeRouterAndIdentityEnrollmentDurationTogetherCLI(t *testing.T) { @@ -432,19 +831,11 @@ func TestEdgeRouterAndIdentityEnrollmentDurationTogetherCLI(t *testing.T) { expectedIdentityConfigValue := "60m" expectedRouterConfigValue := "30m" - // Make sure the env vars are not set - _ = os.Unsetenv("ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION") - _ = os.Unsetenv("ZITI_EDGE_ROUTER_ENROLLMENT_DURATION") - // Create and run the CLI command - cmd := NewCmdCreateConfigController() - cmd.SetArgs([]string{"--routerEnrollmentDuration", cliRouterDurationValue, "--identityEnrollmentDuration", cliIdentityDurationValue}) - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) + args := []string{"--routerEnrollmentDuration", cliRouterDurationValue, "--identityEnrollmentDuration", cliIdentityDurationValue} + configStruct := execCreateConfigControllerCommand(args, nil) // Expect that the config values are represented correctly - configStruct := configToStruct(configOutput) assert.Equal(t, expectedIdentityConfigValue, configStruct.Edge.Enrollment.EdgeIdentity.Duration) assert.Equal(t, expectedRouterConfigValue, configStruct.Edge.Enrollment.EdgeRouter.Duration) } @@ -452,25 +843,100 @@ func TestEdgeRouterAndIdentityEnrollmentDurationTogetherCLI(t *testing.T) { func TestEdgeRouterAndIdentityEnrollmentDurationTogetherEnvVar(t *testing.T) { envVarIdentityDurationValue := "120" envVarRouterDurationValue := "60" - expectedIdentityConfigValue := "120m" - expectedRouterConfigValue := "60m" - - // Set the env vars - _ = os.Setenv("ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION", envVarIdentityDurationValue) - _ = os.Setenv("ZITI_EDGE_ROUTER_ENROLLMENT_DURATION", envVarRouterDurationValue) + expectedIdentityConfigValue := envVarIdentityDurationValue + "m" + expectedRouterConfigValue := envVarRouterDurationValue + "m" // Create and run the CLI command - cmd := NewCmdCreateConfigController() - configOutput := captureOutput(func() { - _ = cmd.Execute() - }) + keys := map[string]string{ + "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION": envVarIdentityDurationValue, + "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION": envVarRouterDurationValue, + } + configStruct := execCreateConfigControllerCommand(nil, keys) // Expect that the config values are represented correctly - configStruct := configToStruct(configOutput) assert.Equal(t, expectedIdentityConfigValue, configStruct.Edge.Enrollment.EdgeIdentity.Duration) assert.Equal(t, expectedRouterConfigValue, configStruct.Edge.Enrollment.EdgeRouter.Duration) } +func TestCtrlEdgeInterfaceAddress(t *testing.T) { + customValue := "123.456.7.8" + keys := map[string]string{ + "ZITI_CTRL_EDGE_INTERFACE_ADDRESS": customValue, + } + + ctrlConfig := execCreateConfigControllerCommand(nil, keys) + + assert.Equal(t, customValue, data.Controller.Web.BindPoints.InterfaceAddress) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].BpInterface, ":")[0]) +} + +func TestCtrlEdgeInterfacePort(t *testing.T) { + customValue := "9999" + keys := map[string]string{ + "ZITI_CTRL_EDGE_INTERFACE_PORT": customValue, + } + + ctrlConfig := execCreateConfigControllerCommand(nil, keys) + + assert.Equal(t, customValue, data.Controller.Web.BindPoints.InterfacePort) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].BpInterface, ":")[1]) +} + +func TestCtrlEdgeAdvertisedAddress(t *testing.T) { + customValue := "123.456.7.8" + keys := map[string]string{ + "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS": customValue, + } + + ctrlConfig := execCreateConfigControllerCommand(nil, keys) + + assert.Equal(t, customValue, data.Controller.Web.BindPoints.AddressAddress) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[0]) +} + +func TestCtrlEdgeAdvertisedPort(t *testing.T) { + customValue := "9999" + keys := map[string]string{ + "ZITI_CTRL_EDGE_ADVERTISED_PORT": customValue, + } + + ctrlConfig := execCreateConfigControllerCommand(nil, keys) + + assert.Equal(t, customValue, data.Controller.Web.BindPoints.AddressPort) + assert.Equal(t, customValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[1]) +} + +func TestCtrlEdgeIdentitySection(t *testing.T) { + caPath := "/var/test/custom/path/file.pem" + keyPath := "/var/test/custom/path/file.key" + serverCertPath := "/var/test/custom/path/file.chain.pem" + certPath := "/var/test/custom/path/file.cert" + keys := map[string]string{ + "ZITI_PKI_CTRL_CA": caPath, + "ZITI_PKI_CTRL_KEY": keyPath, + "ZITI_PKI_CTRL_SERVER_CERT": serverCertPath, + "ZITI_PKI_CTRL_CERT": certPath, + } + + ctrlConfig := execCreateConfigControllerCommand(nil, keys) + + assert.Equal(t, certPath, data.Controller.Web.Identity.Cert) + assert.Equal(t, certPath, ctrlConfig.Web[0].Identity.Cert) + assert.Equal(t, serverCertPath, data.Controller.Web.Identity.ServerCert) + assert.Equal(t, serverCertPath, ctrlConfig.Web[0].Identity.ServerCert) + assert.Equal(t, keyPath, data.Controller.Web.Identity.Key) + assert.Equal(t, keyPath, ctrlConfig.Web[0].Identity.Key) + assert.Equal(t, caPath, data.Controller.Web.Identity.Ca) + assert.Equal(t, caPath, ctrlConfig.Web[0].Identity.Ca) +} + +func clearControllerOptionsAndTemplateData() { + controllerOptions = CreateConfigControllerOptions{} + data = &ConfigTemplateValues{} + + unsetZitiEnv() +} + func configToStruct(config string) ControllerConfig { configStruct := ControllerConfig{} err2 := yaml.Unmarshal([]byte(config), &configStruct) @@ -479,3 +945,19 @@ func configToStruct(config string) ControllerConfig { } return configStruct } + +func execCreateConfigControllerCommand(args []string, keys map[string]string) ControllerConfig { + // Setup + clearControllerOptionsAndTemplateData() + controllerOptions.Output = defaultOutput + + setEnvByMap(keys) + // Create and run the CLI command (capture output to convert to a template struct) + cmd := NewCmdCreateConfigController() + cmd.SetArgs(args) + configOutput := captureOutput(func() { + _ = cmd.Execute() + }) + + return configToStruct(configOutput) +} diff --git a/ziti/cmd/create_config_environment.go b/ziti/cmd/create_config_environment.go index 9c25baef6..87a5e7a9d 100644 --- a/ziti/cmd/create_config_environment.go +++ b/ziti/cmd/create_config_environment.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" "runtime" + "strconv" "strings" "text/template" @@ -83,8 +84,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { Long: createConfigEnvironmentLong, Example: createConfigEnvironmentExample, PreRun: func(cmd *cobra.Command, args []string) { - data.populateEnvVars() - data.populateDefaults() + data.populateConfigValues() // Set router identities SetZitiRouterIdentity(&data.Router, validateRouterName("")) // Set up other identity info @@ -94,34 +94,35 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { environmentOptions.EnvVars = []EnvVar{ {constants.ZitiHomeVarName, constants.ZitiHomeVarDescription, data.ZitiHome}, - {constants.ZitiCtrlNameVarName, constants.ZitiCtrlNameVarDescription, data.Controller.Name}, - {constants.ZitiCtrlPortVarName, constants.ZitiCtrlPortVarDescription, data.Controller.Port}, - {constants.ZitiEdgeRouterRawNameVarName, constants.ZitiEdgeRouterRawNameVarDescription, data.Router.Edge.Hostname}, + {constants.PkiCtrlCertVarName, constants.PkiCtrlCertVarDescription, data.Controller.Identity.Cert}, + {constants.PkiCtrlServerCertVarName, constants.PkiCtrlServerCertVarDescription, data.Controller.Identity.ServerCert}, + {constants.PkiCtrlKeyVarName, constants.PkiCtrlKeyVarDescription, data.Controller.Identity.Key}, + {constants.PkiCtrlCAVarName, constants.PkiCtrlCAVarDescription, data.Controller.Identity.Ca}, + {constants.CtrlListenerAddressVarName, constants.CtrlListenerAddressVarDescription, data.Controller.Ctrl.ListenerAddress}, + {constants.CtrlListenerPortVarName, constants.CtrlListenerPortVarDescription, data.Controller.Ctrl.ListenerPort}, + {constants.CtrlEdgeApiAddressVarName, constants.CtrlEdgeApiAddressVarDescription, data.Controller.EdgeApi.Address}, + {constants.CtrlEdgeApiPortVarName, constants.CtrlEdgeApiPortVarDescription, data.Controller.EdgeApi.Port}, + {constants.PkiSignerCertVarName, constants.PkiSignerCertVarDescription, data.Controller.EdgeEnrollment.SigningCert}, + {constants.PkiSignerKeyVarName, constants.PkiSignerKeyVarDescription, data.Controller.EdgeEnrollment.SigningCertKey}, + {constants.CtrlEdgeIdentityEnrollmentDurationVarName, constants.CtrlEdgeIdentityEnrollmentDurationVarDescription, strconv.FormatInt(int64(data.Controller.EdgeEnrollment.EdgeIdentityDuration), 10)}, + {constants.CtrlEdgeRouterEnrollmentDurationVarName, constants.CtrlEdgeRouterEnrollmentDurationVarDescription, strconv.FormatInt(int64(data.Controller.EdgeEnrollment.EdgeRouterDuration), 10)}, + {constants.CtrlEdgeInterfaceAddressVarName, constants.CtrlEdgeInterfaceAddressVarDescription, data.Controller.Web.BindPoints.InterfaceAddress}, + {constants.CtrlEdgeInterfacePortVarName, constants.CtrlEdgeInterfacePortVarDescription, data.Controller.Web.BindPoints.InterfacePort}, + {constants.CtrlEdgeAdvertisedAddressVarName, constants.CtrlEdgeAdvertisedAddressVarDescription, data.Controller.Web.BindPoints.AddressAddress}, + {constants.CtrlEdgeAdvertisedPortVarName, constants.CtrlEdgeAdvertisedPortVarDescription, data.Controller.Web.BindPoints.AddressPort}, + {constants.CtrlPkiEdgeCertVarName, constants.CtrlPkiEdgeCertVarDescription, data.Controller.Web.Identity.Cert}, + {constants.CtrlPkiEdgeServerCertVarName, constants.CtrlPkiEdgeServerCertVarDescription, data.Controller.Web.Identity.ServerCert}, + {constants.CtrlPkiEdgeKeyVarName, constants.CtrlPkiEdgeKeyVarDescription, data.Controller.Web.Identity.Key}, + {constants.CtrlPkiEdgeCAVarName, constants.CtrlPkiEdgeCAVarDescription, data.Controller.Web.Identity.Ca}, + {constants.ZitiEdgeRouterNameVarName, constants.ZitiEdgeRouterNameVarDescription, data.Router.Edge.Hostname}, {constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port}, {constants.ZitiEdgeRouterListenerBindPortVarName, constants.ZitiEdgeRouterListenerBindPortVarDescription, data.Router.Edge.ListenerBindPort}, - {constants.ZitiEdgeCtrlIdentityCertVarName, constants.ZitiEdgeCtrlIdentityCertVarDescription, data.Controller.Edge.IdentityCert}, - {constants.ZitiEdgeCtrlIdentityServerCertVarName, constants.ZitiEdgeCtrlIdentityServerCertVarDescription, data.Controller.Edge.IdentityServerCert}, - {constants.ZitiEdgeCtrlIdentityKeyVarName, constants.ZitiEdgeCtrlIdentityKeyVarDescription, data.Controller.Edge.IdentityKey}, - {constants.ZitiEdgeCtrlIdentityCAVarName, constants.ZitiEdgeCtrlIdentityCAVarDescription, data.Controller.Edge.IdentityCA}, - {constants.ZitiCtrlIdentityCertVarName, constants.ZitiCtrlIdentityCertVarDescription, data.Controller.IdentityCert}, - {constants.ZitiCtrlIdentityServerCertVarName, constants.ZitiCtrlIdentityServerCertVarDescription, data.Controller.IdentityServerCert}, - {constants.ZitiCtrlIdentityKeyVarName, constants.ZitiCtrlIdentityKeyVarDescription, data.Controller.IdentityKey}, - {constants.ZitiCtrlIdentityCAVarName, constants.ZitiCtrlIdentityCAVarDescription, data.Controller.IdentityCA}, - {constants.ZitiSigningCertVarName, constants.ZitiSigningCertVarDescription, data.Controller.Edge.ZitiSigningCert}, - {constants.ZitiSigningKeyVarName, constants.ZitiSigningKeyVarDescription, data.Controller.Edge.ZitiSigningKey}, {constants.ZitiRouterIdentityCertVarName, constants.ZitiRouterIdentityCertVarDescription, data.Router.IdentityCert}, {constants.ZitiRouterIdentityServerCertVarName, constants.ZitiRouterIdentityServerCertVarDescription, data.Router.IdentityServerCert}, {constants.ZitiRouterIdentityKeyVarName, constants.ZitiRouterIdentityKeyVarDescription, data.Router.IdentityKey}, {constants.ZitiRouterIdentityCAVarName, constants.ZitiRouterIdentityCAVarDescription, data.Router.IdentityCA}, {constants.ZitiEdgeRouterIPOverrideVarName, constants.ZitiEdgeRouterIPOverrideVarDescription, data.Router.Edge.IPOverride}, {constants.ZitiEdgeRouterAdvertisedHostVarName, constants.ZitiEdgeRouterAdvertisedHostVarDescription, data.Router.Edge.AdvertisedHost}, - {constants.ZitiCtrlListenerAddressVarName, constants.ZitiCtrlListenerAddressVarDescription, data.Controller.ListenerAddress}, - {constants.ZitiCtrlAdvertisedAddressVarName, constants.ZitiCtrlAdvertisedAddressVarDescription, data.Controller.AdvertisedAddress}, - {constants.ZitiEdgeCtrlListenerHostPortVarName, constants.ZitiEdgeCtrlListenerHostPortVarDescription, data.Controller.Edge.ListenerHostPort}, - {constants.ZitiEdgeCtrlAdvertisedHostPortVarName, constants.ZitiEdgeCtrlAdvertisedHostPortVarDescription, data.Controller.Edge.AdvertisedHostPort}, - {constants.ZitiEdgeCtrlAdvertisedPortVarName, constants.ZitiEdgeCtrlAdvertisedPortVarDescription, data.Controller.Edge.AdvertisedPort}, - {constants.ZitiEdgeIdentityEnrollmentDurationVarName, constants.ZitiEdgeIdentityEnrollmentDurationVarDescription, data.Controller.EdgeIdentityDuration.String()}, - {constants.ZitiEdgeRouterEnrollmentDurationVarName, constants.ZitiEdgeRouterEnrollmentDurationVarDescription, data.Controller.EdgeRouterDuration.String()}, } // Setup logging @@ -187,16 +188,32 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { "%-40s %-50s %s\n"+ "%-40s %-50s %s\n"+ "%-40s %-50s %s\n"+ + "%-40s %-50s %s\n"+ + "%-40s %-50s %s\n"+ + "%-40s %-50s %s\n"+ "%-40s %-50s %s", constants.ZitiHomeVarName, constants.ZitiHomeVarDescription, data.ZitiHome, - constants.ZitiCtrlPortVarName, constants.ZitiCtrlPortVarDescription, data.Controller.Port, - constants.ZitiCtrlNameVarName, constants.ZitiCtrlNameVarDescription, data.Controller.Name, - constants.ZitiCtrlAdvertisedAddressVarName, constants.ZitiCtrlAdvertisedAddressVarDescription, data.Controller.AdvertisedAddress, - constants.ZitiCtrlListenerAddressVarName, constants.ZitiCtrlListenerAddressVarDescription, data.Controller.ListenerAddress, - constants.ZitiEdgeCtrlListenerHostPortVarName, constants.ZitiEdgeCtrlListenerHostPortVarDescription, data.Controller.Edge.ListenerHostPort, - constants.ZitiEdgeCtrlAdvertisedHostPortVarName, constants.ZitiEdgeCtrlAdvertisedHostPortVarDescription, data.Controller.Edge.AdvertisedHostPort, - constants.ZitiEdgeCtrlAdvertisedPortVarName, constants.ZitiEdgeCtrlAdvertisedPortVarDescription, data.Controller.Edge.AdvertisedPort, - constants.ZitiEdgeRouterRawNameVarName, constants.ZitiEdgeRouterRawNameVarDescription, data.Router.Edge.Hostname, + constants.PkiCtrlCertVarName, constants.PkiCtrlCertVarDescription, data.Controller.Identity.Cert, + constants.PkiCtrlServerCertVarName, constants.PkiCtrlServerCertVarDescription, data.Controller.Identity.ServerCert, + constants.PkiCtrlKeyVarName, constants.PkiCtrlKeyVarDescription, data.Controller.Identity.Key, + constants.PkiCtrlCAVarName, constants.PkiCtrlCAVarDescription, data.Controller.Identity.Ca, + constants.CtrlListenerAddressVarName, constants.CtrlListenerAddressVarDescription, data.Controller.Ctrl.ListenerAddress, + constants.CtrlListenerPortVarName, constants.CtrlListenerPortVarDescription, data.Controller.Ctrl.ListenerPort, + constants.CtrlEdgeApiAddressVarName, constants.CtrlEdgeApiAddressVarDescription, data.Controller.EdgeApi.Address, + constants.CtrlEdgeApiPortVarName, constants.CtrlEdgeApiPortVarDescription, data.Controller.EdgeApi.Port, + constants.PkiSignerCertVarName, constants.PkiSignerCertVarDescription, data.Controller.EdgeEnrollment.SigningCert, + constants.PkiSignerKeyVarName, constants.PkiSignerKeyVarDescription, data.Controller.EdgeEnrollment.SigningCertKey, + constants.CtrlEdgeIdentityEnrollmentDurationVarName, constants.CtrlEdgeIdentityEnrollmentDurationVarDescription, strconv.FormatInt(int64(data.Controller.EdgeEnrollment.EdgeIdentityDuration), 10), + constants.CtrlEdgeRouterEnrollmentDurationVarName, constants.CtrlEdgeRouterEnrollmentDurationVarDescription, strconv.FormatInt(int64(data.Controller.EdgeEnrollment.EdgeRouterDuration), 10), + constants.CtrlEdgeInterfaceAddressVarName, constants.CtrlEdgeInterfaceAddressVarDescription, data.Controller.Web.BindPoints.InterfaceAddress, + constants.CtrlEdgeInterfacePortVarName, constants.CtrlEdgeInterfacePortVarDescription, data.Controller.Web.BindPoints.InterfacePort, + constants.CtrlEdgeAdvertisedAddressVarName, constants.CtrlEdgeAdvertisedAddressVarDescription, data.Controller.Web.BindPoints.AddressAddress, + constants.CtrlEdgeAdvertisedPortVarName, constants.CtrlEdgeAdvertisedPortVarDescription, data.Controller.Web.BindPoints.AddressPort, + constants.CtrlPkiEdgeCertVarName, constants.CtrlPkiEdgeCertVarDescription, data.Controller.Web.Identity.Cert, + constants.CtrlPkiEdgeServerCertVarName, constants.CtrlPkiEdgeServerCertVarDescription, data.Controller.Web.Identity.ServerCert, + constants.CtrlPkiEdgeKeyVarName, constants.CtrlPkiEdgeKeyVarDescription, data.Controller.Web.Identity.Key, + constants.CtrlPkiEdgeCAVarName, constants.CtrlPkiEdgeCAVarDescription, data.Controller.Web.Identity.Ca, + constants.ZitiEdgeRouterNameVarName, constants.ZitiEdgeRouterNameVarDescription, data.Router.Edge.Hostname, constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port, constants.ZitiEdgeRouterListenerBindPortVarName, constants.ZitiEdgeRouterListenerBindPortVarDescription, data.Router.Edge.ListenerBindPort, constants.ZitiRouterIdentityCertVarName, constants.ZitiRouterIdentityCertVarDescription, data.Router.IdentityCert, @@ -205,18 +222,8 @@ 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.ZitiCtrlIdentityCertVarName, constants.ZitiCtrlIdentityCertVarDescription, data.Controller.IdentityCert, - constants.ZitiCtrlIdentityServerCertVarName, constants.ZitiCtrlIdentityServerCertVarDescription, data.Controller.IdentityServerCert, - constants.ZitiCtrlIdentityKeyVarName, constants.ZitiCtrlIdentityKeyVarDescription, data.Controller.IdentityKey, - constants.ZitiCtrlIdentityCAVarName, constants.ZitiCtrlIdentityCAVarDescription, data.Controller.IdentityCA, - constants.ZitiEdgeCtrlIdentityCertVarName, constants.ZitiEdgeCtrlIdentityCertVarDescription, data.Controller.Edge.IdentityCert, - constants.ZitiEdgeCtrlIdentityServerCertVarName, constants.ZitiEdgeCtrlIdentityServerCertVarDescription, data.Controller.Edge.IdentityServerCert, - constants.ZitiEdgeCtrlIdentityKeyVarName, constants.ZitiEdgeCtrlIdentityKeyVarDescription, data.Controller.Edge.IdentityKey, - constants.ZitiEdgeCtrlIdentityCAVarName, constants.ZitiEdgeCtrlIdentityCAVarDescription, data.Controller.Edge.IdentityCA, - constants.ZitiSigningCertVarName, constants.ZitiSigningCertVarDescription, data.Controller.Edge.ZitiSigningCert, - constants.ZitiSigningKeyVarName, constants.ZitiSigningKeyVarDescription, data.Controller.Edge.ZitiSigningKey, - constants.ZitiEdgeIdentityEnrollmentDurationVarName, constants.ZitiEdgeIdentityEnrollmentDurationVarDescription, fmt.Sprintf("%.0f", data.Controller.EdgeIdentityDuration.Minutes()), - constants.ZitiEdgeRouterEnrollmentDurationVarName, constants.ZitiEdgeRouterEnrollmentDurationVarDescription, fmt.Sprintf("%.0f", data.Controller.EdgeRouterDuration.Minutes())) + constants.CtrlEdgeIdentityEnrollmentDurationVarName, constants.CtrlEdgeIdentityEnrollmentDurationVarDescription, fmt.Sprintf("%.0f", data.Controller.EdgeEnrollment.EdgeIdentityDuration.Minutes()), + constants.CtrlEdgeRouterEnrollmentDurationVarName, constants.CtrlEdgeRouterEnrollmentDurationVarDescription, fmt.Sprintf("%.0f", data.Controller.EdgeEnrollment.EdgeRouterDuration.Minutes())) cmd.Long = createConfigLong diff --git a/ziti/cmd/create_config_router.go b/ziti/cmd/create_config_router.go index 10ed476a3..249d2dc51 100644 --- a/ziti/cmd/create_config_router.go +++ b/ziti/cmd/create_config_router.go @@ -64,8 +64,7 @@ func NewCmdCreateConfigRouter() *cobra.Command { logrus.SetOutput(logOut) } - data.populateEnvVars() - data.populateDefaults() + data.populateConfigValues() // Update router data with options passed in data.Router.Name = validateRouterName(routerOptions.RouterName) diff --git a/ziti/cmd/create_config_router_common.go b/ziti/cmd/create_config_router_common.go index 378faeee1..3af211e42 100644 --- a/ziti/cmd/create_config_router_common.go +++ b/ziti/cmd/create_config_router_common.go @@ -37,7 +37,7 @@ func SetZitiRouterIdentity(r *RouterTemplateValues, routerName string) { } externalDNS := os.Getenv(constants.ExternalDNSVarName) - edgeRouterRawName := os.Getenv(constants.ZitiEdgeRouterRawNameVarName) + edgeRouterRawName := os.Getenv(constants.ZitiEdgeRouterNameVarName) if externalDNS != "" { r.Edge.Hostname = externalDNS r.Edge.AdvertisedHost = r.Edge.Hostname //not redundant set AdvertisedHost diff --git a/ziti/cmd/create_config_router_edge_test.go b/ziti/cmd/create_config_router_edge_test.go index 61e55f3cc..414fefdde 100644 --- a/ziti/cmd/create_config_router_edge_test.go +++ b/ziti/cmd/create_config_router_edge_test.go @@ -3,7 +3,9 @@ package cmd import ( "github.com/openziti/ziti/ziti/constants" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "os" + "strconv" "strings" "testing" "time" @@ -12,55 +14,35 @@ import ( var defaultArgs = []string{"edge", "--routerName", "test-router"} var testHostname, _ = os.Hostname() -func setEnvByMap[K string, V string](m map[K]V) { - for k, v := range m { - os.Setenv(string(k), string(v)) - } -} - -func execCreateConfigCommand(args []string, keys map[string]string) { - // Setup options - clearOptionsAndTemplateData() - routerOptions.Output = defaultOutput - - setEnvByMap(keys) - // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) - cmd := NewCmdCreateConfigRouter() - cmd.SetArgs(args) - _ = captureOutput(func() { - _ = cmd.Execute() - }) -} - func TestEdgeRouterAdvertised(t *testing.T) { - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerAdvHostIp := "192.168.10.10" routerAdvHostDns := "controller01.zitinetwork.example.org" keys := map[string]string{ - "ZITI_CTRL_PORT": "80", - "ZITI_EDGE_ROUTER_PORT": "443", + "ZITI_CTRL_LISTENER_PORT": "80", + "ZITI_EDGE_ROUTER_PORT": "443", } execCreateConfigCommand(defaultArgs, keys) - assert.Equal(t, testHostname, data.Router.Edge.AdvertisedHost, nil) + require.Equal(t, testHostname, data.Router.Edge.AdvertisedHost, nil) - keys["ZITI_EDGE_ROUTER_RAWNAME"] = routerAdvHostDns + keys["ZITI_EDGE_ROUTER_NAME"] = routerAdvHostDns execCreateConfigCommand(defaultArgs, keys) - assert.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) + require.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) - keys["ZITI_EDGE_ROUTER_RAWNAME"] = "" + keys["ZITI_EDGE_ROUTER_NAME"] = "" keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = routerAdvHostIp execCreateConfigCommand(defaultArgs, keys) - assert.Equal(t, routerAdvHostIp, data.Router.Edge.AdvertisedHost, nil) + require.Equal(t, routerAdvHostIp, data.Router.Edge.AdvertisedHost, nil) keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = "" keys["EXTERNAL_DNS"] = routerAdvHostDns execCreateConfigCommand(defaultArgs, keys) - assert.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) + require.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) keys["ZITI_EDGE_ROUTER_ADVERTISED_HOST"] = routerAdvHostIp keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = routerAdvHostIp execCreateConfigCommand(defaultArgs, keys) - assert.Equal(t, routerAdvHostIp, data.Router.Edge.AdvertisedHost, nil) + require.Equal(t, routerAdvHostIp, data.Router.Edge.AdvertisedHost, nil) keys["ZITI_EDGE_ROUTER_ADVERTISED_HOST"] = routerAdvHostDns keys["EXTERNAL_DNS"] = routerAdvHostDns @@ -70,7 +52,7 @@ func TestEdgeRouterAdvertised(t *testing.T) { func TestTunnelerEnabledByDefault(t *testing.T) { // Setup options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput // Create and run the CLI command without the tunnel flag @@ -88,7 +70,7 @@ func TestTunnelerEnabledByDefault(t *testing.T) { func TestTunnelerNoneMode(t *testing.T) { // Setup options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput // Create and run the CLI command with the disable tunnel flag @@ -109,7 +91,7 @@ func TestTunnelerNoneMode(t *testing.T) { func TestTunnelerHostModeIsDefault(t *testing.T) { // Setup options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput // Create and run the CLI command without the tunnel flag @@ -128,7 +110,7 @@ func TestTunnelerHostModeIsDefault(t *testing.T) { func TestTunnelerTproxyMode(t *testing.T) { // Setup options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput // Create and run the CLI command without the tunnel flag @@ -151,7 +133,7 @@ func TestTunnelerInvalidMode(t *testing.T) { expectedErrorMsg := "Unknown tunneler mode [" + invalidMode + "] provided, should be \"" + noneTunMode + "\", \"" + hostTunMode + "\", or \"" + tproxyTunMode + "\"" // Create the options with both flags set to true - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput routerOptions.TunnelerMode = invalidMode @@ -161,7 +143,7 @@ func TestTunnelerInvalidMode(t *testing.T) { } func TestPrivateEdgeRouterNotAdvertising(t *testing.T) { - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() // Create and run the CLI command config := createRouterConfig([]string{"edge", "--routerName", "myRouter", "--private"}) @@ -175,7 +157,7 @@ func TestBlankEdgeRouterNameBecomesHostname(t *testing.T) { blank := "" // Setup options with blank router name - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput routerOptions.RouterName = blank @@ -191,7 +173,7 @@ func TestBlankEdgeRouterNameBecomesHostname(t *testing.T) { } func TestDefaultZitiEdgeRouterListenerBindPort(t *testing.T) { - expectedDefaultPort := TEST_ROUTER_LISTENER_PORT + expectedDefaultPortStr := strconv.Itoa(testDefaultRouterListenerPort) // Make sure the related env vars are unset _ = os.Unsetenv("ZITI_EDGE_ROUTER_LISTENER_BIND_PORT") @@ -200,14 +182,14 @@ func TestDefaultZitiEdgeRouterListenerBindPort(t *testing.T) { config := createRouterConfig([]string{"edge", "--routerName", "testRouter"}) // Check that the template data has been updated as expected - assert.Equal(t, expectedDefaultPort, data.Router.Edge.ListenerBindPort) + assert.Equal(t, expectedDefaultPortStr, data.Router.Edge.ListenerBindPort) // Check that the actual config output has the correct port for i := 1; i < len(config.Link.Listeners); i++ { if config.Link.Listeners[i].Binding == "transport" { // Assert Bind and Advertise use Bind port value - assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) - assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Address, ":")[1]) + require.Equal(t, expectedDefaultPortStr, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) + require.Equal(t, expectedDefaultPortStr, strings.Split(config.Link.Listeners[i].Address, ":")[1]) break } } @@ -239,7 +221,7 @@ func TestEdgeRouterCannotBeWSSAndPrivate(t *testing.T) { expectedErrorMsg := "Flags for private and wss configs are mutually exclusive. You must choose private or wss, not both" // Create the options with both flags set to true - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput routerOptions.IsPrivate = true routerOptions.WssEnabled = true @@ -253,7 +235,7 @@ func TestEdgeRouterOutputPathDoesNotExist(t *testing.T) { expectedErrorMsg := "stat /IDoNotExist: no such file or directory" // Set the router options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.TunnelerMode = defaultTunnelerMode routerOptions.RouterName = "MyEdgeRouter" routerOptions.Output = "/IDoNotExist/MyEdgeRouter.yaml" @@ -297,7 +279,7 @@ func TestEdgeRouterIPOverrideIsConsumed(t *testing.T) { externalIP := "123.456.78.9" // Setup options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput // Set the env variable to non-empty value diff --git a/ziti/cmd/create_config_router_fabric_test.go b/ziti/cmd/create_config_router_fabric_test.go index 935852989..e0ec1b26d 100644 --- a/ziti/cmd/create_config_router_fabric_test.go +++ b/ziti/cmd/create_config_router_fabric_test.go @@ -4,13 +4,12 @@ import ( "github.com/openziti/ziti/ziti/constants" "github.com/stretchr/testify/assert" "os" + "strconv" "strings" "testing" "time" ) -var TEST_ROUTER_LISTENER_PORT = 10080 - func TestExecuteCreateConfigRouterFabricHasNonBlankTemplateValues(t *testing.T) { routerName := "MyFabricRouter" expectedNonEmptyStringFields := []string{".Router.Listener.BindPort", ".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Hostname", ".Router.Edge.Port"} @@ -45,7 +44,7 @@ func TestFabricRouterIPOverrideIsConsumed(t *testing.T) { externalIP := "123.456.78.9" // Setup options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput // Set the env variable to non-empty value @@ -71,7 +70,7 @@ func TestFabricRouterIPOverrideIsConsumed(t *testing.T) { } func TestFabricRouterHasNoListeners(t *testing.T) { - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() // Create and run the CLI command config := createRouterConfig([]string{"fabric", "--routerName", "myRouter"}) @@ -85,7 +84,7 @@ func TestBlankFabricRouterNameBecomesHostname(t *testing.T) { blank := "" // Create the options with empty router name - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.Output = defaultOutput routerOptions.RouterName = blank @@ -104,7 +103,7 @@ func TestFabricRouterOutputPathDoesNotExist(t *testing.T) { expectedErrorMsg := "stat /IDoNotExist: no such file or directory" // Set the router options - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() routerOptions.RouterName = "MyFabricRouter" routerOptions.Output = "/IDoNotExist/MyFabricRouter.yaml" @@ -114,7 +113,7 @@ func TestFabricRouterOutputPathDoesNotExist(t *testing.T) { } func TestDefaultZitiFabricRouterListenerBindPort(t *testing.T) { - expectedDefaultPort := TEST_ROUTER_LISTENER_PORT + expectedDefaultPortStr := strconv.Itoa(testDefaultRouterListenerPort) // Make sure the related env vars are unset _ = os.Unsetenv("ZITI_EDGE_ROUTER_LISTENER_BIND_PORT") @@ -123,14 +122,14 @@ func TestDefaultZitiFabricRouterListenerBindPort(t *testing.T) { config := createRouterConfig([]string{"fabric", "--routerName", "testRouter"}) // Check that the template data has been updated as expected - assert.Equal(t, expectedDefaultPort, data.Router.Edge.ListenerBindPort) + assert.Equal(t, expectedDefaultPortStr, data.Router.Edge.ListenerBindPort) // Check that the actual config output has the correct port for i := 1; i < len(config.Link.Listeners); i++ { if config.Link.Listeners[i].Binding == "transport" { // Assert Bind and Advertise use Bind port value - assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) - assert.Equal(t, expectedDefaultPort, strings.Split(config.Link.Listeners[i].Address, ":")[1]) + assert.Equal(t, expectedDefaultPortStr, strings.Split(config.Link.Listeners[i].Bind, ":")[1]) + assert.Equal(t, expectedDefaultPortStr, strings.Split(config.Link.Listeners[i].Address, ":")[1]) break } } diff --git a/ziti/cmd/create_config_router_test.go b/ziti/cmd/create_config_router_test.go index 7d0a18545..226716d8d 100644 --- a/ziti/cmd/create_config_router_test.go +++ b/ziti/cmd/create_config_router_test.go @@ -9,6 +9,9 @@ import ( "testing" ) +// TEST constants +var testDefaultRouterListenerPort = 10080 + /* BEGIN Controller config template structure */ type RouterConfig struct { @@ -120,16 +123,25 @@ func createRouterConfig(args []string) RouterConfig { return configStruct } -func clearOptionsAndTemplateData() { +func execCreateConfigCommand(args []string, keys map[string]string) { + // Setup options + clearRouterOptionsAndTemplateData() + routerOptions.Output = defaultOutput + + setEnvByMap(keys) + // Create and run the CLI command (capture output, otherwise config prints to stdout instead of test results) + cmd := NewCmdCreateConfigRouter() + cmd.SetArgs(args) + _ = captureOutput(func() { + _ = cmd.Execute() + }) +} + +func clearRouterOptionsAndTemplateData() { routerOptions = CreateConfigRouterOptions{} data = &ConfigTemplateValues{} - // Unset environment variables - envVars := getZitiEnvironmentVariables() - for i := 0; i < len(envVars); i++ { - _ = os.Unsetenv(envVars[i]) - } - _ = os.Unsetenv(constants.ExternalDNSVarName) + unsetZitiEnv() } func TestSetZitiRouterIdentityCertDefault(t *testing.T) { @@ -234,7 +246,7 @@ func TestSetZitiRouterIdentityCACustom(t *testing.T) { func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawName(t *testing.T) { // Setup - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() expectedRawName := "MyEdgeRouterRawName" blank := "" rtv := &RouterTemplateValues{} @@ -247,7 +259,7 @@ func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawName(t *testing.T assert.Equal(t, blank, rtv.IdentityCA) // Set the env variable - _ = os.Setenv(constants.ZitiEdgeRouterRawNameVarName, expectedRawName) + _ = os.Setenv(constants.ZitiEdgeRouterNameVarName, expectedRawName) SetZitiRouterIdentity(rtv, expectedRawName) @@ -261,7 +273,7 @@ func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawName(t *testing.T func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawNameToHostWhenBlank(t *testing.T) { // Setup - clearOptionsAndTemplateData() + clearRouterOptionsAndTemplateData() expectedRawName, _ := os.Hostname() blank := "" rtv := &RouterTemplateValues{} @@ -274,7 +286,7 @@ func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawNameToHostWhenBla assert.Equal(t, blank, rtv.IdentityCA) // Set the env variable to an empty value - _ = os.Setenv(constants.ZitiEdgeRouterRawNameVarName, "") + _ = os.Setenv(constants.ZitiEdgeRouterNameVarName, "") SetZitiRouterIdentity(rtv, expectedRawName) diff --git a/ziti/cmd/create_config_test.go b/ziti/cmd/create_config_test.go index 51ed0e9ed..97403e5bd 100644 --- a/ziti/cmd/create_config_test.go +++ b/ziti/cmd/create_config_test.go @@ -3,40 +3,64 @@ package cmd import ( "bytes" "fmt" + "github.com/openziti/ziti/ziti/constants" "github.com/stretchr/testify/assert" "io" "os" "strings" "testing" + "time" +) + +// These constants are hard-coded so that they may serve as a notifier. When the constants change in the source from +// which they came, we may need to update any related documentation. If the constant is changed, the tests should fail +// as they are expecting these hard-coded values. In which case, we update the hard-coded values and check any docs. +const ( + testDefaultCtrlEdgeAdvertisedPort = "1280" + testDefaultCtrlListenerAddress = "0.0.0.0" + testDefaultCtrlListenerPort = "6262" + testDefaultBoltCheckInterval = "30s" + testDefaultBoltCheckTimeout = "20s" + testDefaultBoltCheckInitialDelay = "30s" + testDefaultEdgeOptionsIdleTimeout = "5000ms" + testDefaultEdgeOptionsReadTimeout = "5000ms" + testDefaultEdgeOptionsWriteTimeout = "100000ms" + testDefaultEdgeOptionsMinTLSVersion = "TLS1.2" + testDefaultEdgeOptionsMaxTLSVersion = "TLS1.3" + testDefaultEdgeIdentityEnrollmentDuration = time.Duration(180) * time.Minute + testDefaultEdgeIdentityEnrollmentStr = "180m" + testDefaultEdgeRouterEnrollmentDuration = time.Duration(180) * time.Minute + testDefaultEdgeRouterEnrollmentStr = "180m" ) func getZitiEnvironmentVariables() []string { return []string{ "ZITI_HOME", - "ZITI_CONTROLLER_NAME", - "ZITI_CTRL_PORT", - "ZITI_EDGE_ROUTER_RAWNAME", + "ZITI_EDGE_ROUTER_NAME", "ZITI_EDGE_ROUTER_PORT", - "ZITI_EDGE_CTRL_IDENTITY_CERT", - "ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT", - "ZITI_EDGE_CTRL_IDENTITY_KEY", - "ZITI_EDGE_CTRL_IDENTITY_CA", - "ZITI_EDGE_CONTROLLER_PORT", - "ZITI_CTRL_IDENTITY_CERT", - "ZITI_CTRL_IDENTITY_SERVER_CERT", - "ZITI_CTRL_IDENTITY_KEY", - "ZITI_CTRL_IDENTITY_CA", - "ZITI_SIGNING_CERT", - "ZITI_SIGNING_KEY", + "ZITI_PKI_CTRL_CERT", + "ZITI_PKI_CTRL_SERVER_CERT", + "ZITI_PKI_CTRL_KEY", + "ZITI_PKI_CTRL_CA", + "ZITI_CTRL_LISTENER_ADDRESS", + "ZITI_CTRL_LISTENER_PORT", + "ZITI_CTRL_EDGE_API_ADDRESS", + "ZITI_CTRL_EDGE_API_PORT", + "ZITI_PKI_SIGNER_CERT", + "ZITI_PKI_SIGNER_KEY", + "ZITI_CTRL_EDGE_INTERFACE_ADDRESS", + "ZITI_CTRL_EDGE_INTERFACE_PORT", + "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS", + "ZITI_CTRL_EDGE_ADVERTISED_PORT", + "ZITI_PKI_EDGE_CA", + "ZITI_PKI_EDGE_KEY", + "ZITI_PKI_EDGE_SERVER_CERT", + "ZITI_PKI_EDGE_CERT", "ZITI_ROUTER_IDENTITY_CERT", "ZITI_ROUTER_IDENTITY_SERVER_CERT", "ZITI_ROUTER_IDENTITY_KEY", "ZITI_ROUTER_IDENTITY_CA", "ZITI_EDGE_ROUTER_IP_OVERRIDE", - "ZITI_CTRL_LISTENER_ADDRESS", - "ZITI_CTRL_ADVERTISED_ADDRESS", - "ZITI_CTRL_EDGE_LISTENER_HOST_PORT", - "ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT", "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION", "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION", "ZITI_EDGE_ROUTER_ADVERTISED_HOST", @@ -44,6 +68,15 @@ func getZitiEnvironmentVariables() []string { } } +func unsetZitiEnv() { + // Unset environment variables + envVars := getZitiEnvironmentVariables() + for i := 0; i < len(envVars); i++ { + _ = os.Unsetenv(envVars[i]) + } + _ = os.Unsetenv(constants.ExternalDNSVarName) +} + // Test that all ZITI_* variables are included in the values for output func TestNoUnknownOutputEnvVariablesExist(t *testing.T) { // Get the list of ZITI_* environment variables @@ -234,3 +267,9 @@ func captureOutput(function func()) string { _, _ = io.Copy(&buffer, r) return buffer.String() } + +func setEnvByMap[K string, V string](m map[K]V) { + for k, v := range m { + os.Setenv(string(k), string(v)) + } +} diff --git a/ziti/cmd/helpers/env_helpers.go b/ziti/cmd/helpers/env_helpers.go index 27c5c497e..0e276d131 100644 --- a/ziti/cmd/helpers/env_helpers.go +++ b/ziti/cmd/helpers/env_helpers.go @@ -55,7 +55,8 @@ func GetZitiHome() (string, error) { // If not set, create a default path of the current working directory workingDir, err := WorkingDir() if err != nil { - return "", err + // If there is an error just use . + workingDir = "." } err = os.Setenv(constants.ZitiHomeVarName, workingDir) @@ -69,15 +70,81 @@ func GetZitiHome() (string, error) { return NormalizePath(retVal), nil } -func GetZitiCtrlAdvertisedAddress() (string, error) { +func HostnameOrNetworkName() string { + val := os.Getenv("ZITI_NETWORK_NAME") + if val == "" { + h, err := os.Hostname() + if err != nil { + return "localhost" + } + return h + } + return val +} - // Use External DNS if set - extDNS := os.Getenv(constants.ExternalDNSVarName) - if extDNS != "" { - return extDNS, nil +func GetCtrlListenerAddress() (string, error) { + return getValueOrSetAndGetDefault(constants.CtrlListenerAddressVarName, constants.DefaultCtrlListenerAddress) +} + +func GetCtrlListenerPort() (string, error) { + return getValueOrSetAndGetDefault(constants.CtrlListenerPortVarName, constants.DefaultCtrlListenerPort) +} + +func GetCtrlEdgeApiAddress() (string, error) { + // Get the controller's edge advertised hostname to use as the default + defaultHostname, err := GetCtrlEdgeAdvertisedAddress() + if err != nil { + err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeAdvertisedAddressVarName) + if err != nil { + return "", err + } } - // Use hostname if external DNS and advertised address not set + return getValueOrSetAndGetDefault(constants.CtrlEdgeApiAddressVarName, defaultHostname) +} + +func GetCtrlEdgeApiPort() (string, error) { + // Get the controller's edge advertised port to use as the default + defaultPort, err := GetCtrlEdgeAdvertisedPort() + if err != nil { + err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeAdvertisedPortVarName) + if err != nil { + return "", err + } + } + + return getValueOrSetAndGetDefault(constants.CtrlEdgeApiPortVarName, defaultPort) +} + +func GetCtrlEdgeInterfaceAddress() (string, error) { + // Get the controller's listener hostname to use as the default + defaultHostname, err := GetCtrlListenerAddress() + if err != nil { + err := errors.Wrap(err, "Unable to get "+constants.CtrlListenerAddressVarName) + if err != nil { + return "", err + } + } + + return getValueOrSetAndGetDefault(constants.CtrlEdgeInterfaceAddressVarName, defaultHostname) +} + +func GetCtrlEdgeInterfacePort() (string, error) { + // Get the controller's edge advertised port to use as the default + defaultPort, err := GetCtrlEdgeAdvertisedPort() + if err != nil { + err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeAdvertisedPortVarName) + if err != nil { + return "", err + } + } + + return getValueOrSetAndGetDefault(constants.CtrlEdgeInterfacePortVarName, defaultPort) +} + +func GetCtrlEdgeAdvertisedAddress() (string, error) { + + // Use hostname if edge advertised address not set hostname, err := os.Hostname() if err != nil { err := errors.Wrap(err, "Unable to get hostname") @@ -86,19 +153,11 @@ func GetZitiCtrlAdvertisedAddress() (string, error) { } } - return getValueOrSetAndGetDefault(constants.ZitiCtrlAdvertisedAddressVarName, hostname) + return getValueOrSetAndGetDefault(constants.CtrlEdgeAdvertisedAddressVarName, hostname) } -func GetZitiCtrlPort() (string, error) { - return getValueOrSetAndGetDefault(constants.ZitiCtrlPortVarName, constants.DefaultZitiControllerPort) -} - -func GetZitiCtrlListenerAddress() (string, error) { - return getValueOrSetAndGetDefault(constants.ZitiCtrlListenerAddressVarName, constants.DefaultZitiControllerListenerAddress) -} - -func GetZitiCtrlName() (string, error) { - return getValueOrSetAndGetDefault(constants.ZitiCtrlNameVarName, constants.DefaultZitiControllerName) +func GetCtrlEdgeAdvertisedPort() (string, error) { + return getValueOrSetAndGetDefault(constants.CtrlEdgeAdvertisedPortVarName, constants.DefaultCtrlEdgeAdvertisedPort) } func GetZitiEdgeRouterPort() (string, error) { @@ -109,62 +168,17 @@ func GetZitiEdgeRouterListenerBindPort() (string, error) { return getValueOrSetAndGetDefault(constants.ZitiEdgeRouterListenerBindPortVarName, constants.DefaultZitiEdgeRouterListenerBindPort) } -func GetZitiEdgeCtrlListenerHostPort() (string, error) { - // Get the edge controller port to use as the default - edgeCtrlPort, err := GetZitiEdgeCtrlAdvertisedPort() +func GetCtrlEdgeIdentityEnrollmentDuration() (time.Duration, error) { + retVal, err := getValueOrSetAndGetDefault(constants.CtrlEdgeIdentityEnrollmentDurationVarName, strconv.FormatInt(int64(edge.DefaultEdgeEnrollmentDuration.Minutes()), 10)) if err != nil { - err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeCtrlAdvertisedPortVarName) - if err != nil { - return "", err - } - } - - return getValueOrSetAndGetDefault(constants.ZitiEdgeCtrlListenerHostPortVarName, constants.DefaultZitiEdgeListenerHost+":"+edgeCtrlPort) -} - -func GetZitiEdgeCtrlAdvertisedHostPort() (string, error) { - - port, err := GetZitiEdgeCtrlAdvertisedPort() - if err != nil { - err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeCtrlAdvertisedPortVarName) - if err != nil { - return "", err - } - } - - // Use External DNS if set - extDNS := os.Getenv(constants.ExternalDNSVarName) - if extDNS != "" { - return extDNS + ":" + port, nil - } - - // Use hostname and advertised port if advertised host port env var not set - hostname, err := os.Hostname() - if err != nil { - err := errors.Wrap(err, "Unable to get hostname") - if err != nil { - return "", err - } - } - - return getValueOrSetAndGetDefault(constants.ZitiEdgeCtrlAdvertisedHostPortVarName, hostname+":"+port) -} - -func GetZitiEdgeCtrlAdvertisedPort() (string, error) { - return getValueOrSetAndGetDefault(constants.ZitiEdgeCtrlAdvertisedPortVarName, constants.DefaultZitiEdgeAPIPort) -} - -func GetZitiEdgeIdentityEnrollmentDuration() (time.Duration, error) { - retVal, err := getValueOrSetAndGetDefault(constants.ZitiEdgeIdentityEnrollmentDurationVarName, strconv.FormatInt(int64(edge.DefaultEdgeEnrollmentDuration.Minutes()), 10)) - if err != nil { - err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeIdentityEnrollmentDurationVarDescription) + err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeIdentityEnrollmentDurationVarDescription) if err != nil { return edge.DefaultEdgeEnrollmentDuration, err } } retValInt, err := strconv.Atoi(retVal) if err != nil { - err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeIdentityEnrollmentDurationVarDescription) + err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeIdentityEnrollmentDurationVarDescription) if err != nil { return edge.DefaultEdgeEnrollmentDuration, err } @@ -173,17 +187,17 @@ func GetZitiEdgeIdentityEnrollmentDuration() (time.Duration, error) { return time.Duration(retValInt) * time.Minute, nil } -func GetZitiEdgeRouterEnrollmentDuration() (time.Duration, error) { - retVal, err := getValueOrSetAndGetDefault(constants.ZitiEdgeRouterEnrollmentDurationVarName, strconv.FormatInt(int64(edge.DefaultEdgeEnrollmentDuration.Minutes()), 10)) +func GetCtrlEdgeRouterEnrollmentDuration() (time.Duration, error) { + retVal, err := getValueOrSetAndGetDefault(constants.CtrlEdgeRouterEnrollmentDurationVarName, strconv.FormatInt(int64(edge.DefaultEdgeEnrollmentDuration.Minutes()), 10)) if err != nil { - err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeRouterEnrollmentDurationVarDescription) + err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeRouterEnrollmentDurationVarDescription) if err != nil { return edge.DefaultEdgeEnrollmentDuration, err } } retValInt, err := strconv.Atoi(retVal) if err != nil { - err := errors.Wrap(err, "Unable to get "+constants.ZitiEdgeRouterEnrollmentDurationVarDescription) + err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeRouterEnrollmentDurationVarDescription) if err != nil { return edge.DefaultEdgeEnrollmentDuration, err } diff --git a/ziti/cmd/helpers/helpers_test.go b/ziti/cmd/helpers/helpers_test.go index 29690e80a..6c24a85a0 100644 --- a/ziti/cmd/helpers/helpers_test.go +++ b/ziti/cmd/helpers/helpers_test.go @@ -10,16 +10,12 @@ import ( ) func TestHomeDirHasNoWindowsSlashes(t *testing.T) { - value := HomeDir() - assert.Zero(t, strings.Count(value, "\\")) - } func TestWorkingDirHasNoWindowsSlashes(t *testing.T) { value, _ := WorkingDir() - assert.Zero(t, strings.Count(value, "\\")) } @@ -54,7 +50,7 @@ func TestGetZitiHomeWhenSet(t *testing.T) { assert.Equal(t, expectedValue, actualValue) } -func TestGetZitiHomeWhenSetWithWindowsSlashes(t *testing.T) { +func TestGetHomeWhenSetWithWindowsSlashes(t *testing.T) { // Setup varName := "ZITI_HOME" expectedValue := "/path/to/ziti/home" @@ -67,16 +63,16 @@ func TestGetZitiHomeWhenSetWithWindowsSlashes(t *testing.T) { assert.Equal(t, expectedValue, actualValue) } -func TestGetZitiCtrlAdvertisedAddressWhenUnset(t *testing.T) { +func TestGetCtrlEdgeAdvertisedAddressWhenUnset(t *testing.T) { // Setup - varName := "ZITI_CTRL_ADVERTISED_ADDRESS" + varName := "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS" // Ensure the variable is unset _ = os.Unsetenv(varName) expectedValue, _ := os.Hostname() // Check that the value matches - actualValue, _ := GetZitiCtrlAdvertisedAddress() + actualValue, _ := GetCtrlEdgeAdvertisedAddress() assert.Equal(t, expectedValue, actualValue) // The env variable should be populated with the expected value @@ -84,46 +80,29 @@ func TestGetZitiCtrlAdvertisedAddressWhenUnset(t *testing.T) { assert.Equal(t, expectedValue, envValue) } -func TestGetZitiCtrlAdvertisedAddressWhenSet(t *testing.T) { +func TestGetCtrlEdgeAdvertisedAddressWhenSet(t *testing.T) { // Setup - varName := "ZITI_CTRL_ADVERTISED_ADDRESS" + varName := "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS" expectedValue := "localhost" // Set the env variable _ = os.Setenv(varName, expectedValue) // Check that the value matches - actualValue, _ := GetZitiCtrlAdvertisedAddress() + actualValue, _ := GetCtrlEdgeAdvertisedAddress() assert.Equal(t, expectedValue, actualValue) } -// Confirm that EXTERNAL_DNS is used over ZITI_CTRL_ADVERTISED_ADDRESS -func TestGetZitiCtrlAdvertisedAddressWhenExtDNSSet(t *testing.T) { +func TestGetCtrlPortWhenUnset(t *testing.T) { // Setup - ctrlAdvAddressVarName := "ZITI_CTRL_ADVERTISED_ADDRESS" - ctrlAdvAddressValue := "advertisedAddress" - extDNSVarName := "EXTERNAL_DNS" - externalDNSValue := "myexternaldns" - - // Set the env variable - _ = os.Setenv(ctrlAdvAddressVarName, ctrlAdvAddressValue) - _ = os.Setenv(extDNSVarName, externalDNSValue) - - // Check that the value matches - actualValue, _ := GetZitiCtrlAdvertisedAddress() - assert.Equal(t, externalDNSValue, actualValue) -} - -func TestGetZitiCtrlPortWhenUnset(t *testing.T) { - // Setup - varName := "ZITI_CTRL_PORT" + varName := "ZITI_CTRL_LISTENER_PORT" // Ensure the variable is unset _ = os.Unsetenv(varName) expectedValue := "6262" // Check that the value matches - actualValue, _ := GetZitiCtrlPort() + actualValue, _ := GetCtrlListenerPort() assert.Equal(t, expectedValue, actualValue) // The env variable should be populated with the expected value @@ -131,20 +110,20 @@ func TestGetZitiCtrlPortWhenUnset(t *testing.T) { assert.Equal(t, expectedValue, envValue) } -func TestGetZitiCtrlPortWhenSet(t *testing.T) { +func TestGetCtrlPortWhenSet(t *testing.T) { // Setup - varName := "ZITI_CTRL_PORT" + varName := "ZITI_CTRL_LISTENER_PORT" expectedValue := "1234" // Set the env variable _ = os.Setenv(varName, expectedValue) // Check that the value matches - actualValue, _ := GetZitiCtrlPort() + actualValue, _ := GetCtrlListenerPort() assert.Equal(t, expectedValue, actualValue) } -func TestGetZitiCtrlListenerAddressWhenUnset(t *testing.T) { +func TestGetCtrlListenerAddressWhenUnset(t *testing.T) { // Setup varName := "ZITI_CTRL_LISTENER_ADDRESS" @@ -153,7 +132,7 @@ func TestGetZitiCtrlListenerAddressWhenUnset(t *testing.T) { expectedValue := "0.0.0.0" // Check that the value matches - actualValue, _ := GetZitiCtrlListenerAddress() + actualValue, _ := GetCtrlListenerAddress() assert.Equal(t, expectedValue, actualValue) // The env variable should be populated with the expected value @@ -161,7 +140,7 @@ func TestGetZitiCtrlListenerAddressWhenUnset(t *testing.T) { assert.Equal(t, expectedValue, envValue) } -func TestGetZitiCtrlListenerAddressWhenSet(t *testing.T) { +func TestGetCtrlListenerAddressWhenSet(t *testing.T) { // Setup varName := "ZITI_CTRL_LISTENER_ADDRESS" expectedValue := "localhost" @@ -170,41 +149,11 @@ func TestGetZitiCtrlListenerAddressWhenSet(t *testing.T) { _ = os.Setenv(varName, expectedValue) // Check that the value matches - actualValue, _ := GetZitiCtrlListenerAddress() + actualValue, _ := GetCtrlListenerAddress() assert.Equal(t, expectedValue, actualValue) } -func TestGetZitiCtrlNameWhenUnset(t *testing.T) { - // Setup - varName := "ZITI_CONTROLLER_NAME" - - // Ensure the variable is unset - _ = os.Unsetenv(varName) - expectedValue := "controller" - - // Check that the value matches - actualValue, _ := GetZitiCtrlName() - assert.Equal(t, expectedValue, actualValue) - - // The env variable should be populated with the expected value - envValue := os.Getenv(varName) - assert.Equal(t, expectedValue, envValue) -} - -func TestGetZitiCtrlNameWhenSet(t *testing.T) { - // Setup - varName := "ZITI_CONTROLLER_NAME" - expectedValue := "MyController" - - // Set the env variable - _ = os.Setenv(varName, expectedValue) - - // Check that the value matches - actualValue, _ := GetZitiCtrlName() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeRouterPortWhenUnset(t *testing.T) { +func TestGetEdgeRouterPortWhenUnset(t *testing.T) { // Setup varName := "ZITI_EDGE_ROUTER_PORT" @@ -221,7 +170,7 @@ func TestGetZitiEdgeRouterPortWhenUnset(t *testing.T) { assert.Equal(t, expectedValue, envValue) } -func TestGetZitiEdgeRouterPortWhenSet(t *testing.T) { +func TestGetEdgeRouterPortWhenSet(t *testing.T) { // Setup varName := "ZITI_EDGE_ROUTER_PORT" expectedValue := "4321" @@ -234,213 +183,112 @@ func TestGetZitiEdgeRouterPortWhenSet(t *testing.T) { assert.Equal(t, expectedValue, actualValue) } -func TestGetZitiEdgeCtrlListenerHostPortWhenUnset(t *testing.T) { +func TestGetCtrlEdgeAdvertisedPortWhenNotSet(t *testing.T) { // Setup - varName := "ZITI_CTRL_EDGE_LISTENER_HOST_PORT" - - // Ensure the variable is unset - _ = os.Unsetenv(varName) - expectedValue := "0.0.0.0:1280" - - // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlListenerHostPort() - assert.Equal(t, expectedValue, actualValue) - - // The env variable should be populated with the expected value - envValue := os.Getenv(varName) - assert.Equal(t, expectedValue, envValue) -} - -func TestGetZitiEdgeCtrlListenerHostPortWhenSet(t *testing.T) { - // Setup - varName := "ZITI_CTRL_EDGE_LISTENER_HOST_PORT" - expectedValue := "localhost:1234" - - // Set the env variable - _ = os.Setenv(varName, expectedValue) - - // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlListenerHostPort() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeCtrlAdvertisedHostPortWhenUnset(t *testing.T) { - // Setup - edgeCtrlAdvHostPortVarName := "ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT" - extDNSVarName := "EXTERNAL_DNS" - - // Set up env variables - _ = os.Unsetenv(extDNSVarName) - _ = os.Unsetenv(edgeCtrlAdvHostPortVarName) - hostname, _ := os.Hostname() - expectedValue := hostname + ":1280" - - // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlAdvertisedHostPort() - assert.Equal(t, expectedValue, actualValue) - - // The env variable should be populated with the expected value - envValue := os.Getenv(edgeCtrlAdvHostPortVarName) - assert.Equal(t, expectedValue, envValue) -} - -func TestGetZitiEdgeCtrlAdvertisedHostPortWhenSet(t *testing.T) { - // Setup - edgeCtrlAdvHostPortVarName := "ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT" - extDNSVarName := "EXTERNAL_DNS" - expectedValue := "localhost:4321" - - // Set the env variable - _ = os.Unsetenv(extDNSVarName) - _ = os.Setenv(edgeCtrlAdvHostPortVarName, expectedValue) - - // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlAdvertisedHostPort() - assert.Equal(t, expectedValue, actualValue) -} - -// Confirm that EXTERNAL_DNS and ZITI_EDGE_CONTROLLER_PORT get used over ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT -func TestGetZitiEdgeCtrlAdvertisedHostPortWhenExtDNSAndHostPortSet(t *testing.T) { - // Setup - extDNSVarName := "EXTERNAL_DNS" - zitiEdgeCtrlAdvHostPortVarName := "ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT" - advHostPortValue := "localhost:1234" - externalDNSValue := "myexternaldns" - - expectedValue := externalDNSValue + ":1280" - - // Setup the env variables - _ = os.Setenv(zitiEdgeCtrlAdvHostPortVarName, advHostPortValue) - _ = os.Setenv(extDNSVarName, externalDNSValue) - - // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlAdvertisedHostPort() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeCtrlAdvertisedHostPortWhenExternalDNSAndPortSet(t *testing.T) { - // Setup - extDNSVarName := "EXTERNAL_DNS" - ctrlPortVarName := "ZITI_EDGE_CONTROLLER_PORT" - externalDNSValue := "myexternaldns" - ctrlPortValue := "1234" - expectedValue := externalDNSValue + ":" + ctrlPortValue - - // Setup the env variables - _ = os.Setenv(ctrlPortVarName, ctrlPortValue) - _ = os.Setenv(extDNSVarName, externalDNSValue) - - // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlAdvertisedHostPort() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeCtrlPortWhenNotSet(t *testing.T) { - // Setup - varName := "ZITI_EDGE_CONTROLLER_PORT" + varName := "ZITI_CTRL_EDGE_ADVERTISED_PORT" expectedValue := "1280" // Be sure the var is unset _ = os.Unsetenv(varName) // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlAdvertisedPort() + actualValue, _ := GetCtrlEdgeAdvertisedPort() assert.Equal(t, expectedValue, actualValue) } -func TestGetZitiEdgeIdentityEnrollmentDurationWhenSet(t *testing.T) { +func TestGetCtrlEdgeAdvertisedPortWhenSet(t *testing.T) { // Setup - varName := "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" - expectedValue := 5 * time.Minute - - // Set the env variable - _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) - - // Check that the value matches - actualValue, _ := GetZitiEdgeIdentityEnrollmentDuration() - assert.Equal(t, expectedValue, actualValue) -} - -/* Ensure that the default value is returned even if the environment variable is set but is blank. */ -func TestGetZitiEdgeIdentityEnrollmentDurationWhenSetToBlank(t *testing.T) { - // Setup - varName := "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" - // Expect the default, hard coding the value to act as an alert if default is changed in edge project - expectedValue := 180 * time.Minute - - // Set the env variable - _ = os.Setenv(varName, "") - - // Check that the value matches - actualValue, _ := GetZitiEdgeIdentityEnrollmentDuration() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeIdentityEnrollmentDurationWhenNotSet(t *testing.T) { - // Setup - varName := "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" - // Expect the default, hard coding the value to act as an alert if default is changed in edge project - expectedValue := 180 * time.Minute - - // Set the env variable - _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) - - // Check that the value matches - actualValue, _ := GetZitiEdgeIdentityEnrollmentDuration() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeRouterEnrollmentDurationWhenSet(t *testing.T) { - // Setup - varName := "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" - expectedValue := 5 * time.Minute - - // Set the env variable - _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) - - // Check that the value matches - actualValue, _ := GetZitiEdgeRouterEnrollmentDuration() - assert.Equal(t, expectedValue, actualValue) -} - -/* Ensure that the default value is returned even if the environment variable is set but is blank. */ -func TestGetZitiEdgeRouterEnrollmentDurationWhenSetToBlank(t *testing.T) { - // Setup - varName := "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" - // Expect the default, hard coding the value to act as an alert if default is changed in edge project - expectedValue := 180 * time.Minute - - // Set the env variable - _ = os.Setenv(varName, "") - - // Check that the value matches - actualValue, _ := GetZitiEdgeRouterEnrollmentDuration() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeRouterEnrollmentDurationWhenNotSet(t *testing.T) { - // Setup - varName := "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" - // Expect the default, hard coding the value to act as an alert if default is changed in edge project - expectedValue := 180 * time.Minute - - // Set the env variable - _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) - - // Check that the value matches - actualValue, _ := GetZitiEdgeRouterEnrollmentDuration() - assert.Equal(t, expectedValue, actualValue) -} - -func TestGetZitiEdgeCtrlPortWhenSet(t *testing.T) { - // Setup - varName := "ZITI_EDGE_CONTROLLER_PORT" + varName := "ZITI_CTRL_EDGE_ADVERTISED_PORT" expectedValue := "1234" // Set the env variable _ = os.Setenv(varName, expectedValue) // Check that the value matches - actualValue, _ := GetZitiEdgeCtrlAdvertisedPort() + actualValue, _ := GetCtrlEdgeAdvertisedPort() + assert.Equal(t, expectedValue, actualValue) +} + +func TestGetEdgeIdentityEnrollmentDurationWhenSet(t *testing.T) { + // Setup + varName := "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" + expectedValue := 5 * time.Minute + + // Set the env variable + _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) + + // Check that the value matches + actualValue, _ := GetCtrlEdgeIdentityEnrollmentDuration() + assert.Equal(t, expectedValue, actualValue) +} + +/* Ensure that the default value is returned even if the environment variable is set but is blank. */ +func TestGetEdgeIdentityEnrollmentDurationWhenSetToBlank(t *testing.T) { + // Setup + varName := "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" + // Expect the default, hard coding the value to act as an alert if default is changed in edge project + expectedValue := 180 * time.Minute + + // Set the env variable + _ = os.Setenv(varName, "") + + // Check that the value matches + actualValue, _ := GetCtrlEdgeIdentityEnrollmentDuration() + assert.Equal(t, expectedValue, actualValue) +} + +func TestGetEdgeIdentityEnrollmentDurationWhenNotSet(t *testing.T) { + // Setup + varName := "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" + // Expect the default, hard coding the value to act as an alert if default is changed in edge project + expectedValue := 180 * time.Minute + + // Set the env variable + _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) + + // Check that the value matches + actualValue, _ := GetCtrlEdgeIdentityEnrollmentDuration() + assert.Equal(t, expectedValue, actualValue) +} + +func TestGetEdgeRouterEnrollmentDurationWhenSet(t *testing.T) { + // Setup + varName := "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" + expectedValue := 5 * time.Minute + + // Set the env variable + _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) + + // Check that the value matches + actualValue, _ := GetCtrlEdgeRouterEnrollmentDuration() + assert.Equal(t, expectedValue, actualValue) +} + +/* Ensure that the default value is returned even if the environment variable is set but is blank. */ +func TestGetEdgeRouterEnrollmentDurationWhenSetToBlank(t *testing.T) { + // Setup + varName := "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" + // Expect the default, hard coding the value to act as an alert if default is changed in edge project + expectedValue := 180 * time.Minute + + // Set the env variable + _ = os.Setenv(varName, "") + + // Check that the value matches + actualValue, _ := GetCtrlEdgeRouterEnrollmentDuration() + assert.Equal(t, expectedValue, actualValue) +} + +func TestGetEdgeRouterEnrollmentDurationWhenNotSet(t *testing.T) { + // Setup + varName := "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" + // Expect the default, hard coding the value to act as an alert if default is changed in edge project + expectedValue := 180 * time.Minute + + // Set the env variable + _ = os.Setenv(varName, fmt.Sprintf("%.0f", expectedValue.Minutes())) + + // Check that the value matches + actualValue, _ := GetCtrlEdgeRouterEnrollmentDuration() assert.Equal(t, expectedValue, actualValue) } diff --git a/ziti/cmd/common_install_test.go b/ziti/cmd/install/common_install_test.go similarity index 91% rename from ziti/cmd/common_install_test.go rename to ziti/cmd/install/common_install_test.go index f74ee6798..44b711208 100644 --- a/ziti/cmd/common_install_test.go +++ b/ziti/cmd/install/common_install_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package cmd +package install import ( c "github.com/openziti/ziti/ziti/constants" @@ -35,7 +35,7 @@ func TestInstallZitiApp(t *testing.T) { defer os.Unsetenv("HOME") err = os.Setenv("HOME", "/tmp/"+uuid.New()) assert.Nil(t, err) - err = (&CommonOptions{}).installZitiApp("main", c.ZITI_CONTROLLER, true, "0.0.0-0") + err = (&InstallOptions{}).installZitiApp("main", c.ZITI_CONTROLLER, true, "0.0.0-0") assert.FileExists(t, os.Getenv("HOME")+"/bin/"+c.ZITI_CONTROLLER) } diff --git a/ziti/constants/constants.go b/ziti/constants/constants.go index 3aacff84d..3f78bd3f2 100644 --- a/ziti/constants/constants.go +++ b/ziti/constants/constants.go @@ -39,74 +39,75 @@ const ( DefaultZitiEdgeRouterListenerBindPort = "10080" DefaultGetSessionTimeout = 60 * time.Second - DefaultZitiEdgeRouterPort = "3022" - - DefaultZitiControllerName = "controller" - DefaultZitiEdgeAPIPort = "1280" - DefaultZitiEdgeListenerHost = "0.0.0.0" - DefaultZitiControllerListenerAddress = "0.0.0.0" - DefaultZitiControllerPort = "6262" + DefaultZitiEdgeRouterPort = "3022" + DefaultCtrlEdgeAdvertisedPort = "1280" + DefaultCtrlListenerAddress = "0.0.0.0" + DefaultCtrlListenerPort = "6262" ) // Env Var Constants const ( - ZitiHomeVarName = "ZITI_HOME" - 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" - ZitiEdgeRouterRawNameVarName = "ZITI_EDGE_ROUTER_RAWNAME" - ZitiEdgeRouterRawNameVarDescription = "The Edge Router Raw Name" - ZitiEdgeRouterPortVarName = "ZITI_EDGE_ROUTER_PORT" - ZitiEdgeRouterPortVarDescription = "Port of the Ziti Edge Router" - ZitiEdgeCtrlIdentityCertVarName = "ZITI_EDGE_CTRL_IDENTITY_CERT" - ZitiEdgeCtrlIdentityCertVarDescription = "Path to Identity Cert for Ziti Edge Controller" - ZitiEdgeCtrlIdentityServerCertVarName = "ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT" - ZitiEdgeCtrlIdentityServerCertVarDescription = "Path to Identity Server Cert for Ziti Edge Controller" - ZitiEdgeCtrlIdentityKeyVarName = "ZITI_EDGE_CTRL_IDENTITY_KEY" - ZitiEdgeCtrlIdentityKeyVarDescription = "Path to Identity Key for Ziti Edge Controller" - ZitiEdgeCtrlIdentityCAVarName = "ZITI_EDGE_CTRL_IDENTITY_CA" - ZitiEdgeCtrlIdentityCAVarDescription = "Path to Identity CA for Ziti Edge Controller" - ZitiCtrlIdentityCertVarName = "ZITI_CTRL_IDENTITY_CERT" - ZitiCtrlIdentityCertVarDescription = "Path to Identity Cert for Ziti Controller" - ZitiCtrlIdentityServerCertVarName = "ZITI_CTRL_IDENTITY_SERVER_CERT" - ZitiCtrlIdentityServerCertVarDescription = "Path to Identity Server Cert for Ziti Controller" - ZitiCtrlIdentityKeyVarName = "ZITI_CTRL_IDENTITY_KEY" - ZitiCtrlIdentityKeyVarDescription = "Path to Identity Key for Ziti Controller" - ZitiCtrlIdentityCAVarName = "ZITI_CTRL_IDENTITY_CA" - ZitiCtrlIdentityCAVarDescription = "Path to Identity CA for Ziti Controller" - ZitiSigningCertVarName = "ZITI_SIGNING_CERT" - ZitiSigningCertVarDescription = "Path to the Ziti Signing Cert" - ZitiSigningKeyVarName = "ZITI_SIGNING_KEY" - ZitiSigningKeyVarDescription = "Path to the Ziti Signing Key" - ZitiRouterIdentityCertVarName = "ZITI_ROUTER_IDENTITY_CERT" - ZitiRouterIdentityCertVarDescription = "Path to Identity Cert for Ziti Router" - ZitiRouterIdentityServerCertVarName = "ZITI_ROUTER_IDENTITY_SERVER_CERT" - ZitiRouterIdentityServerCertVarDescription = "Path to Identity Server Cert for Ziti Router" - ZitiRouterIdentityKeyVarName = "ZITI_ROUTER_IDENTITY_KEY" - ZitiRouterIdentityKeyVarDescription = "Path to Identity Key for Ziti Router" - ZitiRouterIdentityCAVarName = "ZITI_ROUTER_IDENTITY_CA" - ZitiRouterIdentityCAVarDescription = "Path to Identity CA for Ziti Router" - ZitiCtrlListenerAddressVarName = "ZITI_CTRL_LISTENER_ADDRESS" - ZitiCtrlListenerAddressVarDescription = "The Ziti Controller Listener Address" - ZitiCtrlAdvertisedAddressVarName = "ZITI_CTRL_ADVERTISED_ADDRESS" - ZitiCtrlAdvertisedAddressVarDescription = "The Ziti Controller Advertised Address" - ZitiEdgeCtrlListenerHostPortVarName = "ZITI_CTRL_EDGE_LISTENER_HOST_PORT" - ZitiEdgeCtrlListenerHostPortVarDescription = "Host and port of the Ziti Edge Controller Listener" - ZitiEdgeCtrlAdvertisedHostPortVarName = "ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT" - ZitiEdgeCtrlAdvertisedHostPortVarDescription = "Host and port of the Ziti Edge Controller API" - ZitiEdgeCtrlAdvertisedPortVarName = "ZITI_EDGE_CONTROLLER_PORT" - ZitiEdgeCtrlAdvertisedPortVarDescription = "The advertised port of the edge controller" - ZitiEdgeIdentityEnrollmentDurationVarName = "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" - ZitiEdgeIdentityEnrollmentDurationVarDescription = "The identity enrollment duration in minutes" - ZitiEdgeRouterEnrollmentDurationVarName = "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" - ZitiEdgeRouterEnrollmentDurationVarDescription = "The router enrollment duration in minutes" - ExternalDNSVarName = "EXTERNAL_DNS" - ZitiEdgeRouterIPOverrideVarName = "ZITI_EDGE_ROUTER_IP_OVERRIDE" - ZitiEdgeRouterIPOverrideVarDescription = "Override the default edge router IP with a custom IP, this IP will also be added to the PKI" - ZitiEdgeRouterAdvertisedHostVarName = "ZITI_EDGE_ROUTER_ADVERTISED_HOST" - ZitiEdgeRouterAdvertisedHostVarDescription = "The advertised host of the router" - ZitiEdgeRouterListenerBindPortVarName = "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" - ZitiEdgeRouterListenerBindPortVarDescription = "The port a public router will advertise on" + ZitiHomeVarName = "ZITI_HOME" + ZitiHomeVarDescription = "Root home directory for Ziti related files" + + PkiCtrlCertVarName = "ZITI_PKI_CTRL_CERT" + PkiCtrlCertVarDescription = "Path to Identity Cert for Ziti Controller" + PkiCtrlServerCertVarName = "ZITI_PKI_CTRL_SERVER_CERT" + PkiCtrlServerCertVarDescription = "Path to Identity Server Cert for Ziti Controller" + PkiCtrlKeyVarName = "ZITI_PKI_CTRL_KEY" + PkiCtrlKeyVarDescription = "Path to Identity Key for Ziti Controller" + PkiCtrlCAVarName = "ZITI_PKI_CTRL_CA" + PkiCtrlCAVarDescription = "Path to Identity CA for Ziti Controller" + CtrlListenerAddressVarName = "ZITI_CTRL_LISTENER_ADDRESS" + CtrlListenerAddressVarDescription = "The hostname routers will use to connect to the Ziti Controller" + CtrlListenerPortVarName = "ZITI_CTRL_LISTENER_PORT" + CtrlListenerPortVarDescription = "The port routers will use to connect to the Ziti Controller" + CtrlEdgeApiAddressVarName = "ZITI_CTRL_EDGE_API_ADDRESS" + CtrlEdgeApiAddressVarDescription = "The hostname for the controller's API plane" + CtrlEdgeApiPortVarName = "ZITI_CTRL_EDGE_API_PORT" + CtrlEdgeApiPortVarDescription = "The port for the controller's API plane" + PkiSignerCertVarName = "ZITI_PKI_SIGNER_CERT" + PkiSignerCertVarDescription = "Path to the Ziti Signing Cert" + PkiSignerKeyVarName = "ZITI_PKI_SIGNER_KEY" + PkiSignerKeyVarDescription = "Path to the Ziti Signing Key" + CtrlEdgeIdentityEnrollmentDurationVarName = "ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION" + CtrlEdgeIdentityEnrollmentDurationVarDescription = "The identity enrollment duration in minutes" + CtrlEdgeRouterEnrollmentDurationVarName = "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" + CtrlEdgeRouterEnrollmentDurationVarDescription = "The router enrollment duration in minutes" + CtrlEdgeInterfaceAddressVarName = "ZITI_CTRL_EDGE_INTERFACE_ADDRESS" + CtrlEdgeInterfaceAddressVarDescription = "The interface hostname to bind the controller's edge listener to" + CtrlEdgeInterfacePortVarName = "ZITI_CTRL_EDGE_INTERFACE_PORT" + CtrlEdgeInterfacePortVarDescription = "The interface port to bind the controller's edge listener to" + CtrlEdgeAdvertisedAddressVarName = "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS" + CtrlEdgeAdvertisedAddressVarDescription = "The publicly addressable controller address value" + CtrlEdgeAdvertisedPortVarName = "ZITI_CTRL_EDGE_ADVERTISED_PORT" + CtrlEdgeAdvertisedPortVarDescription = "The publicly addressable controller port value" + CtrlPkiEdgeCertVarName = "ZITI_PKI_EDGE_CERT" + CtrlPkiEdgeCertVarDescription = "Path to Identity Cert for Ziti Edge Controller" + CtrlPkiEdgeServerCertVarName = "ZITI_PKI_EDGE_SERVER_CERT" + CtrlPkiEdgeServerCertVarDescription = "Path to Identity Server Cert for Ziti Edge Controller" + CtrlPkiEdgeKeyVarName = "ZITI_PKI_EDGE_KEY" + CtrlPkiEdgeKeyVarDescription = "Path to Identity Key for Ziti Edge Controller" + CtrlPkiEdgeCAVarName = "ZITI_PKI_EDGE_CA" + CtrlPkiEdgeCAVarDescription = "Path to Identity CA for Ziti Edge Controller" + + ZitiEdgeRouterNameVarName = "ZITI_EDGE_ROUTER_NAME" + ZitiEdgeRouterNameVarDescription = "The Edge Router Raw Name" + ZitiEdgeRouterPortVarName = "ZITI_EDGE_ROUTER_PORT" + ZitiEdgeRouterPortVarDescription = "Port of the Ziti Edge Router" + ZitiRouterIdentityCertVarName = "ZITI_ROUTER_IDENTITY_CERT" + ZitiRouterIdentityCertVarDescription = "Path to Identity Cert for Ziti Router" + ZitiRouterIdentityServerCertVarName = "ZITI_ROUTER_IDENTITY_SERVER_CERT" + ZitiRouterIdentityServerCertVarDescription = "Path to Identity Server Cert for Ziti Router" + ZitiRouterIdentityKeyVarName = "ZITI_ROUTER_IDENTITY_KEY" + ZitiRouterIdentityKeyVarDescription = "Path to Identity Key for Ziti Router" + ZitiRouterIdentityCAVarName = "ZITI_ROUTER_IDENTITY_CA" + ZitiRouterIdentityCAVarDescription = "Path to Identity CA for Ziti Router" + ZitiEdgeRouterIPOverrideVarName = "ZITI_EDGE_ROUTER_IP_OVERRIDE" + ZitiEdgeRouterIPOverrideVarDescription = "Override the default edge router IP with a custom IP, this IP will also be added to the PKI" + ZitiEdgeRouterAdvertisedHostVarName = "ZITI_EDGE_ROUTER_ADVERTISED_HOST" + ZitiEdgeRouterAdvertisedHostVarDescription = "The advertised host of the router" + ZitiEdgeRouterListenerBindPortVarName = "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" + ZitiEdgeRouterListenerBindPortVarDescription = "The port a public router will advertise on" + ExternalDNSVarName = "EXTERNAL_DNS" ) From 46f5987f003c23c4dc0305ff2f4aa760facdb554 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 10 Mar 2023 13:15:45 -0500 Subject: [PATCH 02/26] WIP for upgrading ziti binaries, need to work on another issue for now. Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 07cd5e992..865e38c5b 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -48,7 +48,11 @@ function _setup_ziti_network { if [[ "${ZITI_NETWORK-}" == "" ]]; then ZITI_NETWORK="$(hostname -s)"; export ZITI_NETWORK; else echo "ZITI_NETWORK overridden: ${ZITI_NETWORK}"; fi } -function _get_file_overwrite_permission() { +function _set_ziti_bin_dir { + if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}"; fi +} + +function _get_file_overwrite_permission { local file_path="${1-}" if [[ -f "${file_path}" ]]; then @@ -298,7 +302,7 @@ function setupEnvironment { getLatestZitiVersion # ZITI_BINARIES_FILE & ZITI_BINARIES_VERSION # Must run after the above (dependent on other variables) - if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}"; fi + _set_ziti_bin_dir # Controller Values if [[ "${ZITI_CTRL_NAME-}" == "" ]]; then export ZITI_CTRL_NAME="${ZITI_NETWORK}"; else echo "ZITI_CTRL_NAME overridden: ${ZITI_CTRL_NAME}"; fi @@ -327,7 +331,7 @@ function setupEnvironment { mkdir -p "${ZITI_HOME}/db" mkdir -p "${ZITI_PKI}" - if [[ "${ENV_FILE-}" == "" ]]; then export ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env"; else echo "ENV_FILE overridden: ${ENV_FILE}"; fi + if [[ "${ZITI_ENV_FILE-}" == "" ]]; then export ZITI_ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env"; else echo "ZITI_ENV_FILE overridden: ${ZITI_ENV_FILE}"; fi echo -e "$(GREEN "Your OpenZiti environment has been set up successfully.")" echo "" @@ -339,13 +343,13 @@ function persistEnvironmentValues { # Get the file path filepath="${1-}" if [[ "" == "${filepath}" ]]; then - _check_env_variable ENV_FILE + _check_env_variable ZITI_ENV_FILE retVal=$? if [[ "${retVal}" != 0 ]]; then - echo -e "$(RED " --- persistEnvironment must take a parameter or have ENV_FILE set ---")" + echo -e "$(RED " --- persistEnvironment must take a parameter or have ZITI_ENV_FILE set ---")" return 1 else - filepath="${ENV_FILE}" + filepath="${ZITI_ENV_FILE}" fi fi @@ -583,7 +587,7 @@ function getZiti { default_path="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}" echo -en "The path for ziti binaries has not been set, use the default (${default_path})? (Y/n) " read -r reply - if [[ -z "${reply}" || ${reply} =~ [yY] ]]; then + if [[ -z "${reply}" || ${reply} =~ [yY]* ]]; then echo "INFO: using the default path ${default_path}" ZITI_BIN_DIR="${default_path}" else @@ -625,16 +629,53 @@ function getZiti { echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR}")" return 1 fi - - # Get the download link - zitidl="https://github.com/openziti/ziti/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}" - echo -e 'Downloading '"$(BLUE "${zitidl}")"' to '"$(BLUE "${ziti_binaries_file_abspath}")" - curl -Ls "${zitidl}" -o "${ziti_binaries_file_abspath}" else - echo -e "$(YELLOW 'Binaries already exist, using existing binaries at ')$(BLUE "${ZITI_BIN_DIR}")" - return 0 + echo "ZITI_BIN_DIR/ziti does exist" + # Get the current version and compare with latest + local currentVersion + currentVersion="v0.27.4" # "$("${ZITI_BIN_DIR}"/ziti -v) " + if [[ "${ZITI_BINARIES_VERSION}" != "${currentVersion}" ]]; then + # Prompt user for new download + echo -en "There is a newer version of OpenZiti, would you like to download it (Y/n)?" + read -r reply + if [[ -z "${reply}" || "${reply}" == [Yy]* ]]; then + # Update the ZITI_BIN_DIR path to point to the latest version + unset ZITI_BIN_DIR + _set_ziti_bin_dir + # Make the directory + mkdir -p "${ZITI_BIN_DIR}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR}")" + return 1 + fi + + # Update the .env file with the new downloaded version + if ! test -f "${ZITI_ENV_FILE}"; then + echo -e " * $(YELLOW "WARN: The OpenZiti Environment file could not be found to update ziti binary related paths")" + else + sed "s/export ZITI_BIN_DIR=.*/export ZITI_BIN_DIR=${ZITI_BIN_DIR}/g" + sed "s/export ZITI_BINARIES_VERSION=.*/export ZITI_BINARIES_VERSION=${ZITI_BINARIES_VERSION}/g" + sed "s/export ZITI_BINARIES_FILE=.*/export ZITI_BINARIES_FILE=${ZITI_BINARIES_FILE}/g" + sed "s/export ZITI_BINARIES_FILE_ABSPATH=.*/d" + fi + + echo -e "$(YELLOW 'Getting latest binaries ')$(BLUE "${ZITI_BIN_DIR}")" + else + echo -e "$(YELLOW 'Using existing binaries at ')$(BLUE "${ZITI_BIN_DIR}")" + return 0 + fi + else + echo -e "$(YELLOW 'Latest binaries already exist, using existing binaries at ')$(BLUE "${ZITI_BIN_DIR}")" + return 0 + fi fi + # Get the download link + zitidl="https://github.com/openziti/ziti/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}" + echo -e 'Downloading '"$(BLUE "${zitidl}")"' to '"$(BLUE "${ziti_binaries_file_abspath}")" + curl -Ls "${zitidl}" -o "${ziti_binaries_file_abspath}" + # Unzip the files tar -xf "${ziti_binaries_file_abspath}" --directory "${ZITI_BIN_DIR}" From 3e027860055218a7aeb279798539c5c367a7086b Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 24 Mar 2023 13:18:32 -0400 Subject: [PATCH 03/26] Adding a migration path for quickstart cleanup Closes #1030 Signed-off-by: gberl002 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d20328161..15927e2f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * Makes inspect CLI more discoverable by adding subcommands for inspectable values * Adds new inspection allowing configs to be retrieved: `ziti fabric inspect config` +* Quickstart environment variable names have been cleaned up. + * IMPORTANT: If you update your OpenZiti binaries to this version or later (which can be done easily with the `getZiti()` function, you will need to migrate any existing network that has been developed using OpenZiti v0.27.5 or earlier binaries as the new binaries will expect the new environment variable names. A function `performMigration()` has been provided in the `ziti-cli-script.sh` for this purpose. Simply source the latest `ziti-cli-script.sh`, and your current network's .env file, then run `performMigration()` to update environment variable name references. If the migration process cannot find your existing environment file in the default location, you will need to provide the path to the migration function, ex: `performMigration ` ## Component Updates and Bug Fixes @@ -26,6 +28,7 @@ * github.com/openziti/transport/v2: [v2.0.51 -> v2.0.52](https://github.com/openziti/transport/compare/v2.0.51...v2.0.52) * github.com/openziti/ziti: [v0.27.5 -> v0.27.6](https://github.com/openziti/ziti/compare/v0.27.5...v0.27.6) * [Issue #1031](https://github.com/openziti/ziti/issues/1031) - Fixed quickstart bug with arm and arm64 ambiguity when running quickstart on arm architecture + * [Issue #1030](https://github.com/openziti/ziti/issues/1030) - Provide an upgrade path for quickstart cleanup # Release 0.27.5 From 1f2f9c8ce03c5c7e95803b010b93e69476042906 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 24 Mar 2023 13:25:51 -0400 Subject: [PATCH 04/26] This includes the new function for migrating Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 83 +++++++++++++++++-- 1 file changed, 75 insertions(+), 8 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 865e38c5b..a53cdc116 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -44,6 +44,12 @@ function _setup_ziti_home { if [[ "${ZITI_HOME-}" == "" ]]; then export ZITI_HOME="${HOME}/.ziti/quickstart/${ZITI_NETWORK-}"; else echo "ZITI_HOME overridden: ${ZITI_HOME}"; fi } +function _setup_ziti_env_path { + _setup_ziti_network + _setup_ziti_home + if [[ "${ZITI_ENV_FILE-}" == "" ]]; then export ZITI_ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env"; else echo "ZITI_ENV_FILE overridden: ${ZITI_ENV_FILE}"; fi +} + function _setup_ziti_network { if [[ "${ZITI_NETWORK-}" == "" ]]; then ZITI_NETWORK="$(hostname -s)"; export ZITI_NETWORK; else echo "ZITI_NETWORK overridden: ${ZITI_NETWORK}"; fi } @@ -312,15 +318,15 @@ function setupEnvironment { if [[ "${ZITI_PKI_CTRL_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_ROOTCA_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-root-ca"; else echo "ZITI_PKI_CTRL_ROOTCA_NAME overridden: ${ZITI_PKI_CTRL_ROOTCA_NAME}"; fi if [[ "${ZITI_PKI_CTRL_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_INTERMEDIATE_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-intermediate"; else echo "ZITI_PKI_CTRL_INTERMEDIATE_NAME overridden: ${ZITI_PKI_CTRL_INTERMEDIATE_NAME}"; fi if [[ "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_EDGE_ROOTCA_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-root-ca"; else echo "ZITI_PKI_CTRL_EDGE_ROOTCA_NAME overridden: ${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}"; fi - if [[ "${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-intermediate"; else echo "ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME overridden: ${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}"; fi + if [[ "${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-intermediate"; else echo "ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME overridden: ${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}"; fi if [[ "${ZITI_PKI_CTRL_SERVER_CERT-}" == "" ]]; then export ZITI_PKI_CTRL_SERVER_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.chain.pem"; else echo "ZITI_PKI_CTRL_SERVER_CERT overridden: ${ZITI_PKI_CTRL_SERVER_CERT}"; fi if [[ "${ZITI_PKI_CTRL_KEY-}" == "" ]]; then export ZITI_PKI_CTRL_KEY="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.key"; else echo "ZITI_PKI_CTRL_KEY overridden: ${ZITI_PKI_CTRL_KEY}"; fi if [[ "${ZITI_PKI_CTRL_CA-}" == "" ]]; then export ZITI_PKI_CTRL_CA="${ZITI_PKI}/cas.pem"; else echo "ZITI_PKI_CTRL_CA overridden: ${ZITI_PKI_CTRL_CA}"; fi if [[ "${ZITI_PKI_CTRL_CERT-}" == "" ]]; then export ZITI_PKI_CTRL_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-client.cert"; else echo "ZITI_PKI_CTRL_CERT overridden: ${ZITI_PKI_CTRL_CERT}"; fi - if [[ "${ZITI_PKI_EDGE_CERT-}" == "" ]]; then export ZITI_PKI_EDGE_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-client.cert"; else echo "ZITI_PKI_EDGE_CERT overridden: ${ZITI_PKI_EDGE_CERT}"; fi - if [[ "${ZITI_PKI_EDGE_SERVER_CERT}" == "" ]]; then export ZITI_PKI_EDGE_SERVER_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.chain.pem"; else echo "ZITI_PKI_EDGE_SERVER_CERT overridden: ${ZITI_PKI_EDGE_SERVER_CERT}"; fi - if [[ "${ZITI_PKI_EDGE_KEY}" == "" ]]; then export ZITI_PKI_EDGE_KEY="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.key"; else echo "ZITI_PKI_EDGE_KEY overridden: ${ZITI_PKI_EDGE_KEY}"; fi - if [[ "${ZITI_PKI_EDGE_CA}" == "" ]]; then export ZITI_PKI_EDGE_CA="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}.cert"; else echo "ZITI_PKI_EDGE_CA overridden: ${ZITI_PKI_EDGE_CA}"; fi + if [[ "${ZITI_PKI_EDGE_CERT-}" == "" ]]; then export ZITI_PKI_EDGE_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-client.cert"; else echo "ZITI_PKI_EDGE_CERT overridden: ${ZITI_PKI_EDGE_CERT}"; fi + if [[ "${ZITI_PKI_EDGE_SERVER_CERT}" == "" ]]; then export ZITI_PKI_EDGE_SERVER_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.chain.pem"; else echo "ZITI_PKI_EDGE_SERVER_CERT overridden: ${ZITI_PKI_EDGE_SERVER_CERT}"; fi + if [[ "${ZITI_PKI_EDGE_KEY}" == "" ]]; then export ZITI_PKI_EDGE_KEY="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.key"; else echo "ZITI_PKI_EDGE_KEY overridden: ${ZITI_PKI_EDGE_KEY}"; fi + if [[ "${ZITI_PKI_EDGE_CA}" == "" ]]; then export ZITI_PKI_EDGE_CA="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert"; else echo "ZITI_PKI_EDGE_CA overridden: ${ZITI_PKI_EDGE_CA}"; fi # Router Values if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then ZITI_EDGE_ROUTER_NAME="${ZITI_NETWORK}-edge-router"; else echo "ZITI_EDGE_ROUTER_NAME overridden: ${ZITI_EDGE_ROUTER_NAME}"; fi @@ -331,7 +337,7 @@ function setupEnvironment { mkdir -p "${ZITI_HOME}/db" mkdir -p "${ZITI_PKI}" - if [[ "${ZITI_ENV_FILE-}" == "" ]]; then export ZITI_ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env"; else echo "ZITI_ENV_FILE overridden: ${ZITI_ENV_FILE}"; fi + _setup_ziti_env_path echo -e "$(GREEN "Your OpenZiti environment has been set up successfully.")" echo "" @@ -700,7 +706,7 @@ function createPki { local retVal pki_allow_list_dns pki_allow_list_ip ZITI_SPURIOUS_INTERMEDIATE _check_env_variable ZITI_PKI_CTRL_ROOTCA_NAME ZITI_PKI_CTRL_EDGE_ROOTCA_NAME ZITI_PKI_SIGNER_ROOTCA_NAME \ ZITI_PKI_SIGNER_INTERMEDIATE_NAME ZITI_PKI_CTRL_INTERMEDIATE_NAME \ - ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME + ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -713,7 +719,7 @@ function createPki { ZITI_SPURIOUS_INTERMEDIATE="${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}_spurious_intermediate" _pki_create_intermediate "${ZITI_PKI_CTRL_ROOTCA_NAME}" "${ZITI_PKI_CTRL_INTERMEDIATE_NAME}" 1 - _pki_create_intermediate "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}" "${ZITI_PKI_CTRL_EDGE_INTERMEDATE_NAME}" 1 + _pki_create_intermediate "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}" "${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}" 1 _pki_create_intermediate "${ZITI_PKI_SIGNER_ROOTCA_NAME}" "${ZITI_SPURIOUS_INTERMEDIATE}" 2 _pki_create_intermediate "${ZITI_SPURIOUS_INTERMEDIATE}" "${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}" 1 @@ -1408,6 +1414,67 @@ function _portCheck { return 0 } +# A function for upgrading an existing (<=0.27.5) network to a later (>0.27.5) network +# The binary, which relies on environment variables were extensively altered and will not work on an existing network +# without migrating it first +function performMigration { + if [[ "${1-}" == "" ]]; then + # Check if the env file is in the expected location + _setup_ziti_env_path + if ! test -f "${ZITI_ENV_FILE}"; then + echo -e "performMigration Usage: performMigration " + return 0 + fi + else + ZITI_ENV_FILE="${1-}" + fi + + # Replace old Env Vars with new ones + # NOTE: the '' after -i is required for Mac, otherwise an error is thrown + sed -i '' 's/ZITI_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CONTROLLER_INTERMEDIATE_NAME/ZITI_CTRL_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CONTROLLER_RAWNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CONTROLLER_ROOTCA_NAME/ZITI_CTRL_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_ADVERTISED_ADDRESS/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_EDGE_PORT/ZITI_CTRL_EDGE_ADVERTISED_PORT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_IDENTITY_CA/ZITI_PKI_CTRL_CA/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_IDENTITY_CERT/ZITI_PKI_CTRL_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_IDENTITY_KEY/ZITI_PKI_CTRL_KEY/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_IDENTITY_SERVER_CERT/ZITI_PKI_CTRL_SERVER_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_PORT/ZITI_CTRL_LISTENER_PORT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_CA/ZITI_PKI_EDGE_CA/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_CERT/ZITI_PKI_EDGE_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_KEY/ZITI_PKI_EDGE_KEY/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_SERVER_CERT/ZITI_PKI_EDGE_SERVER_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME/ZITI_CTRL_EDGE_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_PORT/ZITI_CTRL_EDGE_ADVERTISED_PORT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_RAWNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_ROOTCA_NAME/ZITI_CTRL_EDGE_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CA/ZITI_CTRL_WEB_IDENTITY_CA/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CERT/ZITI_CTRL_WEB_IDENTITY_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_KEY/ZITI_CTRL_WEB_IDENTITY_KEY/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT/ZITI_CTRL_WEB_IDENTITY_SERVER_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_ROUTER_RAWNAME/ZITI_EDGE_ROUTER_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_PKI_OS_SPECIFIC/ZITI_PKI/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_SIGNING_CERT/ZITI_PKI_SIGNER_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_SIGNING_KEY/ZITI_PKI_SIGNER_KEY/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_ROUTER_HOSTNAME/ZITI_ROUTER_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" + echo "export ZITI_CTRL_NAME=${ZITI_NETWORK}" >> "${ZITI_ENV_FILE}" + + # Update the necessary ziti binary references (others are not needed or are overwritten later) + if [[ "${ZITI_BIN_DIR-}" != "" ]]; then + sed '/^export ZITI_BIN_DIR=/d' "${ZITI_ENV_FILE}" + echo "export ZITI_BIN_DIR=${ZITI_BIN_DIR}" >> "${ZITI_ENV_FILE}" + fi + if [[ "${ZITI_BINARIES_VERSION-}" != "" ]]; then + sed '/^export ZITI_BINARIES_VERSION=/d' "${ZITI_ENV_FILE}" + echo "export ZITI_BINARIES_VERSION=${ZITI_BINARIES_VERSION}" >> "${ZITI_ENV_FILE}" + fi + + echo -e "$(GREEN "SUCCESS Your Environment file has been updated, please use source the file for the latest values")" +} + # ******* Deprecated functions, refer to new functions ********** function deprecationMessage { echo -e "$(YELLOW "WARNING The ${1} function has been deprecated, please use ${2} going forward")" From 9705e73eb226abb7db7aec4c08055a129ad40c41 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 24 Mar 2023 13:29:58 -0400 Subject: [PATCH 05/26] Removing debugging code left in Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index a53cdc116..cd4ee743d 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -639,7 +639,7 @@ function getZiti { echo "ZITI_BIN_DIR/ziti does exist" # Get the current version and compare with latest local currentVersion - currentVersion="v0.27.4" # "$("${ZITI_BIN_DIR}"/ziti -v) " + currentVersion="$("${ZITI_BIN_DIR}"/ziti -v) " if [[ "${ZITI_BINARIES_VERSION}" != "${currentVersion}" ]]; then # Prompt user for new download echo -en "There is a newer version of OpenZiti, would you like to download it (Y/n)?" From efcbbf4eba7c54fe73d5fcca901be9c6a76c96a3 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Mon, 27 Mar 2023 15:25:01 -0400 Subject: [PATCH 06/26] Adding some more helpful info after express install completes Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 07cd5e992..bd3b21c6c 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -979,6 +979,9 @@ function expressInstall { echo "" echo -e "$(GREEN "Congratulations. Express setup complete!")" + echo -e "Your ZITI_HOME is located here: $(BLUE "${ZITI_HOME}")" + echo -e "Your admin password is: $(BLUE "${ZITI_PWD}")" + echo "" echo -e "Start your Ziti Controller by running the function: $(BLUE "startController")" echo -e "Start your Ziti Edge Router by running : $(BLUE 'startRouter')" echo "" From 46eeff109179e6e7c686674253a023e170e5eb63 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Mon, 24 Apr 2023 12:33:45 -0400 Subject: [PATCH 07/26] Moving issue fix to the correct version Signed-off-by: gberl002 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77cbd4a3b..950e894b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [Issue #1013](https://github.com/openziti/ziti/issues/1013) - Stop regenerating a new password with each container 'down/up' cycle * Quickstart environment variable names have been cleaned up. * IMPORTANT: If you update your OpenZiti binaries to this version or later (which can be done easily with the `getZiti()` function, you will need to migrate any existing network that has been developed using OpenZiti v0.27.5 or earlier binaries as the new binaries will expect the new environment variable names. A function `performMigration()` has been provided in the `ziti-cli-script.sh` for this purpose. Simply source the latest `ziti-cli-script.sh`, and your current network's .env file, then run `performMigration()` to update environment variable name references. If the migration process cannot find your existing environment file in the default location, you will need to provide the path to the migration function, ex: `performMigration ` + * [Issue #1030](https://github.com/openziti/ziti/issues/1030) - Provide an upgrade path for quickstart cleanup * Added AMQP event writter for events # Release 0.27.9 @@ -122,7 +123,6 @@ * [Issue #1041](https://github.com/openziti/ziti/issues/1041) - Add ziti compact command to CLI * [Issue #1032](https://github.com/openziti/ziti/issues/1032) - ziti edge create service fails silently if config names don't exist * [Issue #1031](https://github.com/openziti/ziti/issues/1031) - Fixed quickstart bug with arm and arm64 ambiguity when running quickstart on arm architecture - * [Issue #1030](https://github.com/openziti/ziti/issues/1030) - Provide an upgrade path for quickstart cleanup # Release 0.27.5 From a3d3b0669e5cd20ea89a00983ab8e3ed23f1fb96 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Mon, 1 May 2023 15:53:04 -0400 Subject: [PATCH 08/26] Addressing some github issues and todo tasks Adding close tags for entire PR, some were missed in previous commits closes #986 closes #920 closes #779 closes #761 closes #650 Signed-off-by: gberl002 --- quickstart/docker/.env | 4 ++-- quickstart/docker/image/ziti-cli-functions.sh | 19 ++++++++----------- quickstart/local/add-zcat.sh | 2 +- quickstart/local/newid.sh | 2 +- quickstart/local/test-ziti.sh | 2 +- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/quickstart/docker/.env b/quickstart/docker/.env index 487b63931..1491fa225 100644 --- a/quickstart/docker/.env +++ b/quickstart/docker/.env @@ -9,7 +9,7 @@ ZITI_EDGE_ROUTER_ENROLLMENT_DURATION=10080 # controller address/port information ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=ziti-edge-controller -#ZITI_CTRL_EDGE_ADVERTISED_PORT=8441 +#ZITI_CTRL_EDGE_ADVERTISED_PORT=1280 #ZITI_CTRL_WEB_LISTENER_PORT=8440 # Leave password blank to have a unique value generated or set the password explicitly @@ -19,5 +19,5 @@ ZITI_PWD= # router address/port information #ZITI_EDGE_ROUTER_NAME=advertised.address -#ZITI_EDGE_ROUTER_PORT=8442 +#ZITI_EDGE_ROUTER_PORT=3022 #ZITI_EDGE_ROUTER_IP_OVERRIDE=172.17.0.1 diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 769e409c6..ab5574fe8 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -639,7 +639,7 @@ function getZiti { echo "ZITI_BIN_DIR/ziti does exist" # Get the current version and compare with latest local currentVersion - currentVersion="$("${ZITI_BIN_DIR}"/ziti -v) " + currentVersion="$("${ZITI_BIN_DIR}"/ziti --version) " if [[ "${ZITI_BINARIES_VERSION}" != "${currentVersion}" ]]; then # Prompt user for new download echo -en "There is a newer version of OpenZiti, would you like to download it (Y/n)?" @@ -741,7 +741,6 @@ function createPki { # Creates a controller config file function createControllerConfig { local controller_name retVal file_path output_file - # TODO: allow passing in of env file # Allow controller name to be passed in as arg controller_name="${1-}" # If no controller name provided and env var is not set, prompt user for a controller name @@ -878,6 +877,12 @@ function _create_router_config { # Used to create a router, router config, then enroll the router. function addRouter { local router_name router_type retVal + # Make sure necessary env variables are set + _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_USER ZITI_PWD + retVal=$? + if [ $retVal -ne 0 ]; then + return 1 + fi # Allow router name and type to be passed in as arg router_name="${1-}" router_type="${2-}" @@ -897,15 +902,7 @@ function addRouter { router_name="${ZITI_EDGE_ROUTER_NAME}" fi - # Make sure necessary env variables are set - _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_USER ZITI_PWD - retVal=$? - if [ $retVal -ne 0 ]; then - return 1 - fi - # Create router - # TODO: Add prompt to user to delete an existing router if it exists zitiLogin "${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${router_name}" "${ZITI_BIN_DIR-}/ziti" edge create edge-router "${router_name}" -o "${ZITI_HOME}/${router_name}.jwt" -t -a "${router_type}" @@ -917,7 +914,7 @@ function addRouter { "${ZITI_BIN_DIR-}/ziti" router enroll "${ZITI_HOME}/${router_name}.yaml" --jwt "${ZITI_HOME}/${router_name}.jwt" &> "${ZITI_HOME}/${router_name}.enrollment.log" retVal=$? if [[ "${retVal}" != 0 ]]; then - echo -e "$(RED " --- There was an error during router enrollment ---")" + echo -e "$(RED " --- There was an error during router enrollment, check the logs at ${ZITI_HOME}/${router_name}.enrollment.log ---")" return 1 else echo -e "$(GREEN "Enrollment successful")" diff --git a/quickstart/local/add-zcat.sh b/quickstart/local/add-zcat.sh index eb2933b78..e0e242069 100644 --- a/quickstart/local/add-zcat.sh +++ b/quickstart/local/add-zcat.sh @@ -1,4 +1,4 @@ -ziti edge login "${ZITI_EDGE_CONTROLLER_API}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" +ziti edge login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" ziti edge delete service zcatsvc ziti edge delete config zcatconfig diff --git a/quickstart/local/newid.sh b/quickstart/local/newid.sh index 54f063ab1..95ae77b39 100755 --- a/quickstart/local/newid.sh +++ b/quickstart/local/newid.sh @@ -1,7 +1,7 @@ suffix=$(date +"%b-%d-%H%M") idname="User${suffix}" -ziti edge login "${ZITI_EDGE_CONTROLLER_API}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" +ziti edge login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" ziti edge delete identity "${idname}" ziti edge create identity device "${idname}" -o "${ZITI_HOME}/test_identity".jwt diff --git a/quickstart/local/test-ziti.sh b/quickstart/local/test-ziti.sh index 62254f97e..8e90825c2 100755 --- a/quickstart/local/test-ziti.sh +++ b/quickstart/local/test-ziti.sh @@ -1,4 +1,4 @@ -ziti edge controller login "${ZITI_EDGE_CONTROLLER_API}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" +ziti edge controller login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" ziti edge delete service netcatsvc ziti edge delete service zcatsvc From adc0670fb51ba6c244e22805811ebbe6231d097b Mon Sep 17 00:00:00 2001 From: gberl002 Date: Mon, 1 May 2023 16:39:20 -0400 Subject: [PATCH 09/26] Removing environment variable that is no longer used Signed-off-by: gberl002 --- quickstart/docker/.env | 1 - 1 file changed, 1 deletion(-) diff --git a/quickstart/docker/.env b/quickstart/docker/.env index 1491fa225..72dd4ecde 100644 --- a/quickstart/docker/.env +++ b/quickstart/docker/.env @@ -10,7 +10,6 @@ ZITI_EDGE_ROUTER_ENROLLMENT_DURATION=10080 # controller address/port information ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=ziti-edge-controller #ZITI_CTRL_EDGE_ADVERTISED_PORT=1280 -#ZITI_CTRL_WEB_LISTENER_PORT=8440 # Leave password blank to have a unique value generated or set the password explicitly ZITI_PWD= From 4f6127a564978c9596535d36a680d1cacd907585 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Thu, 4 May 2023 15:12:56 -0400 Subject: [PATCH 10/26] Fixing some bugs in quickstart cli Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index ab5574fe8..0f08db9f4 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -298,7 +298,7 @@ function setupEnvironment { if [[ "${ZITI_PKI-}" == "" ]]; then export ZITI_PKI="${ZITI_HOME}/pki"; else echo "ZITI_PKI overridden: ${ZITI_PKI}"; fi if [[ "${ZITI_PKI_SIGNER_CERT_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_CERT_NAME="${ZITI_NETWORK}-signing"; else echo "ZITI_PKI_SIGNER_CERT_NAME overridden: ${ZITI_PKI_SIGNER_CERT_NAME}"; fi if [[ "${ZITI_PKI_SIGNER_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_ROOTCA_NAME="${ZITI_PKI_SIGNER_CERT_NAME}-root-ca"; else echo "ZITI_PKI_SIGNER_ROOTCA_NAME overridden: ${ZITI_PKI_SIGNER_ROOTCA_NAME}"; fi - if [[ "${ZITI_PKI_SIGNER_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_INTERMEDIATE_NAME="${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}-intermediate"; else echo "ZITI_PKI_SIGNER_INTERMEDIATE_NAME overridden: ${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}"; fi + if [[ "${ZITI_PKI_SIGNER_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_INTERMEDIATE_NAME="${ZITI_PKI_SIGNER_CERT_NAME}-intermediate"; else echo "ZITI_PKI_SIGNER_INTERMEDIATE_NAME overridden: ${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}"; fi if [[ "${ZITI_PKI_SIGNER_CERT}" == "" ]]; then export ZITI_PKI_SIGNER_CERT="${ZITI_PKI}/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}/certs/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}.cert"; else echo "ZITI_PKI_SIGNER_CERT overridden: ${ZITI_PKI_SIGNER_CERT}"; fi if [[ "${ZITI_PKI_SIGNER_KEY}" == "" ]]; then export ZITI_PKI_SIGNER_KEY="${ZITI_PKI}/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}/keys/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}.key"; else echo "ZITI_PKI_SIGNER_KEY overridden: ${ZITI_PKI_SIGNER_KEY}"; fi @@ -329,7 +329,7 @@ function setupEnvironment { if [[ "${ZITI_PKI_EDGE_CA}" == "" ]]; then export ZITI_PKI_EDGE_CA="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert"; else echo "ZITI_PKI_EDGE_CA overridden: ${ZITI_PKI_EDGE_CA}"; fi # Router Values - if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then ZITI_EDGE_ROUTER_NAME="${ZITI_NETWORK}-edge-router"; else echo "ZITI_EDGE_ROUTER_NAME overridden: ${ZITI_EDGE_ROUTER_NAME}"; fi + if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then export ZITI_EDGE_ROUTER_NAME="${ZITI_NETWORK}-edge-router"; else echo "ZITI_EDGE_ROUTER_NAME overridden: ${ZITI_EDGE_ROUTER_NAME}"; fi if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; else echo "ZITI_EDGE_ROUTER_PORT overridden: ${ZITI_EDGE_ROUTER_PORT}"; fi # Set up directories From 54648a59a62c3ea938c36574a430fd69a4a3e96c Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 5 May 2023 16:22:18 -0400 Subject: [PATCH 11/26] Fixing some bugs in docker quickstart Signed-off-by: gberl002 --- quickstart/docker/.env | 3 ++- quickstart/docker/image/run-controller.sh | 8 +++----- quickstart/docker/image/run-router.sh | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/quickstart/docker/.env b/quickstart/docker/.env index 72dd4ecde..0a010e966 100644 --- a/quickstart/docker/.env +++ b/quickstart/docker/.env @@ -7,7 +7,8 @@ ZITI_VERSION=latest ZITI_EDGE_IDENTITY_ENROLLMENT_DURATION=10080 ZITI_EDGE_ROUTER_ENROLLMENT_DURATION=10080 -# controller address/port information +# controller name, address/port information +ZITI_CTRL_NAME=ziti-controller ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=ziti-edge-controller #ZITI_CTRL_EDGE_ADVERTISED_PORT=1280 diff --git a/quickstart/docker/image/run-controller.sh b/quickstart/docker/image/run-controller.sh index 48101f525..df3a61680 100755 --- a/quickstart/docker/image/run-controller.sh +++ b/quickstart/docker/image/run-controller.sh @@ -1,5 +1,4 @@ #!/bin/bash -echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS is ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" ziti_controller_cfg="${ZITI_HOME}/ziti-edge-controller.yaml" export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=ziti-edge-controller @@ -12,10 +11,9 @@ if [ ! -f "${ZITI_HOME}/access-control.init" ]; then persistEnvironmentValues fi . ${ZITI_HOME}/ziti.env -echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS is ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + # create pki createPki -echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS is ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" if [ ! -f "${ziti_controller_cfg}" ]; then echo " " echo "${ziti_controller_cfg} doesn't exist. Generating config file" @@ -29,9 +27,9 @@ else fi # initialize the database with the admin user: -"${ZITI_BIN_DIR}/ziti" controller edge init "${ZITI_HOME}/ziti-edge-controller.yaml" -u "${ZITI_USER}" -p "${ZITI_PWD}" +"${ZITI_BIN_DIR}/ziti" controller edge init "${ZITI_HOME}/${ZITI_CTRL_NAME}.yaml" -u "${ZITI_USER}" -p "${ZITI_PWD}" # create a place for the internal db mkdir -p $ZITI_HOME/db -"${ZITI_BIN_DIR}/ziti" controller run "${ZITI_HOME}/ziti-edge-controller.yaml" +"${ZITI_BIN_DIR}/ziti" controller run "${ZITI_HOME}/${ZITI_CTRL_NAME}.yaml" diff --git a/quickstart/docker/image/run-router.sh b/quickstart/docker/image/run-router.sh index 4e2df0fdf..0cb23b18b 100755 --- a/quickstart/docker/image/run-router.sh +++ b/quickstart/docker/image/run-router.sh @@ -53,5 +53,5 @@ else echo "" fi -"${ZITI_BIN_DIR}/ziti router" run "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml" > "${ZITI_HOME}/ziti-${ZITI_ROUTER_ADVERTISED_ADDRESS}.log" +"${ZITI_BIN_DIR}/ziti" router run "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml" > "${ZITI_HOME}/ziti-${ZITI_ROUTER_ADVERTISED_ADDRESS}.log" From 6e5b97a6a75b22885472da9c25546deb65e0d91d Mon Sep 17 00:00:00 2001 From: gberl002 Date: Thu, 11 May 2023 10:34:30 -0400 Subject: [PATCH 12/26] Updated environment variable references in newly created files Fixed bug with PKI generation when using EXTERNAL_DNS Fixed other environment variable name related bugs Signed-off-by: gberl002 --- doc/003-local-deploy.md | 14 ++--- .../docker/image/run-router-external.sh | 54 +++++++++---------- quickstart/docker/image/ziti-cli-functions.sh | 24 ++++----- quickstart/local/add-zcat.sh | 2 +- quickstart/local/newid.sh | 2 +- quickstart/local/test-ziti.sh | 2 +- quickstart/test/quickstart_test.go | 4 +- 7 files changed, 49 insertions(+), 53 deletions(-) diff --git a/doc/003-local-deploy.md b/doc/003-local-deploy.md index 6dc4d6ed4..a4d9fc2c0 100644 --- a/doc/003-local-deploy.md +++ b/doc/003-local-deploy.md @@ -36,12 +36,12 @@ ZITI_HOME=. \ ZITI_CTRL_LISTENER_ADDRESS=127.0.0.1 \ ZITI_CTRL_EDGE_LISTENER_HOST_PORT=127.0.0.1:1280 \ ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT=127.0.0.1:1280 \ -ZITI_CTRL_IDENTITY_CERT=./etc/ca/intermediate/certs/ctrl-client.cert.pem \ -ZITI_CTRL_IDENTITY_SERVER_CERT=./etc/ca/intermediate/certs/ctrl-server.cert.pem \ -ZITI_CTRL_IDENTITY_KEY=./etc/ca/intermediate/private/ctrl.key.pem \ -ZITI_CTRL_IDENTITY_CA=./etc/ca/intermediate/certs/ca-chain.cert.pem \ -ZITI_SIGNING_CERT=./etc/ca/intermediate/certs/intermediate.cert.pem \ -ZITI_SIGNING_KEY=./etc/ca/intermediate/private/intermediate.key.decrypted.pem \ +ZITI_PKI_CTRL_CERT=./etc/ca/intermediate/certs/ctrl-client.cert.pem \ +ZITI_PKI_CTRL_SERVER_CERT=./etc/ca/intermediate/certs/ctrl-server.cert.pem \ +ZITI_PKI_CTRL_KEY=./etc/ca/intermediate/private/ctrl.key.pem \ +ZITI_PKI_CTRL_CA=./etc/ca/intermediate/certs/ca-chain.cert.pem \ +ZITI_PKI_SIGNER_CERT=./etc/ca/intermediate/certs/intermediate.cert.pem \ +ZITI_PKI_SIGNER_KEY=./etc/ca/intermediate/private/intermediate.key.decrypted.pem \ ziti create config controller \ --output ./db/ctrl-config.yml ``` @@ -82,7 +82,7 @@ Generate a configuration file for router01. ```bash ZITI_HOME=./db \ -ZITI_CTRL_ADVERTISED_ADDRESS=127.0.0.1 \ +ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=127.0.0.1 \ ZITI_EDGE_ROUTER_NAME=localhost \ ziti create config router edge \ --routerName router01 \ diff --git a/quickstart/docker/image/run-router-external.sh b/quickstart/docker/image/run-router-external.sh index 25f5814ea..208dc0699 100755 --- a/quickstart/docker/image/run-router-external.sh +++ b/quickstart/docker/image/run-router-external.sh @@ -7,81 +7,81 @@ sleep 5 . "${ZITI_SCRIPTS}/ziti-cli-functions.sh" # If we have not defined these, then no point going further - so dont -if [[ "${ZITI_EDGE_ROUTER_HOSTNAME}" == "" ]]; then echo "ERROR: Missing ZITI_EDGE_ROUTER_HOSTNAME definition" >&2; exit; fi -export ZITI_EDGE_ROUTER_RAWNAME=${ZITI_EDGE_ROUTER_RAWNAME_OVERRIDE} +if [[ "${ZITI_ROUTER_ADVERTISED_ADDRESS}" == "" ]]; then echo "ERROR: Missing ZITI_ROUTER_ADVERTISED_ADDRESS definition" >&2; exit; fi +export ZITI_EDGE_ROUTER_NAME=${ZITI_EDGE_ROUTER_NAME_OVERRIDE} -echo "ZITI_EDGE_ROUTER_HOSTNAME = ${ZITI_EDGE_ROUTER_HOSTNAME}" +echo "ZITI_ROUTER_ADVERTISED_ADDRESS = ${ZITI_ROUTER_ADVERTISED_ADDRESS}" # If we dont have a key file, then we assume we haven't enrolled, so lets do that -if [ ! -f ${ZITI_EDGE_ROUTER_HOSTNAME}.jwt ]; then +if [ ! -f ${ZITI_ROUTER_ADVERTISED_ADDRESS}.jwt ]; then # May have been a bad attempt before, so lets clean up - rm -f ${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}* + rm -f ${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}* # If we have override variables then override the base variable # This is required as the .bashrc loads the env file which clobbers passed in varibles if [[ "${ZITI_EDGE_ROUTER_RAWNAME_OVERRIDE}" == "" ]]; then echo "ERROR: Missing ZITI_EDGE_ROUTER_RAWNAME_OVERRIDE definition" >&2; exit; fi # May have been a bad attempt before, so lets clean up - rm -f ${ZITI_HOME}/${ZITI_EDGE_ROUTER_RAWNAME}* + rm -f ${ZITI_HOME}/${ZITI_EDGE_ROUTER_NAME}* - if [[ ${ZITI_CTRL_ADVERTISED_ADDRESS_OVERRIDE} != "" ]]; then export ZITI_CTRL_ADVERTISED_ADDRESS=${ZITI_CTRL_ADVERTISED_ADDRESS_OVERRIDE}; fi + if [[ ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS} != "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS=${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}; fi if [[ ${ZITI_USER_OVERRIDE} != "" ]]; then export ZITI_USER=${ZITI_USER_OVERRIDE}; fi if [[ ${ZITI_PWD_OVERRIDE} != "" ]]; then export ZITI_PWD=${ZITI_PWD_OVERRIDE}; fi - if [[ ${ZITI_EDGE_CONTROLLER_PORT_OVERRIDE} != "" ]]; then export ZITI_EDGE_CONTROLLER_PORT=${ZITI_EDGE_CONTROLLER_PORT_OVERRIDE}; fi - if [[ ${ZITI_EDGE_ROUTER_HOSTNAME} == "" ]]; then export ZITI_EDGE_ROUTER_HOSTNAME=${ZITI_EDGE_ROUTER_RAWNAME}; fi + if [[ ${ZITI_EDGE_CONTROLLER_PORT_OVERRIDE} != "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT=${ZITI_EDGE_CONTROLLER_PORT_OVERRIDE}; fi + if [[ ${ZITI_ROUTER_ADVERTISED_ADDRESS} == "" ]]; then export ZITI_ROUTER_ADVERTISED_ADDRESS=${ZITI_EDGE_ROUTER_NAME}; fi # First off - lets make sure we have what we need if [[ ${ZITI_USER} == "" ]] || [[ ${ZITI_PWD} == "" ]]; then echo "ERROR: Need ZITI_USER and ZITI_PWD defined" >&2; exit; fi if [[ "$1" == "" ]]; then echo "ERROR: Have not defined router type. It should be one of edge,wss,fabric or private." >&2; exit; fi - if [[ "${ZITI_CTRL_ADVERTISED_ADDRESS}" == "" ]]; then echo "ERROR: Missing ZITI_CTRL_ADVERTISED_ADDRESS_OVERRIDE definition" >&2; exit; fi + if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" == "" ]]; then echo "ERROR: Missing ZITI_CTRL_EDGE_ADVERTISED_ADDRESS definition" >&2; exit; fi if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi - if [[ "${ZITI_EDGE_ROUTER_ROLES}" == "" ]]; then export ZITI_EDGE_ROUTER_ROLES="${ZITI_EDGE_ROUTER_HOSTNAME}"; fi + if [[ "${ZITI_EDGE_ROUTER_ROLES}" == "" ]]; then export ZITI_EDGE_ROUTER_ROLES="${ZITI_ROUTER_ADVERTISED_ADDRESS}"; fi - echo "ZITI_EDGE_ROUTER_RAWNAME = ${ZITI_EDGE_ROUTER_RAWNAME}" + echo "ZITI_EDGE_ROUTER_NAME = ${ZITI_EDGE_ROUTER_NAME}" echo "ZITI_EDGE_ROUTER_ROLES = ${ZITI_EDGE_ROUTER_ROLES}" echo "ZITI_EDGE_ROUTER_PORT = ${ZITI_EDGE_ROUTER_PORT}" - echo "ZITI_CTRL_ADVERTISED_ADDRESS = ${ZITI_CTRL_ADVERTISED_ADDRESS}" - echo "ZITI_CTRL_PORT = ${ZITI_CTRL_PORT}" + echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS = ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" + echo "ZITI_CTRL_LISTENER_PORT = ${ZITI_CTRL_LISTENER_PORT}" echo "ZITI_USER = ${ZITI_USER}" if [[ ! "${ZITI_PWD}" == "" ]]; then echo "ZITI_PWD = (obscured)"; fi # Login to the cloud controller - "${ZITI_BIN_DIR}/ziti" edge login -y ${ZITI_CTRL_ADVERTISED_ADDRESS}:${ZITI_EDGE_CONTROLLER_PORT} -u ${ZITI_USER} -p ${ZITI_PWD} + "${ZITI_BIN_DIR}/ziti" edge login -y ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:${ZITI_CTRL_EDGE_ADVERTISED_PORT} -u ${ZITI_USER} -p ${ZITI_PWD} if [[ "$1" == "edge" ]]; then echo "CREATING EDGE ROUTER CONFIG" - createEdgeRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createEdgeRouterConfig "${ZITI_EDGE_ROUTER_NAME}" fi if [[ "$1" == "wss" ]]; then echo "CREATING EDGE ROUTER WSS CONFIG" - createEdgeRouterWssConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createEdgeRouterWssConfig "${ZITI_EDGE_ROUTER_NAME}" fi if [[ "$1" == "fabric" ]]; then echo "CREATING FABRIC ROUTER CONFIG" - createFabricRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createFabricRouterConfig "${ZITI_EDGE_ROUTER_NAME}" fi if [[ "$1" == "private" ]]; then echo "CREATING PRIVATE ROUTER CONFIG" - createPrivateRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + createPrivateRouterConfig "${ZITI_EDGE_ROUTER_NAME}" fi - mv ${ZITI_HOME}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml ${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.yaml + mv ${ZITI_HOME}/${ZITI_EDGE_ROUTER_NAME}.yaml ${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml - echo "---------- Creating edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." - found=$(${ZITI_BIN_DIR}/ziti edge list edge-routers 'name = "'"${ZITI_EDGE_ROUTER_HOSTNAME}"'"' | grep -c "${ZITI_EDGE_ROUTER_HOSTNAME}") + echo "---------- Creating edge-router ${ZITI_EDGE_ROUTER_NAME}...." + found=$(${ZITI_BIN_DIR}/ziti edge list edge-routers 'name = "'"${ZITI_ROUTER_ADVERTISED_ADDRESS}"'"' | grep -c "${ZITI_ROUTER_ADVERTISED_ADDRESS}") if [[ found -gt 0 ]]; then - echo "---------- Found existing edge-router ${ZITI_EDGE_ROUTER_HOSTNAME}...." + echo "---------- Found existing edge-router ${ZITI_ROUTER_ADVERTISED_ADDRESS}...." else - "${ZITI_BIN_DIR}/ziti" edge create edge-router "${ZITI_EDGE_ROUTER_HOSTNAME}" -o "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.jwt" -t -a "${ZITI_EDGE_ROUTER_ROLES}" + "${ZITI_BIN_DIR}/ziti" edge create edge-router "${ZITI_ROUTER_ADVERTISED_ADDRESS}" -o "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.jwt" -t -a "${ZITI_EDGE_ROUTER_ROLES}" sleep 1 - echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_HOSTNAME}...." - "${ZITI_BIN_DIR}/ziti-router" enroll "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.yaml" --jwt "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.jwt" + echo "---------- Enrolling edge-router ${ZITI_ROUTER_ADVERTISED_ADDRESS}...." + "${ZITI_BIN_DIR}/ziti-router" enroll "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml" --jwt "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.jwt" echo "" fi fi # Run the router -"${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME}/${ZITI_EDGE_ROUTER_HOSTNAME}.yaml" > "${ZITI_HOME}/ziti-${ZITI_EDGE_ROUTER_HOSTNAME}.log" +"${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME}/${ZITI_ROUTER_ADVERTISED_ADDRESS}.yaml" > "${ZITI_HOME}/ziti-${ZITI_ROUTER_ADVERTISED_ADDRESS}.log" diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 0f08db9f4..052722131 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -372,8 +372,8 @@ function persistEnvironmentValues { echo "export PFXLOG_NO_JSON=true" >> "${filepath}" echo "alias zec='ziti edge'" >> "${filepath}" - echo "alias zlogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" - echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" + echo "alias zlogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" + echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" echo "alias psz='ps -ef | grep ziti'" >> "${filepath}" #when sourcing the emitted file add the bin folder to the path @@ -1432,9 +1432,9 @@ function performMigration { # Replace old Env Vars with new ones # NOTE: the '' after -i is required for Mac, otherwise an error is thrown sed -i '' 's/ZITI_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CONTROLLER_INTERMEDIATE_NAME/ZITI_CTRL_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CONTROLLER_INTERMEDIATE_NAME/ZITI_PKI_CTRL_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_CONTROLLER_RAWNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CONTROLLER_ROOTCA_NAME/ZITI_CTRL_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_CONTROLLER_ROOTCA_NAME/ZITI_PKI_CTRL_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_CTRL_ADVERTISED_ADDRESS/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_CTRL_EDGE_PORT/ZITI_CTRL_EDGE_ADVERTISED_PORT/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_CTRL_IDENTITY_CA/ZITI_PKI_CTRL_CA/g' "${ZITI_ENV_FILE}" @@ -1442,19 +1442,15 @@ function performMigration { sed -i '' 's/ZITI_CTRL_IDENTITY_KEY/ZITI_PKI_CTRL_KEY/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_CTRL_IDENTITY_SERVER_CERT/ZITI_PKI_CTRL_SERVER_CERT/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_CTRL_PORT/ZITI_CTRL_LISTENER_PORT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_CA/ZITI_PKI_EDGE_CA/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_CERT/ZITI_PKI_EDGE_CERT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_KEY/ZITI_PKI_EDGE_KEY/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_WEB_IDENTITY_SERVER_CERT/ZITI_PKI_EDGE_SERVER_CERT/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME/ZITI_CTRL_EDGE_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME/ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CONTROLLER_PORT/ZITI_CTRL_EDGE_ADVERTISED_PORT/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CONTROLLER_RAWNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_ROOTCA_NAME/ZITI_CTRL_EDGE_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CA/ZITI_CTRL_WEB_IDENTITY_CA/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CERT/ZITI_CTRL_WEB_IDENTITY_CERT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_KEY/ZITI_CTRL_WEB_IDENTITY_KEY/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT/ZITI_CTRL_WEB_IDENTITY_SERVER_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_ROOTCA_NAME/ZITI_PKI_CTRL_EDGE_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CA/ZITI_PKI_EDGE_CA/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CERT/ZITI_PKI_EDGE_CERT/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_KEY/ZITI_PKI_EDGE_KEY/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT/ZITI_PKI_EDGE_SERVER_CERT/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_ROUTER_RAWNAME/ZITI_EDGE_ROUTER_NAME/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_PKI_OS_SPECIFIC/ZITI_PKI/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_SIGNING_CERT/ZITI_PKI_SIGNER_CERT/g' "${ZITI_ENV_FILE}" diff --git a/quickstart/local/add-zcat.sh b/quickstart/local/add-zcat.sh index e0e242069..eb5e7e848 100644 --- a/quickstart/local/add-zcat.sh +++ b/quickstart/local/add-zcat.sh @@ -1,4 +1,4 @@ -ziti edge login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" +ziti edge login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert" ziti edge delete service zcatsvc ziti edge delete config zcatconfig diff --git a/quickstart/local/newid.sh b/quickstart/local/newid.sh index 95ae77b39..65afbf10f 100755 --- a/quickstart/local/newid.sh +++ b/quickstart/local/newid.sh @@ -1,7 +1,7 @@ suffix=$(date +"%b-%d-%H%M") idname="User${suffix}" -ziti edge login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" +ziti edge login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert" ziti edge delete identity "${idname}" ziti edge create identity device "${idname}" -o "${ZITI_HOME}/test_identity".jwt diff --git a/quickstart/local/test-ziti.sh b/quickstart/local/test-ziti.sh index 8e90825c2..248e2e9f9 100755 --- a/quickstart/local/test-ziti.sh +++ b/quickstart/local/test-ziti.sh @@ -1,4 +1,4 @@ -ziti edge controller login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" +ziti edge controller login "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" -u "${ZITI_USER}" -p "${ZITI_PWD}" -c "${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert" ziti edge delete service netcatsvc ziti edge delete service zcatsvc diff --git a/quickstart/test/quickstart_test.go b/quickstart/test/quickstart_test.go index 909ce3b56..38120267a 100644 --- a/quickstart/test/quickstart_test.go +++ b/quickstart/test/quickstart_test.go @@ -228,8 +228,8 @@ func TestQuickStartEnvFile(t *testing.T) { "export ZITI_USER=\"admin\"", "export ZITI_PWD=\"admin\"", "export ZITI_PKI=\"/persistent/pki\"", - "export ZITI_EDGE_CONTROLLER_ROOTCA_NAME=\"localhost-root-ca\"", - "export ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME=\"localhost-intermediate\"", + "export ZITI_PKI_CTRL_EDGE_ROOTCA_NAME=\"localhost-root-ca\"", + "export ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME=\"localhost-intermediate\"", } // Build the image From 27939cf5712d8c0b3afcd638af7baf2c0ae2c9c0 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Wed, 17 May 2023 10:35:04 -0400 Subject: [PATCH 13/26] Removed External DNS from CLI Fixed SANs assignments with advertised address Removed references to "raw name" from various parts of the code Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 6 ++-- ziti/cmd/config_templates/router.yml | 4 +-- ziti/cmd/create_config.go | 1 - ziti/cmd/create_config_controller_test.go | 4 --- ziti/cmd/create_config_environment.go | 4 +-- ziti/cmd/create_config_router_common.go | 31 ++++++------------- ziti/cmd/create_config_router_edge_test.go | 28 +++++------------ ziti/cmd/create_config_router_fabric_test.go | 4 +-- ziti/cmd/create_config_router_test.go | 22 ++++++------- ziti/cmd/create_config_test.go | 2 -- ziti/cmd/helpers/env_helpers.go | 4 +-- ziti/constants/constants.go | 9 +++--- 12 files changed, 43 insertions(+), 76 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 052722131..375c402cf 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -331,6 +331,7 @@ function setupEnvironment { # Router Values if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then export ZITI_EDGE_ROUTER_NAME="${ZITI_NETWORK}-edge-router"; else echo "ZITI_EDGE_ROUTER_NAME overridden: ${ZITI_EDGE_ROUTER_NAME}"; fi if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; else echo "ZITI_EDGE_ROUTER_PORT overridden: ${ZITI_EDGE_ROUTER_PORT}"; fi + if [[ "${EXTERNAL_DNS-}" != "" ]]; then export ZITI_EDGE_ROUTER_ADVERTISED_HOST="${EXTERNAL_DNS}"; fi # Set up directories mkdir -p "${ZITI_HOME}" @@ -372,8 +373,8 @@ function persistEnvironmentValues { echo "export PFXLOG_NO_JSON=true" >> "${filepath}" echo "alias zec='ziti edge'" >> "${filepath}" - echo "alias zlogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" - echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" + echo "alias zlogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:\${ZITI_CTRL_EDGE_ADVERTISED_PORT}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" + echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:\${ZITI_CTRL_EDGE_ADVERTISED_PORT}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -c \"\${ZITI_PKI}/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/\${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert\"'" >> "${filepath}" echo "alias psz='ps -ef | grep ziti'" >> "${filepath}" #when sourcing the emitted file add the bin folder to the path @@ -923,7 +924,6 @@ function addRouter { function initializeController { local retVal log_file - # TODO: Update this to possibly take a controller name as an argument, possibly check pwd for controller file, then default to env var values _setup_ziti_home # Make sure necessary env variables are set _check_env_variable ZITI_HOME ZITI_CTRL_NAME ZITI_USER ZITI_PWD ZITI_PKI_CTRL_CA ZITI_BIN_DIR diff --git a/ziti/cmd/config_templates/router.yml b/ziti/cmd/config_templates/router.yml index f30c7c6c4..2778c568b 100644 --- a/ziti/cmd/config_templates/router.yml +++ b/ziti/cmd/config_templates/router.yml @@ -47,7 +47,7 @@ csr: organizationalUnit: Ziti sans: dns: - - {{ .Router.Edge.Hostname }} + - {{ .Router.Edge.AdvertisedHost }} - localhost ip: - "127.0.0.1" @@ -62,7 +62,7 @@ edge: organizationalUnit: Ziti sans: dns: - - {{ .Router.Edge.Hostname }} + - {{ .Router.Edge.AdvertisedHost }} - localhost ip: - "127.0.0.1" diff --git a/ziti/cmd/create_config.go b/ziti/cmd/create_config.go index c2c170dcb..3ec18ae1f 100644 --- a/ziti/cmd/create_config.go +++ b/ziti/cmd/create_config.go @@ -149,7 +149,6 @@ type RouterTemplateValues struct { } type EdgeRouterTemplateValues struct { - Hostname string Port string IPOverride string AdvertisedHost string diff --git a/ziti/cmd/create_config_controller_test.go b/ziti/cmd/create_config_controller_test.go index 94ac411ed..b42b9b13d 100644 --- a/ziti/cmd/create_config_controller_test.go +++ b/ziti/cmd/create_config_controller_test.go @@ -695,10 +695,6 @@ func TestCtrlEdgeAPIAddress(t *testing.T) { assert.Equal(t, customValue, data.Controller.EdgeApi.Address) assert.Equal(t, customValue, strings.Split(ctrlConfig.Edge.Api.Address, ":")[0]) - - // Ensure that the web listener was also set to this value (web listener must match the edge API address) - assert.Equal(t, customValue, data.Controller.Web.BindPoints.AddressAddress) - assert.Equal(t, customValue, strings.Split(ctrlConfig.Web[0].BindPoints[0].Address, ":")[0]) } func TestCtrlEdgeAPIPort(t *testing.T) { diff --git a/ziti/cmd/create_config_environment.go b/ziti/cmd/create_config_environment.go index 87a5e7a9d..44933dcc1 100644 --- a/ziti/cmd/create_config_environment.go +++ b/ziti/cmd/create_config_environment.go @@ -114,7 +114,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { {constants.CtrlPkiEdgeServerCertVarName, constants.CtrlPkiEdgeServerCertVarDescription, data.Controller.Web.Identity.ServerCert}, {constants.CtrlPkiEdgeKeyVarName, constants.CtrlPkiEdgeKeyVarDescription, data.Controller.Web.Identity.Key}, {constants.CtrlPkiEdgeCAVarName, constants.CtrlPkiEdgeCAVarDescription, data.Controller.Web.Identity.Ca}, - {constants.ZitiEdgeRouterNameVarName, constants.ZitiEdgeRouterNameVarDescription, data.Router.Edge.Hostname}, + {constants.ZitiEdgeRouterNameVarName, constants.ZitiEdgeRouterNameVarDescription, data.Router.Name}, {constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port}, {constants.ZitiEdgeRouterListenerBindPortVarName, constants.ZitiEdgeRouterListenerBindPortVarDescription, data.Router.Edge.ListenerBindPort}, {constants.ZitiRouterIdentityCertVarName, constants.ZitiRouterIdentityCertVarDescription, data.Router.IdentityCert}, @@ -213,7 +213,7 @@ func NewCmdCreateConfigEnvironment() *cobra.Command { constants.CtrlPkiEdgeServerCertVarName, constants.CtrlPkiEdgeServerCertVarDescription, data.Controller.Web.Identity.ServerCert, constants.CtrlPkiEdgeKeyVarName, constants.CtrlPkiEdgeKeyVarDescription, data.Controller.Web.Identity.Key, constants.CtrlPkiEdgeCAVarName, constants.CtrlPkiEdgeCAVarDescription, data.Controller.Web.Identity.Ca, - constants.ZitiEdgeRouterNameVarName, constants.ZitiEdgeRouterNameVarDescription, data.Router.Edge.Hostname, + constants.ZitiEdgeRouterNameVarName, constants.ZitiEdgeRouterNameVarDescription, data.Router.Name, constants.ZitiEdgeRouterPortVarName, constants.ZitiEdgeRouterPortVarDescription, data.Router.Edge.Port, constants.ZitiEdgeRouterListenerBindPortVarName, constants.ZitiEdgeRouterListenerBindPortVarDescription, data.Router.Edge.ListenerBindPort, constants.ZitiRouterIdentityCertVarName, constants.ZitiRouterIdentityCertVarDescription, data.Router.IdentityCert, diff --git a/ziti/cmd/create_config_router_common.go b/ziti/cmd/create_config_router_common.go index 3af211e42..2a2e5daca 100644 --- a/ziti/cmd/create_config_router_common.go +++ b/ziti/cmd/create_config_router_common.go @@ -20,7 +20,6 @@ import ( _ "embed" cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" "github.com/openziti/ziti/ziti/constants" - "log" "os" ) @@ -30,38 +29,26 @@ func SetZitiRouterIdentity(r *RouterTemplateValues, routerName string) { SetZitiRouterIdentityKey(r, routerName) SetZitiRouterIdentityCA(r, routerName) + // Set the router name + r.Name = routerName + // Edge router IP override edgeRouterIPOverride := os.Getenv(constants.ZitiEdgeRouterIPOverrideVarName) if edgeRouterIPOverride != "" { r.Edge.IPOverride = edgeRouterIPOverride } - externalDNS := os.Getenv(constants.ExternalDNSVarName) - edgeRouterRawName := os.Getenv(constants.ZitiEdgeRouterNameVarName) - if externalDNS != "" { - r.Edge.Hostname = externalDNS - r.Edge.AdvertisedHost = r.Edge.Hostname //not redundant set AdvertisedHost - } else if edgeRouterRawName != "" { - r.Edge.Hostname = edgeRouterRawName - r.Edge.AdvertisedHost = r.Edge.Hostname //not redundant set AdvertisedHost - } else { - r.Edge.Hostname, _ = os.Hostname() - r.Edge.AdvertisedHost = r.Edge.Hostname //not redundant set AdvertisedHost - } - + // Set advertised host advertisedHost := os.Getenv(constants.ZitiEdgeRouterAdvertisedHostVarName) + resolvedHostname, _ := os.Hostname() if advertisedHost != "" { - if advertisedHost != edgeRouterIPOverride && advertisedHost != r.Edge.AdvertisedHost { - log.Panicf("if %s[%s] is supplied, it *MUST* match the %s[%s] or resolved hostname[%s]", constants.ZitiEdgeRouterAdvertisedHostVarName, advertisedHost, constants.ZitiEdgeRouterIPOverrideVarName, edgeRouterIPOverride, r.Edge.Hostname) - } - r.Edge.AdvertisedHost = advertisedHost //finally override AdvertisedHost if provided + r.Edge.AdvertisedHost = advertisedHost } else { - if externalDNS != "" || edgeRouterRawName != "" { - r.Edge.AdvertisedHost = r.Edge.Hostname - } else if edgeRouterIPOverride != "" { + // If advertised host is not provided, set to IP override, or default to resolved hostname + if edgeRouterIPOverride != "" { r.Edge.AdvertisedHost = edgeRouterIPOverride } else { - r.Edge.AdvertisedHost = r.Edge.Hostname //not redundant set AdvertisedHost + r.Edge.AdvertisedHost = resolvedHostname } } } diff --git a/ziti/cmd/create_config_router_edge_test.go b/ziti/cmd/create_config_router_edge_test.go index 414fefdde..4e061a53e 100644 --- a/ziti/cmd/create_config_router_edge_test.go +++ b/ziti/cmd/create_config_router_edge_test.go @@ -14,7 +14,7 @@ import ( var defaultArgs = []string{"edge", "--routerName", "test-router"} var testHostname, _ = os.Hostname() -func TestEdgeRouterAdvertised(t *testing.T) { +func TestEdgeRouterAdvertisedAddress(t *testing.T) { clearRouterOptionsAndTemplateData() routerAdvHostIp := "192.168.10.10" routerAdvHostDns := "controller01.zitinetwork.example.org" @@ -22,32 +22,20 @@ func TestEdgeRouterAdvertised(t *testing.T) { "ZITI_CTRL_LISTENER_PORT": "80", "ZITI_EDGE_ROUTER_PORT": "443", } + // Defaults to hostname if nothing is set execCreateConfigCommand(defaultArgs, keys) require.Equal(t, testHostname, data.Router.Edge.AdvertisedHost, nil) - keys["ZITI_EDGE_ROUTER_NAME"] = routerAdvHostDns - execCreateConfigCommand(defaultArgs, keys) - require.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) - - keys["ZITI_EDGE_ROUTER_NAME"] = "" - keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = routerAdvHostIp - execCreateConfigCommand(defaultArgs, keys) - require.Equal(t, routerAdvHostIp, data.Router.Edge.AdvertisedHost, nil) - - keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = "" - keys["EXTERNAL_DNS"] = routerAdvHostDns - execCreateConfigCommand(defaultArgs, keys) - require.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) - - keys["ZITI_EDGE_ROUTER_ADVERTISED_HOST"] = routerAdvHostIp + // If IP override set, uses that value over hostname keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = routerAdvHostIp execCreateConfigCommand(defaultArgs, keys) require.Equal(t, routerAdvHostIp, data.Router.Edge.AdvertisedHost, nil) + // If advertised address set, uses that over IP override or hostname keys["ZITI_EDGE_ROUTER_ADVERTISED_HOST"] = routerAdvHostDns - keys["EXTERNAL_DNS"] = routerAdvHostDns + keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = routerAdvHostIp execCreateConfigCommand(defaultArgs, keys) - assert.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) + require.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) } func TestTunnelerEnabledByDefault(t *testing.T) { @@ -247,8 +235,8 @@ func TestEdgeRouterOutputPathDoesNotExist(t *testing.T) { func TestExecuteCreateConfigRouterEdgeHasNonBlankTemplateValues(t *testing.T) { routerName := "MyEdgeRouter" - expectedNonEmptyStringFields := []string{".Router.Edge.ListenerBindPort", ".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Hostname", ".Router.Edge.Port"} - expectedNonEmptyStringValues := []*string{&data.Router.Edge.ListenerBindPort, &data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Hostname, &data.Router.Edge.Port} + expectedNonEmptyStringFields := []string{".Router.Edge.ListenerBindPort", ".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Port"} + expectedNonEmptyStringValues := []*string{&data.Router.Edge.ListenerBindPort, &data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Port} expectedNonEmptyIntFields := []string{".Router.Listener.OutQueueSize", ".Router.Wss.ReadBufferSize", ".Router.Wss.WriteBufferSize", ".Router.Forwarder.XgressDialQueueLength", ".Router.Forwarder.XgressDialWorkerCount", ".Router.Forwarder.LinkDialQueueLength", ".Router.Forwarder.LinkDialWorkerCount"} expectedNonEmptyIntValues := []*int{&data.Router.Listener.OutQueueSize, &data.Router.Wss.ReadBufferSize, &data.Router.Wss.WriteBufferSize, &data.Router.Forwarder.XgressDialQueueLength, &data.Router.Forwarder.XgressDialWorkerCount, &data.Router.Forwarder.LinkDialQueueLength, &data.Router.Forwarder.LinkDialWorkerCount} expectedNonEmptyTimeFields := []string{".Router.Listener.ConnectTimeout", "Router.Listener.GetSessionTimeout", ".Router.Wss.WriteTimeout", ".Router.Wss.ReadTimeout", ".Router.Wss.IdleTimeout", ".Router.Wss.PongTimeout", ".Router.Wss.PingInterval", ".Router.Wss.HandshakeTimeout", ".Router.Forwarder.LatencyProbeInterval"} diff --git a/ziti/cmd/create_config_router_fabric_test.go b/ziti/cmd/create_config_router_fabric_test.go index e0ec1b26d..7c4a005bb 100644 --- a/ziti/cmd/create_config_router_fabric_test.go +++ b/ziti/cmd/create_config_router_fabric_test.go @@ -12,8 +12,8 @@ import ( func TestExecuteCreateConfigRouterFabricHasNonBlankTemplateValues(t *testing.T) { routerName := "MyFabricRouter" - expectedNonEmptyStringFields := []string{".Router.Listener.BindPort", ".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Hostname", ".Router.Edge.Port"} - expectedNonEmptyStringValues := []*string{&data.Router.Edge.ListenerBindPort, &data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Hostname, &data.Router.Edge.Port} + expectedNonEmptyStringFields := []string{".Router.Listener.BindPort", ".ZitiHome", ".Hostname", ".Router.Name", ".Router.IdentityCert", ".Router.IdentityServerCert", ".Router.IdentityKey", ".Router.IdentityCA", ".Router.Edge.Port"} + expectedNonEmptyStringValues := []*string{&data.Router.Edge.ListenerBindPort, &data.ZitiHome, &data.Hostname, &data.Router.Name, &data.Router.IdentityCert, &data.Router.IdentityServerCert, &data.Router.IdentityKey, &data.Router.IdentityCA, &data.Router.Edge.Port} expectedNonEmptyIntFields := []string{".Router.Listener.OutQueueSize", ".Router.Wss.ReadBufferSize", ".Router.Wss.WriteBufferSize", ".Router.Forwarder.XgressDialQueueLength", ".Router.Forwarder.XgressDialWorkerCount", ".Router.Forwarder.LinkDialQueueLength", ".Router.Forwarder.LinkDialWorkerCount"} expectedNonEmptyIntValues := []*int{&data.Router.Listener.OutQueueSize, &data.Router.Wss.ReadBufferSize, &data.Router.Wss.WriteBufferSize, &data.Router.Forwarder.XgressDialQueueLength, &data.Router.Forwarder.XgressDialWorkerCount, &data.Router.Forwarder.LinkDialQueueLength, &data.Router.Forwarder.LinkDialWorkerCount} expectedNonEmptyTimeFields := []string{".Router.Listener.ConnectTimeout", "Router.Listener.GetSessionTimeout", ".Router.Wss.WriteTimeout", ".Router.Wss.ReadTimeout", ".Router.Wss.IdleTimeout", ".Router.Wss.PongTimeout", ".Router.Wss.PingInterval", ".Router.Wss.HandshakeTimeout", ".Router.Forwarder.LatencyProbeInterval"} diff --git a/ziti/cmd/create_config_router_test.go b/ziti/cmd/create_config_router_test.go index 226716d8d..4ca5be906 100644 --- a/ziti/cmd/create_config_router_test.go +++ b/ziti/cmd/create_config_router_test.go @@ -244,42 +244,42 @@ func TestSetZitiRouterIdentityCACustom(t *testing.T) { assert.Equal(t, expectedCustom, rtv.IdentityCA) } -func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawName(t *testing.T) { +func TestSetZitiRouterIdentitySetsAllIdentitiesAndRouterName(t *testing.T) { // Setup clearRouterOptionsAndTemplateData() - expectedRawName := "MyEdgeRouterRawName" + expectedName := "MyRouterName" blank := "" rtv := &RouterTemplateValues{} // Check that they're all currently blank - assert.Equal(t, blank, rtv.Edge.Hostname) + assert.Equal(t, blank, rtv.Name) assert.Equal(t, blank, rtv.IdentityCert) assert.Equal(t, blank, rtv.IdentityServerCert) assert.Equal(t, blank, rtv.IdentityKey) assert.Equal(t, blank, rtv.IdentityCA) // Set the env variable - _ = os.Setenv(constants.ZitiEdgeRouterNameVarName, expectedRawName) + _ = os.Setenv(constants.ZitiEdgeRouterNameVarName, expectedName) - SetZitiRouterIdentity(rtv, expectedRawName) + SetZitiRouterIdentity(rtv, expectedName) // Check that the value matches - assert.Equal(t, expectedRawName, rtv.Edge.Hostname) + assert.Equal(t, expectedName, rtv.Name) assert.NotEqualf(t, blank, rtv.IdentityCert, "Router.IdentityCert expected to have a value, instead it was blank") assert.NotEqualf(t, blank, rtv.IdentityServerCert, "Router.IdentityCert expected to have a value, instead it was blank") assert.NotEqualf(t, blank, rtv.IdentityKey, "Router.IdentityCert expected to have a value, instead it was blank") assert.NotEqualf(t, blank, rtv.IdentityCA, "Router.IdentityCert expected to have a value, instead it was blank") } -func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawNameToHostWhenBlank(t *testing.T) { +func TestSetZitiRouterIdentitySetsAllIdentitiesAndRouterNameToHostWhenBlank(t *testing.T) { // Setup clearRouterOptionsAndTemplateData() - expectedRawName, _ := os.Hostname() + expectedName, _ := os.Hostname() blank := "" rtv := &RouterTemplateValues{} // Check that they're all currently blank - assert.Equal(t, blank, rtv.Edge.Hostname) + assert.Equal(t, blank, rtv.Name) assert.Equal(t, blank, rtv.IdentityCert) assert.Equal(t, blank, rtv.IdentityServerCert) assert.Equal(t, blank, rtv.IdentityKey) @@ -288,10 +288,10 @@ func TestSetZitiRouterIdentitySetsAllIdentitiesAndEdgeRouterRawNameToHostWhenBla // Set the env variable to an empty value _ = os.Setenv(constants.ZitiEdgeRouterNameVarName, "") - SetZitiRouterIdentity(rtv, expectedRawName) + SetZitiRouterIdentity(rtv, expectedName) // Check that the value matches - assert.Equal(t, expectedRawName, rtv.Edge.Hostname) + assert.Equal(t, expectedName, rtv.Name) assert.NotEqualf(t, blank, rtv.IdentityCert, "Router.IdentityCert expected to have a value, instead it was blank") assert.NotEqualf(t, blank, rtv.IdentityServerCert, "Router.IdentityCert expected to have a value, instead it was blank") assert.NotEqualf(t, blank, rtv.IdentityKey, "Router.IdentityCert expected to have a value, instead it was blank") diff --git a/ziti/cmd/create_config_test.go b/ziti/cmd/create_config_test.go index 97403e5bd..09dc5a4f3 100644 --- a/ziti/cmd/create_config_test.go +++ b/ziti/cmd/create_config_test.go @@ -3,7 +3,6 @@ package cmd import ( "bytes" "fmt" - "github.com/openziti/ziti/ziti/constants" "github.com/stretchr/testify/assert" "io" "os" @@ -74,7 +73,6 @@ func unsetZitiEnv() { for i := 0; i < len(envVars); i++ { _ = os.Unsetenv(envVars[i]) } - _ = os.Unsetenv(constants.ExternalDNSVarName) } // Test that all ZITI_* variables are included in the values for output diff --git a/ziti/cmd/helpers/env_helpers.go b/ziti/cmd/helpers/env_helpers.go index 0e276d131..448fabd3b 100644 --- a/ziti/cmd/helpers/env_helpers.go +++ b/ziti/cmd/helpers/env_helpers.go @@ -92,7 +92,7 @@ func GetCtrlListenerPort() (string, error) { func GetCtrlEdgeApiAddress() (string, error) { // Get the controller's edge advertised hostname to use as the default - defaultHostname, err := GetCtrlEdgeAdvertisedAddress() + defaultAddress, err := GetCtrlEdgeAdvertisedAddress() if err != nil { err := errors.Wrap(err, "Unable to get "+constants.CtrlEdgeAdvertisedAddressVarName) if err != nil { @@ -100,7 +100,7 @@ func GetCtrlEdgeApiAddress() (string, error) { } } - return getValueOrSetAndGetDefault(constants.CtrlEdgeApiAddressVarName, defaultHostname) + return getValueOrSetAndGetDefault(constants.CtrlEdgeApiAddressVarName, defaultAddress) } func GetCtrlEdgeApiPort() (string, error) { diff --git a/ziti/constants/constants.go b/ziti/constants/constants.go index 3f78bd3f2..ce746b9fe 100644 --- a/ziti/constants/constants.go +++ b/ziti/constants/constants.go @@ -59,11 +59,11 @@ const ( PkiCtrlCAVarName = "ZITI_PKI_CTRL_CA" PkiCtrlCAVarDescription = "Path to Identity CA for Ziti Controller" CtrlListenerAddressVarName = "ZITI_CTRL_LISTENER_ADDRESS" - CtrlListenerAddressVarDescription = "The hostname routers will use to connect to the Ziti Controller" + CtrlListenerAddressVarDescription = "The address routers will use to connect to the Ziti Controller" CtrlListenerPortVarName = "ZITI_CTRL_LISTENER_PORT" CtrlListenerPortVarDescription = "The port routers will use to connect to the Ziti Controller" CtrlEdgeApiAddressVarName = "ZITI_CTRL_EDGE_API_ADDRESS" - CtrlEdgeApiAddressVarDescription = "The hostname for the controller's API plane" + CtrlEdgeApiAddressVarDescription = "The address for the controller's API plane" CtrlEdgeApiPortVarName = "ZITI_CTRL_EDGE_API_PORT" CtrlEdgeApiPortVarDescription = "The port for the controller's API plane" PkiSignerCertVarName = "ZITI_PKI_SIGNER_CERT" @@ -75,7 +75,7 @@ const ( CtrlEdgeRouterEnrollmentDurationVarName = "ZITI_EDGE_ROUTER_ENROLLMENT_DURATION" CtrlEdgeRouterEnrollmentDurationVarDescription = "The router enrollment duration in minutes" CtrlEdgeInterfaceAddressVarName = "ZITI_CTRL_EDGE_INTERFACE_ADDRESS" - CtrlEdgeInterfaceAddressVarDescription = "The interface hostname to bind the controller's edge listener to" + CtrlEdgeInterfaceAddressVarDescription = "The interface address to bind the controller's edge listener to" CtrlEdgeInterfacePortVarName = "ZITI_CTRL_EDGE_INTERFACE_PORT" CtrlEdgeInterfacePortVarDescription = "The interface port to bind the controller's edge listener to" CtrlEdgeAdvertisedAddressVarName = "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS" @@ -92,7 +92,7 @@ const ( CtrlPkiEdgeCAVarDescription = "Path to Identity CA for Ziti Edge Controller" ZitiEdgeRouterNameVarName = "ZITI_EDGE_ROUTER_NAME" - ZitiEdgeRouterNameVarDescription = "The Edge Router Raw Name" + ZitiEdgeRouterNameVarDescription = "The Edge Router Name" ZitiEdgeRouterPortVarName = "ZITI_EDGE_ROUTER_PORT" ZitiEdgeRouterPortVarDescription = "Port of the Ziti Edge Router" ZitiRouterIdentityCertVarName = "ZITI_ROUTER_IDENTITY_CERT" @@ -109,5 +109,4 @@ const ( ZitiEdgeRouterAdvertisedHostVarDescription = "The advertised host of the router" ZitiEdgeRouterListenerBindPortVarName = "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" ZitiEdgeRouterListenerBindPortVarDescription = "The port a public router will advertise on" - ExternalDNSVarName = "EXTERNAL_DNS" ) From 750db7a01cb7cb5009dbf02ac5fcdde95e021298 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Wed, 17 May 2023 14:46:24 -0400 Subject: [PATCH 14/26] Fixed addRouter type and added attribute option Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 375c402cf..5361da7ed 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -877,7 +877,7 @@ function _create_router_config { # Used to create a router, router config, then enroll the router. function addRouter { - local router_name router_type retVal + local router_name router_type retVal router_attr # Make sure necessary env variables are set _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_USER ZITI_PWD retVal=$? @@ -887,6 +887,7 @@ function addRouter { # Allow router name and type to be passed in as arg router_name="${1-}" router_type="${2-}" + router_attr="${3-}" # If no router name provided and env var is not set, prompt user for a router name if [[ "${router_name}" == "" ]] && [[ -z "${ZITI_EDGE_ROUTER_NAME}" ]]; then echo -e "$(YELLOW "addRouter requires a router name to be supplied") " @@ -906,7 +907,7 @@ function addRouter { # Create router zitiLogin "${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${router_name}" - "${ZITI_BIN_DIR-}/ziti" edge create edge-router "${router_name}" -o "${ZITI_HOME}/${router_name}.jwt" -t -a "${router_type}" + "${ZITI_BIN_DIR-}/ziti" edge create edge-router "${router_name}" -o "${ZITI_HOME}/${router_name}.jwt" -t -a "${router_attr}" # Create router config _create_router_config "${router_name}" "${router_type}" From 69a6e22b19efb615d6c1e7a13e5d7ef6d3fd2c33 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 19 May 2023 12:46:20 -0400 Subject: [PATCH 15/26] Added clearer messaging around ZITI_BIN_DIR Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 5361da7ed..eeeb9ceb2 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -55,7 +55,7 @@ function _setup_ziti_network { } function _set_ziti_bin_dir { - if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}"; fi + if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}"; else echo "ZITI_BIN_DIR overridden: ${ZITI_BIN_DIR}"; fi } function _get_file_overwrite_permission { @@ -630,14 +630,15 @@ function getZiti { # Check if they're already downloaded or maybe the user explicitly pointed ZITI_BIN_DIR to their local bins if ! test -f "${ZITI_BIN_DIR}/ziti"; then # Make the directory + echo -en "No existing binary found, creating the ZITI_BIN_DIR directory ($(BLUE "${ZITI_BIN_DIR}"))" mkdir -p "${ZITI_BIN_DIR}" retVal=$? if [[ "${retVal}" != 0 ]]; then - echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR}")" + echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR})")" return 1 fi else - echo "ZITI_BIN_DIR/ziti does exist" + echo -en "ziti found in ZITI_BIN_DIR ($(BLUE "${ZITI_BIN_DIR}"))" # Get the current version and compare with latest local currentVersion currentVersion="$("${ZITI_BIN_DIR}"/ziti --version) " From c2aafde2534cf0443b0c48e10b62a95460f25836 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:03:32 -0400 Subject: [PATCH 16/26] fixing stopController --- quickstart/docker/image/ziti-cli-functions.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index bd8107a36..6e1707794 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -452,15 +452,15 @@ function stopController { local pid retVal pid=${1-} if [[ "${pid}" == "" ]]; then - _check_env_variable ZITI_CTRL_LISTENER_PORT + _check_env_variable ZITI_CTRL_EDGE_ADVERTISED_PORT retVal=$? if [[ "${retVal}" != 0 ]]; then - echo "You will need to source the ziti env file first so that the controller process can be found" + echo "You will need to source the ziti env file first or set ZITI_CTRL_EDGE_ADVERTISED_PORT so that the controller process can be found" return 1 fi # Get the pid listening on the controller port - pid=$(lsof -ti:"${ZITI_CTRL_LISTENER_PORT}") + pid=$(lsof -ti:"${ZITI_CTRL_EDGE_ADVERTISED_PORT}") fi if [[ -n ${pid:-} ]]; then From 53f78c9344316044043612dd9517578b13781479 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Tue, 6 Jun 2023 09:45:03 -0400 Subject: [PATCH 17/26] Fixing docker router hostname Signed-off-by: gberl002 --- quickstart/docker/docker-compose.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/quickstart/docker/docker-compose.yml b/quickstart/docker/docker-compose.yml index ca1583dce..9c1eef4eb 100644 --- a/quickstart/docker/docker-compose.yml +++ b/quickstart/docker/docker-compose.yml @@ -53,6 +53,7 @@ services: - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" - ZITI_EDGE_ROUTER_NAME=${ZITI_EDGE_ROUTER_NAME:-ziti-edge-router} - ZITI_EDGE_ROUTER_ROLES=public + - ZITI_EDGE_ROUTER_ADVERTISED_HOST=${ZITI_EDGE_ROUTER_ADVERTISED_HOST:-ziti-edge-router} ports: - ${ZITI_EDGE_ROUTER_PORT:-3022}:${ZITI_EDGE_ROUTER_PORT:-3022} networks: @@ -72,6 +73,7 @@ services: - ZITI_EDGE_ROUTER_NAME=ziti-edge-router-wss - ZITI_EDGE_ROUTER_PORT=3023 - ZITI_EDGE_ROUTER_ROLES=public + - ZITI_EDGE_ROUTER_ADVERTISED_HOST=ziti-edge-router-wss ports: - 3023:3023 networks: @@ -89,6 +91,7 @@ services: environment: - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" - ZITI_EDGE_ROUTER_NAME=ziti-fabric-router-br + - ZITI_EDGE_ROUTER_ADVERTISED_HOST=ziti-fabric-router-br #ports: # - 3024:3024 networks: @@ -106,6 +109,7 @@ services: environment: - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" - ZITI_EDGE_ROUTER_NAME=ziti-private-red + - ZITI_EDGE_ROUTER_ADVERTISED_HOST=ziti-private-red #ports: # - 3025:3025 networks: @@ -122,6 +126,7 @@ services: environment: - ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" - ZITI_EDGE_ROUTER_NAME=ziti-private-blue + - ZITI_EDGE_ROUTER_ADVERTISED_HOST=ziti-private-blue #ports: # - 3026:3026 networks: From 3fdefe756ec5c8509a480a11e131ca830acdb7d0 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Thu, 8 Jun 2023 16:43:57 -0400 Subject: [PATCH 18/26] Fixing whitespace, newline, and formatting issues. Signed-off-by: gberl002 --- quickstart/docker/image/Dockerfile | 2 +- quickstart/docker/image/ziti-cli-functions.sh | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/quickstart/docker/image/Dockerfile b/quickstart/docker/image/Dockerfile index bfbec1755..11fcb9d70 100644 --- a/quickstart/docker/image/Dockerfile +++ b/quickstart/docker/image/Dockerfile @@ -40,4 +40,4 @@ COPY --chown=ziti run-with-ziti-cli.sh "${ZITI_SCRIPTS}/" COPY --chown=ziti access-control.sh "${ZITI_SCRIPTS}/" COPY --chown=ziti run-router-external.sh "${ZITI_SCRIPTS}/" -RUN /bin/bash -c "source ${ZITI_SCRIPTS}/ziti-cli-functions.sh; ziti_createEnvFile; echo source ${ZITI_HOME}/ziti.env >> ~/.bashrc" +RUN /bin/bash -c "source ${ZITI_SCRIPTS}/ziti-cli-functions.sh; echo source ${ZITI_HOME}/ziti.env >> ~/.bashrc" diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 6e1707794..4de67334f 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -62,7 +62,7 @@ function _get_file_overwrite_permission { local file_path="${1-}" if [[ -f "${file_path}" ]]; then - echo -en "This will overwrite the existing file, continue (y/N)? " + echo -en "This will overwrite the existing file, continue? (y/N) " read -r if [[ "${REPLY}" == [^Yy]* ]]; then echo -e "$(RED " --- Cancelling overwrite ---")" @@ -287,7 +287,7 @@ function setupEnvironment { if [[ -z "${pwd_reply}" || ${pwd_reply} =~ [yY] ]]; then echo "INFO: using ZITI_PWD=${ZITI_PWD}" else - echo -en "Type the preferred admin password and press " + echo -en "Type the preferred admin password and press " read -r ZITI_PWD fi else @@ -403,7 +403,7 @@ function removeZitiEnvironment { if [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]] && [[ "${ZITI_VERSION_OVERRIDE-}" != "${ZITI_BINARIES_VERSION-}" ]]; then # Don't allow overriding the version if ziti quickstart was already run, the DB may not be compatible echo -e "$(RED " --- Overriding the ziti version is not supported if the version differs from one already installed. ---")" - echo -en "Would you like to continue by using the latest version. (y/N)?" + echo -en "Would you like to continue by using the latest version? (y/N) " read -r echo " " if [[ "${REPLY}" == [Yy]* ]]; then @@ -413,7 +413,7 @@ function removeZitiEnvironment { fi elif [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]]; then echo -e "$(RED " --- You have set the ZITI_VERSION_OVERRIDE value to ${ZITI_VERSION_OVERRIDE}. ---")" - echo -en "Would you like to use this version again, choosing no will pull the latest version. (y/N)?" + echo -en "Would you like to use this version again, choosing no will pull the latest version? (y/N) " read -r echo " " if [[ "${REPLY}" == [Yy]* ]]; then @@ -597,7 +597,7 @@ function getZiti { echo "INFO: using the default path ${default_path}" ZITI_BIN_DIR="${default_path}" else - echo -en "Enter the preferred path and press (the path will be created if necessary)" + echo -en "Enter the preferred path and press (the path will be created if necessary) " read -r ZITI_BIN_DIR fi fi @@ -629,7 +629,7 @@ function getZiti { # Check if they're already downloaded or maybe the user explicitly pointed ZITI_BIN_DIR to their local bins if ! test -f "${ZITI_BIN_DIR}/ziti"; then # Make the directory - echo -en "No existing binary found, creating the ZITI_BIN_DIR directory ($(BLUE "${ZITI_BIN_DIR}"))" + echo -e "No existing binary found, creating the ZITI_BIN_DIR directory ($(BLUE "${ZITI_BIN_DIR}"))" mkdir -p "${ZITI_BIN_DIR}" retVal=$? if [[ "${retVal}" != 0 ]]; then @@ -637,13 +637,13 @@ function getZiti { return 1 fi else - echo -en "ziti found in ZITI_BIN_DIR ($(BLUE "${ZITI_BIN_DIR}"))" + echo -e "ziti found in ZITI_BIN_DIR ($(BLUE "${ZITI_BIN_DIR}"))" # Get the current version and compare with latest local currentVersion currentVersion="$("${ZITI_BIN_DIR}"/ziti --version) " if [[ "${ZITI_BINARIES_VERSION}" != "${currentVersion}" ]]; then # Prompt user for new download - echo -en "There is a newer version of OpenZiti, would you like to download it (Y/n)?" + echo -en "There is a newer version of OpenZiti, would you like to download it? (Y/n) " read -r reply if [[ -z "${reply}" || "${reply}" == [Yy]* ]]; then # Update the ZITI_BIN_DIR path to point to the latest version @@ -821,7 +821,7 @@ function _create_router_config { # If router name is not passed as arg, prompt user for input echo -e "$(YELLOW "createEdgeRouterConfig requires a router name to be supplied") " default_router_name="${ZITI_EDGE_ROUTER_NAME}" - echo -en "Enter router name (${default_router_name}):" + echo -en "Enter router name (${default_router_name}): " read -r router_name # Accept the default if no name provided @@ -948,7 +948,7 @@ function expressInstall { # Check if expressInstall has been run before if [[ "" != "${ZITIx_EXPRESS_COMPLETE-}" ]]; then echo -e "$(RED " --- It looks like you've run an express install in this shell already. ---")" - echo -en "Would you like to clear existing Ziti variables and continue (y/N)? " + echo -en "Would you like to clear existing Ziti variables and continue? (y/N) " read -r echo " " if [[ "${REPLY}" == [Yy]* ]]; then @@ -1053,7 +1053,7 @@ function createControllerSystemdFile { # If no controller name provided and env var is not set, prompt user for a controller name if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_CTRL_NAME}" ]]; then echo -e "$(YELLOW "createControllerSystemdFile requires a controller name to be supplied") " - echo -en "Enter controller name:" + echo -en "Enter controller name: " read -r controller_name # Quit if no name is provided @@ -1110,7 +1110,7 @@ function createRouterSystemdFile { # If router name is not passed as arg, prompt user for input echo -e "$(YELLOW "createRouterSystemdFile requires a router name to be supplied") " default_router_name="${ZITI_EDGE_ROUTER_NAME}" - echo -en "Enter router name (${default_router_name}):" + echo -en "Enter router name (${default_router_name}): " read -r router_name # Accept the default if no name provided @@ -1238,7 +1238,7 @@ function createRouterLaunchdFile { # If router name is not passed as arg, prompt user for input echo -e "$(YELLOW "createRouterLaunchdFile requires a router name to be supplied") " default_router_name="${ZITI_EDGE_ROUTER_NAME}" - echo -en "Enter router name (${default_router_name}):" + echo -en "Enter router name (${default_router_name}): " read -r router_name # Accept the default if no name provided @@ -1400,7 +1400,7 @@ function _portCheck { return 0 fi - echo -e "Checking ${2-}'s port (${envVarValue}) $(GREEN "Open")" + echo -en "Checking ${2-}'s port (${envVarValue})" portCheckResult=$(lsof -w -i :"${envVarValue}" 2>&1) if [[ "${portCheckResult}" != "" ]]; then echo -e "$(RED " ")" @@ -1411,11 +1411,13 @@ function _portCheck { echo -e "$(RED "export ${envVar}=1234")" echo -e "$(RED " ")" return 1 + else + echo -e "$(GREEN "Open")" fi return 0 } -# A function for upgrading an existing (<=0.27.5) network to a later (>0.27.5) network +# A function for upgrading an existing (<=0.28.0) network to a later (>0.28.0) network # The binary, which relies on environment variables were extensively altered and will not work on an existing network # without migrating it first function performMigration { From 9b19c3145985fa4275c07f9534ca158324c564d6 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Thu, 8 Jun 2023 16:56:59 -0400 Subject: [PATCH 19/26] Added additional changelog entries for bugs and enhancements Signed-off-by: gberl002 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65fe12ef4..785179185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## Component Updates and Bug Fixes * github.com/openziti/ziti: [v0.28.0 -> v0.28.1](https://github.com/openziti/ziti/compare/v0.28.0...v0.28.1) * [Issue #1132](https://github.com/openziti/ziti/issues/1132) - Updated `ws` protocol to `wss` as `ws` is no longer supported. + * [Issue #986](https://github.com/openziti/ziti/issues/986) - Updated default ports in `.env` file to match documentation. + * [Issue #920](https://github.com/openziti/ziti/issues/920) - Fixed bug causing failure when re-running quickstart. + * [Issue #779](https://github.com/openziti/ziti/issues/779) - Add ability to upgrade ziti binaries using a quickstart function. + * [Issue #761](https://github.com/openziti/ziti/issues/761) - Remove Management Listener section from controller config. + * [Issue #650](https://github.com/openziti/ziti/issues/650) - Removed/Updated references to `ZITI_EDGE_CONTROLLER_API` * Quickstart environment variable names have been cleaned up. * IMPORTANT: If you update your OpenZiti binaries to this version or later (which can be done easily with the `getZiti()` function, you will need to migrate any existing network that has been developed using OpenZiti v0.27.5 or earlier binaries as the new binaries will expect the new environment variable names. A function `performMigration()` has been provided in the `ziti-cli-script.sh` for this purpose. Simply source the latest `ziti-cli-script.sh`, and your current network's .env file, then run `performMigration()` to update environment variable name references. If the migration process cannot find your existing environment file in the default location, you will need to provide the path to the migration function, ex: `performMigration ` * [Issue #1030](https://github.com/openziti/ziti/issues/1030) - Provide an upgrade path for quickstart cleanup From 78ae10ce866abc96ef9d4c5c92a8a25774b52937 Mon Sep 17 00:00:00 2001 From: "Steven A. Broderick Elias" Date: Mon, 12 Jun 2023 15:03:46 -0400 Subject: [PATCH 20/26] Fixes #1144 panic on db explore when path arg is missing --- ziti/cmd/database/cmd.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ziti/cmd/database/cmd.go b/ziti/cmd/database/cmd.go index 41d23c9f4..f26bfe68d 100644 --- a/ziti/cmd/database/cmd.go +++ b/ziti/cmd/database/cmd.go @@ -14,6 +14,7 @@ func NewCmdDb(out io.Writer, errOut io.Writer) *cobra.Command { exploreCmd := &cobra.Command{ Use: "explore |help|version", Short: "Interactive CLI to explore Ziti database files", + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := zdecli.Run("ziti db explore", args[0]); err != nil { _, _ = errOut.Write([]byte(fmt.Sprintf("Error: %s", err))) From 4d1607683e041f544ee966b69d99c479fa34edcd Mon Sep 17 00:00:00 2001 From: gberl002 Date: Thu, 15 Jun 2023 14:35:02 -0400 Subject: [PATCH 21/26] Enhancement changes to the migration function. Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 4de67334f..554f224e9 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -1432,7 +1432,7 @@ function performMigration { ZITI_ENV_FILE="${1-}" fi - # Replace old Env Vars with new ones + # Replace old Env Vars in the env file with new ones # NOTE: the '' after -i is required for Mac, otherwise an error is thrown sed -i '' 's/ZITI_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_CONTROLLER_INTERMEDIATE_NAME/ZITI_PKI_CTRL_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" @@ -1448,7 +1448,7 @@ function performMigration { sed -i '' 's/ZITI_EDGE_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME/ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CONTROLLER_PORT/ZITI_CTRL_EDGE_ADVERTISED_PORT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_RAWNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" + sed -i '' 's/ZITI_EDGE_CONTROLLER_RAWNAME/ZITI_CTRL_NAME/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CONTROLLER_ROOTCA_NAME/ZITI_PKI_CTRL_EDGE_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CA/ZITI_PKI_EDGE_CA/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CERT/ZITI_PKI_EDGE_CERT/g' "${ZITI_ENV_FILE}" @@ -1459,7 +1459,28 @@ function performMigration { sed -i '' 's/ZITI_SIGNING_CERT/ZITI_PKI_SIGNER_CERT/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_SIGNING_KEY/ZITI_PKI_SIGNER_KEY/g' "${ZITI_ENV_FILE}" sed -i '' 's/ZITI_EDGE_ROUTER_HOSTNAME/ZITI_ROUTER_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - echo "export ZITI_CTRL_NAME=${ZITI_NETWORK}" >> "${ZITI_ENV_FILE}" + + # Update environment variables if currently set + if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" != "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_EDGE_CONTROLLER_HOSTNAME}"; fi + if [[ "${ZITI_CONTROLLER_INTERMEDIATE_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_INTERMEDIATE_NAME="${ZITI_CONTROLLER_INTERMEDIATE_NAME}"; fi + if [[ "${ZITI_CONTROLLER_ROOTCA_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_ROOTCA_NAME="${ZITI_CONTROLLER_ROOTCA_NAME}"; fi + if [[ "${ZITI_CTRL_EDGE_PORT-}" != "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT="${ZITI_CTRL_EDGE_PORT}"; fi + if [[ "${ZITI_CTRL_IDENTITY_CA-}" != "" ]]; then export ZITI_PKI_CTRL_CA="${ZITI_CTRL_IDENTITY_CA}"; fi + if [[ "${ZITI_CTRL_IDENTITY_CERT-}" != "" ]]; then export ZITI_PKI_CTRL_CERT="${ZITI_CTRL_IDENTITY_CERT}"; fi + if [[ "${ZITI_CTRL_IDENTITY_KEY-}" != "" ]]; then export ZITI_PKI_CTRL_KEY="${ZITI_CTRL_IDENTITY_KEY}"; fi + if [[ "${ZITI_CTRL_IDENTITY_SERVER_CERT-}" != "" ]]; then export ZITI_PKI_CTRL_SERVER_CERT="${ZITI_CTRL_IDENTITY_SERVER_CERT}"; fi + if [[ "${ZITI_CTRL_PORT-}" != "" ]]; then export ZITI_CTRL_LISTENER_PORT="${ZITI_CTRL_PORT}"; fi + if [[ "${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME="${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}"; fi + if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" != "" ]]; then export ZITI_CTRL_NAME="${ZITI_EDGE_CONTROLLER_RAWNAME}"; fi + if [[ "${ZITI_EDGE_CONTROLLER_ROOTCA_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_EDGE_ROOTCA_NAME="${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_CA-}" != "" ]]; then export ZITI_PKI_EDGE_CA="${ZITI_EDGE_CTRL_IDENTITY_CA}"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_CERT-}" != "" ]]; then export ZITI_PKI_EDGE_CERT="${ZITI_EDGE_CTRL_IDENTITY_CERT}"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_KEY-}" != "" ]]; then export ZITI_PKI_EDGE_KEY="${ZITI_EDGE_CTRL_IDENTITY_KEY}"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT-}" != "" ]]; then export ZITI_EDGE_ROUTER_NAME="${ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT}"; fi + if [[ "${ZITI_PKI_OS_SPECIFIC-}" != "" ]]; then export ZITI_PKI="${ZITI_PKI_OS_SPECIFIC}"; fi + if [[ "${ZITI_SIGNING_CERT-}" != "" ]]; then export ZITI_PKI_SIGNER_CERT="${ZITI_SIGNING_CERT}"; fi + if [[ "${ZITI_SIGNING_KEY-}" != "" ]]; then export ZITI_PKI_SIGNER_KEY="${ZITI_SIGNING_KEY}"; fi + if [[ "${ZITI_EDGE_ROUTER_HOSTNAME-}" != "" ]]; then export ZITI_ROUTER_ADVERTISED_ADDRESS="${ZITI_EDGE_ROUTER_HOSTNAME}"; fi # Update the necessary ziti binary references (others are not needed or are overwritten later) if [[ "${ZITI_BIN_DIR-}" != "" ]]; then @@ -1471,12 +1492,12 @@ function performMigration { echo "export ZITI_BINARIES_VERSION=${ZITI_BINARIES_VERSION}" >> "${ZITI_ENV_FILE}" fi - echo -e "$(GREEN "SUCCESS Your Environment file has been updated, please use source the file for the latest values")" + echo -e "$(GREEN "SUCCESS: Your Environment file has been updated, please use source the file for the latest values. Be sure to source the .env file as needed.")" } # ******* Deprecated functions, refer to new functions ********** function deprecationMessage { - echo -e "$(YELLOW "WARNING The ${1} function has been deprecated, please use ${2} going forward")" + echo -e "$(YELLOW "WARNING: The ${1} function has been deprecated, please use ${2} going forward")" } function generateEnvFile { From fb2a905f6e57354a1477047966f30b9637abafaf Mon Sep 17 00:00:00 2001 From: gberl002 Date: Fri, 16 Jun 2023 15:13:02 -0400 Subject: [PATCH 22/26] Reverting quickstart cleanup changes temporarily Signed-off-by: gberl002 --- quickstart/docker/image/ziti-cli-functions.sh | 2225 +++++++++-------- 1 file changed, 1133 insertions(+), 1092 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 554f224e9..68aa27648 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -2,164 +2,734 @@ set -uo pipefail -# Global Variables ASCI_WHITE='\033[01;37m' ASCI_RESTORE='\033[0m' ASCI_RED='\033[00;31m' ASCI_GREEN='\033[00;32m' ASCI_YELLOW='\033[00;33m' ASCI_BLUE='\033[00;34m' -ASCI_PURPLE='\033[00;35m' -ZITIx_EXPRESS_COMPLETE="" +#ASCI_MAGENTA='\033[00;35m' +#ASCI_PURPLE='\033[00;35m' +#ASCI_CYAN='\033[00;36m' +#ASCI_LIGHTGRAY='\033[00;37m' +#ASCI_LRED='\033[01;31m' +#ASCI_LGREEN='\033[01;32m' +#ASCI_LYELLOW='\033[01;33m' +#ASCI_LBLUE='\033[01;34m' +#ASCI_LMAGENTA='\033[01;35m' +#ASCI_LPURPLE='\033[01;35m' +#ASCI_LCYAN='\033[01;36m' function WHITE { echo "${ASCI_WHITE}${1-}${ASCI_RESTORE}" } -function RED { # Generally used for ERROR +function RED { echo "${ASCI_RED}${1-}${ASCI_RESTORE}" } -function GREEN { # Generally used for SUCCESS messages +function GREEN { echo "${ASCI_GREEN}${1-}${ASCI_RESTORE}" } -function YELLOW { # Generally used for WARNING messages +function YELLOW { echo "${ASCI_YELLOW}${1-}${ASCI_RESTORE}" } -function BLUE { # Generally used for directory paths +function BLUE { echo "${ASCI_BLUE}${1-}${ASCI_RESTORE}" } -function PURPLE { # Generally used for Express Install milestones. - echo "${ASCI_PURPLE}${1-}${ASCI_RESTORE}" -} -function _wait_for_controller { - local advertised_host_port="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:${ZITI_CTRL_EDGE_ADVERTISED_PORT}" - while [[ "$(curl -w "%{http_code}" -m 1 -s -k -o /dev/null https://"${advertised_host_port}"/version)" != "200" ]]; do - echo "waiting for https://${advertised_host_port}" - sleep 3 +function checkPrereqs { + commands_to_test=(curl jq tar hostname) + missing_requirements="" + # verify all the commands required in the automation exist before trying to run the full suite + for cmd in "${commands_to_test[@]}" + do + # checking all commands are on the path before continuing... + if ! [[ -x "$(command -v "${cmd}")" ]]; then + missing_requirements="${missing_requirements} * ${cmd} +" + fi done -} - -function _setup_ziti_home { - _setup_ziti_network - if [[ "${ZITI_HOME-}" == "" ]]; then export ZITI_HOME="${HOME}/.ziti/quickstart/${ZITI_NETWORK-}"; else echo "ZITI_HOME overridden: ${ZITI_HOME}"; fi -} - -function _setup_ziti_env_path { - _setup_ziti_network - _setup_ziti_home - if [[ "${ZITI_ENV_FILE-}" == "" ]]; then export ZITI_ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env"; else echo "ZITI_ENV_FILE overridden: ${ZITI_ENV_FILE}"; fi -} - -function _setup_ziti_network { - if [[ "${ZITI_NETWORK-}" == "" ]]; then ZITI_NETWORK="$(hostname -s)"; export ZITI_NETWORK; else echo "ZITI_NETWORK overridden: ${ZITI_NETWORK}"; fi -} - -function _set_ziti_bin_dir { - if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}"; else echo "ZITI_BIN_DIR overridden: ${ZITI_BIN_DIR}"; fi -} - -function _get_file_overwrite_permission { - local file_path="${1-}" - - if [[ -f "${file_path}" ]]; then - echo -en "This will overwrite the existing file, continue? (y/N) " - read -r - if [[ "${REPLY}" == [^Yy]* ]]; then - echo -e "$(RED " --- Cancelling overwrite ---")" + # are requirements ? if yes, stop here and help 'em out + if ! [[ "" = "${missing_requirements}" ]]; then + echo " " + echo "You're missing one or more commands that are used in this script." + echo "Please ensure the commands listed are on the path and then try again." + echo "${missing_requirements}" + echo " " return 1 - fi - - return 0 fi } -# removes duplicate strings in a list -function _dedupe_list { - local list delimiter retVal - list=${1-} - if [[ "${list}" == "" ]]; then - return 1 - fi - delimiter=${2-} - if [[ "${delimiter}" == "" ]]; then - delimiter="," - fi +checkPrereqs - echo "${list}" | tr "'${delimiter}'" '\n' | sort -u | xargs | tr ' ' ',' +# the default ZITI_NETWORK (network name) is the short hostname +: "${DEFAULT_ZITI_NETWORK:="$(hostname -s)"}" + +# shellcheck disable=SC2155 +export DEFAULT_ZITI_HOME_LOCATION="${HOME}/.ziti/quickstart/${DEFAULT_ZITI_NETWORK}" +export ZITI_QUICKSTART_ENVROOT="${HOME}/.ziti/quickstart" + +function zitiLogin { + "${ZITI_BIN_DIR-}/ziti" edge login "${ZITI_EDGE_CTRL_ADVERTISED}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -y } - -function _pki_client_server { - local retVal dns_allow_list ZITI_CA_NAME_local ip_allow_list file_name - _check_env_variable ZITI_PKI ZITI_BIN_DIR +function cleanZitiController { + checkEnvVariable ZITI_HOME retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 fi - dns_allow_list=${1-} - ZITI_CA_NAME_local=$2 - ip_allow_list=$3 - file_name=$4 + rm -rf "${ZITI_HOME}/db" + mkdir "${ZITI_HOME}/db" + initializeController +} +function initializeController { + log_file="${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}-init.log" + "${ZITI_BIN_DIR-}/ziti-controller" edge init "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" -u "${ZITI_USER-}" -p "${ZITI_PWD}" &> "${log_file}" + echo -e "ziti-controller initialized. see $(BLUE "${log_file}") for details" +} +function startController { + log_file="${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}.log" + # shellcheck disable=SC2034 + "${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" &> "${log_file}" & + ZITI_EXPRESS_CONTROLLER_PID=$! + echo -e "ziti-controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${log_file}")" +} - if [[ "${ip_allow_list}" == "" ]]; then - ip_allow_list="127.0.0.1" +function stopController { + if [[ -n ${ZITI_EXPRESS_CONTROLLER_PID:-} ]]; then + kill "$ZITI_EXPRESS_CONTROLLER_PID" + # shellcheck disable=SC2181 + if [[ $? == 0 ]]; then + echo "Controller stopped." + return 0 + fi + else + echo "ERROR: you can only stop a controller process that was started with startController" >&2 + return 1 + fi +} + +function startRouter { + log_file="${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" + "${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${log_file}" 2>&1 & + ZITI_EXPRESS_EDGE_ROUTER_PID=$! + echo -e "Express Edge Router started as process id: $ZITI_EXPRESS_EDGE_ROUTER_PID. log located at: $(BLUE "${log_file}")" + +} + +function stopRouter { + if [[ -n ${ZITI_EXPRESS_EDGE_ROUTER_PID:-} ]]; then + # shellcheck disable=SC2015 + kill "${ZITI_EXPRESS_EDGE_ROUTER_PID}" && { + echo "INFO: stopped router" + } || { + echo "ERROR: something went wrong with stopping the router(s)" >&2 + return 1 + } + else + echo "ERROR: you can only stop a router process that was started with startRouter" >&2 + return 1 + fi +} + +function checkHostsFile { + ctrlexists=$(grep -c "${ZITI_CONTROLLER_HOSTNAME}" /etc/hosts) + edgectrlexists=$(grep -c "${ZITI_EDGE_CONTROLLER_HOSTNAME}" /etc/hosts) + erexists=$(grep -c "${ZITI_EDGE_ROUTER_HOSTNAME}" /etc/hosts) + + if [[ "0" = "${ctrlexists}" ]] || [[ "0" = "${edgectrlexists}" ]] || [[ "0" = "${erexists}" ]]; then + echo " " + echo -e "$(YELLOW "Ziti is generally used to create an overlay network. Generally speaking this will involve more than one host")" + echo -e "$(YELLOW "Since this is a script geared towards setting up a very minimal development environment it needs to make some")" + echo -e "$(YELLOW "assumptions. One of these assumptions is that the three specific entries are entered onto your hosts file.")" + echo -e "$(YELLOW "One or more of these are missing:")" + echo " " + if [[ "0" == "${ctrlexists}" ]]; then + echo -e " * $(RED "MISSING: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " + else + echo -e " * $(GREEN " FOUND: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " + fi + if [[ "0" == "${edgectrlexists}" ]]; then + echo -e " * $(RED "MISSING: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " + else + echo -e " * $(GREEN " FOUND: ${ZITI_EDGE_CONTROLLER_HOSTNAME}") " + fi + if [[ "0" == "${erexists}" ]]; then + echo -e " * $(RED "MISSING: ${ZITI_EDGE_ROUTER_HOSTNAME}") " + else + echo -e " * $(GREEN " FOUND: ${ZITI_EDGE_ROUTER_HOSTNAME}") " + fi + + echo " " + echo "The easiest way to correct this is to run the following command:" + echo " echo \"127.0.0.1 ${ZITI_CONTROLLER_HOSTNAME} ${ZITI_EDGE_CONTROLLER_HOSTNAME} ${ZITI_EDGE_ROUTER_HOSTNAME}\" | sudo tee -a /etc/hosts" + echo " " + echo "add these entries to your hosts file, and rerun the script when ready" + return 1 + else + echo -e "$(GREEN "Hosts file looks good")" + fi +} + +function verifyZitiVersionExists { + setupZitiHome + + if ! setOs; then + return 1 fi - # Dedupe the lists - dns_allow_list=$(_dedupe_list "${dns_allow_list}") - ip_allow_list=$(_dedupe_list "${ip_allow_list}") + detectArchitecture + + unset ZITI_BINARIES_VERSION + + ziticurl="$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/tags/"${ZITI_VERSION_OVERRIDE}")" + # shellcheck disable=SC2155 + export ZITI_BINARIES_FILE=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') + # shellcheck disable=SC2155 + export ZITI_BINARIES_VERSION=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.tag_name') + + # Check if there was an error while trying to get the requested version + if [[ "${ZITI_BINARIES_VERSION-}" == "null" ]]; then + echo "ERROR: response missing '.tag_name': ${ziticurl}" >&2 + return 1 + fi + + echo "ZITI_BINARIES_VERSION: ${ZITI_BINARIES_VERSION}" +} + +function detectArchitecture { + if [ -n "${ZITI_ARCH}" ]; then return; fi + ZITI_ARCH="amd64" + detected_arch="$(uname -m)" + # Apple M1 silicon + if [[ "${detected_arch}" == *"arm"* ]] && [[ "${ZITI_OSTYPE}" == "darwin" ]]; then + echo -e "$(YELLOW "WARN: It has been detected that you are using an Apple computer with ARM architecture. Deployment of Apple ARM architecture distributions is currently unsupported through git, the installer will pull darwin amd distribution instead.")" + # LLVM 64 bit backends have merged so some versions of *nix use aarch64 while others use arm64 for parity with Apple + elif [[ "${detected_arch}" == *"aarch64"* ]] || [[ "${detected_arch}" == *"arm64"* ]]; then + ZITI_ARCH="arm64" + elif [[ "${detected_arch}" == *"arm"* ]]; then + ZITI_ARCH="arm" + fi +} + +function getLatestZitiVersion { + setupZitiHome + + if ! setOs; then + return 1 + fi + + detectArchitecture + + unset ZITI_BINARIES_VERSION + + if [[ "${ZITI_BINARIES_VERSION-}" == "" ]]; then + zitilatest=$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/latest) + # shellcheck disable=SC2155 + export ZITI_BINARIES_FILE=$(echo "${zitilatest}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') + # shellcheck disable=SC2155 + export ZITI_BINARIES_VERSION=$(echo "${zitilatest}" | tr '\r\n' ' ' | jq -r '.tag_name') + fi + echo "ZITI_BINARIES_VERSION: ${ZITI_BINARIES_VERSION}" +} + +function getZiti { + setupZitiHome + checkEnvVariable ZITI_HOME + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + ziti_bin_root="${ZITI_BIN_ROOT-}" + if [[ "${ziti_bin_root}" == "" ]]; then + ziti_bin_root="${ZITI_HOME-}/ziti-bin" + fi + export ZITI_BIN_ROOT="${ziti_bin_root}/ziti-bin" + + mkdir -p "${ziti_bin_root}" + + # Get the latest version unless a specific version is specified + if [[ "${ZITI_VERSION_OVERRIDE-}" == "" ]]; then + if ! getLatestZitiVersion; then + return 1 + fi + else + # Check if an error occurred while trying to pull desired version (happens with incorrect version or formatting issue) + if ! verifyZitiVersionExists; then + echo -e " * $(RED "ERROR: This version of ziti (${ZITI_VERSION_OVERRIDE}) could not be found. Please check the version and try again. The version should follow the format \"vx.x.x\".") " + return 1 + fi + fi + + if [[ "${ZITI_BIN_DIR-}" == "" ]]; then export ZITI_BIN_DIR="${ziti_bin_root}/ziti-${ZITI_BINARIES_VERSION}"; else echo "Using ZITI_BIN_DIR: ${ZITI_BIN_DIR}"; fi + + ZITI_BINARIES_FILE_ABSPATH="${ziti_bin_root}/${ZITI_BINARIES_FILE}" + if ! test -f "${ZITI_BINARIES_FILE_ABSPATH}"; then + zitidl="https://github.com/openziti/ziti/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}" + echo -e 'Downloading '"$(BLUE "${zitidl}")"' to '"$(BLUE "${ZITI_BINARIES_FILE_ABSPATH}")" + curl -Ls "${zitidl}" -o "${ZITI_BINARIES_FILE_ABSPATH}" + else + echo -e "$(YELLOW 'Already Downloaded ')""$(BLUE "${ZITI_BINARIES_FILE}")"' at: '"${ZITI_BINARIES_FILE_ABSPATH}" + fi + + echo -e 'UNZIPPING '"$(BLUE "${ZITI_BINARIES_FILE_ABSPATH}")"' into: '"$(GREEN "${ZITI_BIN_DIR}")" + rm -rf "${ziti_bin_root}/ziti-${ZITI_BINARIES_VERSION-}" + if [[ "${ZITI_OSTYPE}" == "windows" ]]; then + unzip "${ZITI_BINARIES_FILE_ABSPATH}" -d "${ZITI_BIN_DIR}" + mv "${ZITI_BIN_DIR}/ziti/"* "${ZITI_BIN_DIR}/" + rm -rf "${ZITI_BIN_DIR}/ziti/"* + rmdir "${ZITI_BIN_DIR}/ziti/" + chmod +x "${ZITI_BIN_DIR}/"* + else + tar -xf "${ZITI_BINARIES_FILE_ABSPATH}" --directory "${ziti_bin_root}" + mv "${ziti_bin_root}/ziti" "${ZITI_BIN_DIR}" + fi + + echo -e 'Marking executables at '"$(GREEN "${ZITI_BIN_DIR}")"' executable' + chmod +x "${ZITI_BIN_DIR}/"* + + if [[ "${1-}" == "yes" ]]; then + echo "Adding ${ZITI_BIN_DIR} to the path if necessary:" + if [[ "$(echo "$PATH"|grep -q "${ZITI_BIN_DIR}" && echo "yes")" == "yes" ]]; then + echo -e "$(GREEN "${ZITI_BIN_DIR}") is already on the path" + else + echo -e "adding $(RED "${ZITI_BIN_DIR}") to the path" + export PATH=$PATH:"${ZITI_BIN_DIR}" + fi + fi +} + +function _portCheck { + if [[ "${1-}" == "" ]] || [[ "${2-}" == "" ]]; then + echo -e "_portCheck Usage: _portCheck " + return 0 + fi + + envVar="${1-}" + if [[ -n "$ZSH_VERSION" ]]; then + envVarValue="${(P)envVar}" + elif [[ -n "$BASH_VERSION" ]]; then + envVarValue="${!envVar}" + else + echo -e "$(YELLOW "Unknown/Unsupported shell, cannot verify availability of ${2-}'s intended port, proceed with caution")" + return 0 + fi + + echo -e "Checking if ${2-}'s port (${envVarValue}) is available" + portCheckResult=$(lsof -w -i :"${envVarValue}" 2> /dev/null) + if [[ "${portCheckResult}" != "" ]]; then # Controller management plane + echo -e "$(RED " ")" + echo -e "$(RED "The intended ${2-} port (${envVarValue}) is currently being used, the process using this port should be closed or the port value should be changed.")" + echo -e "$(RED "To use a different port, set the port value in ${envVar}")" + echo -e "$(RED " ")" + echo -e "$(RED "Example:")" + echo -e "$(RED "export ${envVar}=1234")" + echo -e "$(RED " ")" + return 1 + fi + return 0 +} + +function checkControllerName { + if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME}" == *['!'@#\$%^\&*\(\)_+]* ]]; then + echo -e "$(RED " - The provided Network name contains an invalid character: '!'@#\$%^\&*()_+")" + return 1 + fi + return 0 +} + +function unsetZitiEnv { + if [[ "${1-}" == "-s" ]]; then + # Silent... + for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; unset "${envvar}"; done + else + for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; echo unsetting "[${envvar}]${zEnvVar}"; unset "${envvar}"; done + fi + unset ZITIx_EXPRESS_COMPLETE +} + +function issueGreeting { + #echo "-------------------------------------------------------------" + echo " " + echo " _ _ _" + echo " ____ (_) | |_ (_)" + echo " |_ / | | | __| | |" + echo " / / | | | |_ | |" + echo " /___| |_| \__| |_|" + echo "-------------------------------------------------------------" + echo " " + echo "This script will make it trivial to setup a very simple environment locally which will allow you to start" + echo "learning ziti. This environment is suitable for development work only and is not a decent representation of" + echo "a fully redundant production-caliber network." + echo "" + echo "Please note that this script will write files to your home directory into a directory named .ziti." + echo -n "For you this location will be: " + echo -e "$(BLUE "${ZITI_QUICKSTART_ENVROOT}")" + echo " " +} + +function setupZitiNetwork { + if [[ "${1-}" == "" ]]; then + echo " " + echo "Creating a controller is effectively creating a network. The name of the network will be used when writing" + echo "configuration files locally. Choose the name of your network now. The format of the network name should resemble" + echo -n "what a hostname looks like. A good choice is to actually use your system's hostname: " + echo -e "$(BLUE "${DEFAULT_ZITI_NETWORK}")" + echo " " + echo -en "$(echo -ne "Network Name [$(BLUE "${DEFAULT_ZITI_NETWORK}")]: ")" + read -r ZITI_NETWORK + echo " " + if checkControllerName; then + : #clear to continue + if [[ "${ZITI_NETWORK-}" == "" ]]; then + ZITI_NETWORK="${DEFAULT_ZITI_NETWORK}" + fi + echo "name: ${ZITI_NETWORK-}" + else + echo "" + echo "============ FAILED TO SETUP NETWORK ============" + return 1 + fi + echo " " + else + ZITI_NETWORK="${1-}" + fi +} + +function setupZitiHome { + if [[ "${ZITI_HOME-}" == "" ]]; then + export ZITI_HOME="${HOME}/.ziti/quickstart/${ZITI_NETWORK-}" + echo -e "using default ZITI_HOME: $(BLUE "${ZITI_HOME}")" + fi +} + +function generateEnvFile { + + echo -e "Generating new network with name: $(BLUE "${ZITI_NETWORK-}")" + + if [[ "${ZITI_CONTROLLER_RAWNAME-}" == "" ]]; then export ZITI_CONTROLLER_RAWNAME="${ZITI_NETWORK-}"; fi + if [[ "${ZITI_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_CONTROLLER_HOSTNAME="${ZITI_CONTROLLER_RAWNAME}"; fi + if [[ "${ZITI_CTRL_PORT-}" == "" ]]; then export ZITI_CTRL_PORT="6262"; fi + if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; fi + + if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_RAWNAME="${ZITI_NETWORK-}"; fi + if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_HOSTNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}"; fi + + if [[ "${ZITI_ZAC_RAWNAME-}" == "" ]]; then export ZITI_ZAC_RAWNAME="${ZITI_NETWORK-}"; fi + if [[ "${ZITI_ZAC_HOSTNAME-}" == "" ]]; then export ZITI_ZAC_HOSTNAME="${ZITI_ZAC_RAWNAME}"; fi + + if [[ "${ZITI_BIN_ROOT-}" == "" ]]; then + export ZITI_BIN_ROOT="${ZITI_HOME-}/ziti-bin" + fi + + export ENV_FILE="${ZITI_HOME-}/${ZITI_NETWORK-}.env" + + if ! ziti_createEnvFile; then + return 1 + fi + + echo -e "environment file sourced from: $(BLUE "${ENV_FILE}")" +} + +function ziti_expressConfiguration { + if [[ "${ZITIx_EXPRESS_COMPLETE-}" != "" ]]; then + echo -e "$(RED " --- It looks like you've run an express install in this shell already. ---")" + echo -en "Would you like to clear existing Ziti variables and continue (y/N)? " + read -r + echo " " + if [[ "${REPLY}" == [Yy]* ]]; then + echo -e "$(GREEN "Clearing existing Ziti variables and continuing with express install")" + + # Check if the user chose a specific version + specifiedVersion="" + if [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]] && [[ "${ZITI_VERSION_OVERRIDE-}" != "${ZITI_BINARIES_VERSION-}" ]]; then + # Don't allow overriding the version if ziti quickstart was already run, the DB may not be compatible + echo -e "$(RED " --- Overriding the ziti version is not supported if the version differs from one already installed. ---")" + echo -en "Would you like to continue by using the latest version. (y/N)?" + read -r + echo " " + if [[ "${REPLY}" == [Yy]* ]]; then + unset ZITI_VERSION_OVERRIDE + else + return 1 + fi + elif [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]]; then + echo -e "$(RED " --- You have set the ZITI_VERSION_OVERRIDE value to ${ZITI_VERSION_OVERRIDE}. ---")" + echo -en "Would you like to use this version again, choosing no will pull the latest version. (y/N)?" + read -r + echo " " + if [[ "${REPLY}" == [Yy]* ]]; then + specifiedVersion="${ZITI_VERSION_OVERRIDE}" + fi + fi + + # Silently clear ziti variables + unsetZitiEnv "-s" + + if [[ "${specifiedVersion}" != "" ]]; then + export ZITI_VERSION_OVERRIDE="${specifiedVersion}" + fi + + # Stop any devices currently running to avoid port collisions + stopRouter + stopController + else + echo -e "$(RED " --- Exiting express install ---")" + return 1 + fi + fi + export ZITIx_EXPRESS_COMPLETE="true" + echo " " + echo "___________ _______________________________________^__" + echo " ___ ___ ||| ___ ___ ___ ___ ___ | __ ,----\ " + echo "| | | |||| | | | | | | | | | | | | |_____\ " + echo "|___| |___|||| |___| |___| |___| | O | O | | | | \ " + echo " ||| ===== EXPRESS ==== |___|___| | |__| )" + echo "___________|||______________________________|______________/" + echo " ||| /--------" + echo "-----------'''---------------------------------------'" + echo "" + if [[ "${ZITI_CONTROLLER_RAWNAME-}" != "" ]]; then echo "ZITI_CONTROLLER_RAWNAME OVERRIDDEN: $ZITI_CONTROLLER_RAWNAME"; fi + if [[ "${ZITI_CONTROLLER_HOSTNAME-}" != "" ]]; then echo "ZITI_CONTROLLER_HOSTNAME OVERRIDDEN: $ZITI_CONTROLLER_HOSTNAME"; fi + if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" != "" ]]; then echo "ZITI_EDGE_CONTROLLER_RAWNAME OVERRIDDEN: $ZITI_EDGE_CONTROLLER_RAWNAME"; fi + if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" != "" ]]; then echo "ZITI_EDGE_CONTROLLER_HOSTNAME OVERRIDDEN: $ZITI_EDGE_CONTROLLER_HOSTNAME"; fi + if [[ "${ZITI_ZAC_RAWNAME-}" != "" ]]; then echo "ZITI_ZAC_RAWNAME OVERRIDDEN: $ZITI_ZAC_RAWNAME"; fi + if [[ "${ZITI_ZAC_HOSTNAME-}" != "" ]]; then echo "ZITI_ZAC_HOSTNAME OVERRIDDEN: $ZITI_ZAC_HOSTNAME"; fi + if [[ "${ZITI_EDGE_ROUTER_HOSTNAME-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_HOSTNAME OVERRIDDEN: $ZITI_EDGE_ROUTER_HOSTNAME"; fi + if [[ "${ZITI_EDGE_ROUTER_PORT-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_PORT OVERRIDDEN: $ZITI_EDGE_ROUTER_PORT"; fi + if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" != "" ]]; then echo "ZITI_EDGE_ROUTER_RAWNAME OVERRIDDEN: $ZITI_EDGE_ROUTER_RAWNAME"; fi + + echo " " + echo " " + echo -e "******** Setting Up Environment ********" + if [[ "${1-}" == "" ]]; then + nw="${DEFAULT_ZITI_NETWORK}" + else + nw="${1-}" + fi + + setupZitiNetwork "${nw}" + setupZitiHome + echo -e "ZITI HOME SET TO: $(BLUE "${ZITI_HOME}")" + + if ! getZiti "no"; then + echo -e "$(RED "getZiti failed")" + return 1 + fi + if ! generateEnvFile; then + echo "Exiting as env file was not generated" + return 1 + fi + + # Check Ports + returnCnt=0 + _portCheck "ZITI_CTRL_PORT" "Controller" + returnCnt=$((returnCnt + $?)) + _portCheck "ZITI_EDGE_ROUTER_PORT" "Edge Router" + returnCnt=$((returnCnt + $?)) + _portCheck "ZITI_EDGE_CONTROLLER_PORT" "Edge Controller" + returnCnt=$((returnCnt + $?)) + _portCheck "ZITI_CTRL_MGMT_PORT" "Controller Management Plane" + returnCnt=$((returnCnt + $?)) + if [[ "${ZITI_EDGE_ROUTER_LISTENER_BIND_PORT-}" != "" ]]; then + # This port can be explicitly set but is not always, only check if set + _portCheck "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" "Router Listener Bind Port" + returnCnt=$((returnCnt + $?)) + fi + if [[ "returnCnt" -gt "0" ]]; then return 1; fi + + #checkHostsFile + + echo " " + echo " " + echo -e "******** Setting Up Public Key Infrastructure ********" + createPki + + echo " " + echo " " + echo -e "******** Setting Up Controller ********" + createControllerConfig + #createControllerSystemdFile + initializeController + startController + echo "waiting for the controller to come online to allow the edge router to enroll" + + waitForController + + zitiLogin + + echo " " + echo " " + echo -e "******** Setting Up Edge Routers ********" + echo -e "---------- Creating an edge router policy allowing all identities to connect to routers with a $(GREEN "#public") attribute" + "${ZITI_BIN_DIR-}/ziti" edge delete edge-router-policy allEdgeRouters > /dev/null + "${ZITI_BIN_DIR-}/ziti" edge create edge-router-policy allEdgeRouters --edge-router-roles '#public' --identity-roles '#all' > /dev/null + + echo -e "---------- Creating a service edge router policy allowing all services to use $(GREEN "#public") edge routers" + "${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcAllRouters > /dev/null + "${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcAllRouters --edge-router-roles '#all' --service-roles '#all' > /dev/null + + echo "USING ZITI_EDGE_ROUTER_RAWNAME: $ZITI_EDGE_ROUTER_RAWNAME" + + createRouterPki "${ZITI_EDGE_ROUTER_RAWNAME}" + + createEdgeRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" + #createRouterSystemdFile "${ZITI_EDGE_ROUTER_RAWNAME}" + + echo "---------- Creating edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." + "${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${ZITI_EDGE_ROUTER_RAWNAME}" > /dev/null + "${ZITI_BIN_DIR-}/ziti" edge create edge-router "${ZITI_EDGE_ROUTER_RAWNAME}" -o "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" -t -a "public"> /dev/null + sleep 1 + echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." + + "${ZITI_BIN_DIR-}/ziti-router" enroll "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" --jwt "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" &> "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.enrollment.log" + echo "" + + stopController + echo "Edge Router enrolled. Controller stopped." + + echo "" + echo -e "$(GREEN "Congratulations. Express setup complete!")" + echo -e "Start your Ziti Controller by running the function: $(BLUE "startController")" + echo -e "Start your Ziti Edge Router by running : $(BLUE 'startRouter')" + echo "" +} + +function decideToUseDefaultZitiHome { + yn="" + while true + do + echo "ZITI_HOME has not been set. Do you want to use the default ZITI_HOME: ${DEFAULT_ZITI_HOME_LOCATION}" + echo " " + echo -en "Select an action: " + read -r yn + case $yn in + [yY]* ) + ZITI_HOME="${DEFAULT_ZITI_HOME_LOCATION}" + break;; + [Nn]* ) + echo "" + return 1;; + * ) + echo " " + echo "Answer $yn is not valid. Please answer yes or no. (y/n [yes/NO])";; + esac + yn= + done + echo " " +} + +function decideOperation { + yn="${1-}" + while true + do + if [[ "${yn}" == "" ]]; then + echo "What sort of operation are you looking to perform?" + echo " 1.) Express configuration - a simple overlay will be spawned containing one controller and two edge routers" + echo " 2.) Create Controller configuration - answer a few questions and a controller config will be emitted" + echo " 3.) Create Edge Router configuration - answer a few questions and an edge router config will be emitted" + echo " 4.) Start a network with the provided name" + echo " " + echo -en "Select an action: " + read -r yn + fi + case $yn in + [1]* ) + ziti_expressConfiguration "$2" + break;; + [2]* ) + generateEnvFile + + ;; + [3]* ) + echo "333 has been chosen" + echo " " + ;; + [4]* ) + echo "4444 has been chosen" + echo " " + ;; + [yYqQeE]* ) + break + ;; + [Nn]* ) + echo ""; echo "Ok - come back when you're ready." + exit;; + * ) echo "Please answer yes or no. (yes/NO)";; + esac + yn= + done + echo " " +} + +function expressInstall { + #greet the user with the banner and quick blurb about what to expect + issueGreeting + + #make sure the user has all the necessary commands to be successful + checkPrereqs + retval=$? + if [ $retval -ne 0 ]; then + return 1 + fi + echo "Let's get started creating your local development network!" + echo "" + echo "" + + #prompt the user for input and do what they want/need + decideOperation 1 "${1-}" +} + +function pki_client_server { + allow_list=${1-} + ZITI_CA_NAME_local=$2 + ip_local=$3 + file_name=$4 + + if [[ "${ip_local}" == "" ]]; then + ip_local="127.0.0.1" + fi if ! test -f "${ZITI_PKI}/${ZITI_CA_NAME_local}/keys/${file_name}-server.key"; then - echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list} / ${ip_allow_list}" - "${ZITI_BIN_DIR-}/ziti" pki create server --pki-root="${ZITI_PKI}" --ca-name "${ZITI_CA_NAME_local}" \ + echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${allow_list} / ${ip_local}" + "${ZITI_BIN_DIR-}/ziti" pki create server --pki-root="${ZITI_PKI_OS_SPECIFIC}" --ca-name "${ZITI_CA_NAME_local}" \ --server-file "${file_name}-server" \ - --dns "${dns_allow_list}" --ip "${ip_allow_list}" \ + --dns "${allow_list}" --ip "${ip_local}" \ --server-name "${file_name} server certificate" else - echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list}" + echo "Creating server cert from ca: ${ZITI_CA_NAME_local} for ${allow_list}" echo "key exists" fi if ! test -f "${ZITI_PKI}/${ZITI_CA_NAME_local}/keys/${file_name}-client.key"; then - echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list}" - "${ZITI_BIN_DIR-}/ziti" pki create client --pki-root="${ZITI_PKI}" --ca-name "${ZITI_CA_NAME_local}" \ + echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${allow_list}" + "${ZITI_BIN_DIR-}/ziti" pki create client --pki-root="${ZITI_PKI_OS_SPECIFIC}" --ca-name "${ZITI_CA_NAME_local}" \ --client-file "${file_name}-client" \ --key-file "${file_name}-server" \ --client-name "${file_name}" else - echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${dns_allow_list}" + echo "Creating client cert from ca: ${ZITI_CA_NAME_local} for ${allow_list}" echo "key exists" fi echo " " } -function _pki_create_ca { - local cert retVal - _check_env_variable ZITI_PKI ZITI_BIN_DIR - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - cert="${1}" +function pki_create_ca { + cert=$1 echo "Creating CA: ${cert}" if ! test -f "${ZITI_PKI}/${cert}/keys/${cert}.key"; then - "${ZITI_BIN_DIR}/ziti" pki create ca --pki-root="${ZITI_PKI}" --ca-file="${cert}" --ca-name="${cert} Root CA" + "${ZITI_BIN_DIR}/ziti" pki create ca --pki-root="${ZITI_PKI_OS_SPECIFIC}" --ca-file="${cert}" --ca-name="${cert} Root CA" else echo "key exists" fi echo " " } -function _pki_create_intermediate { - local retVal - _check_env_variable ZITI_PKI ZITI_BIN_DIR - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi +function pki_create_intermediate { echo "Creating intermediate: ${1} ${2} ${3}" if ! test -f "${ZITI_PKI}/${2}/keys/${2}.key"; then - "${ZITI_BIN_DIR}/ziti" pki create intermediate --pki-root "${ZITI_PKI}" --ca-name "${1}" \ + "${ZITI_BIN_DIR}/ziti" pki create intermediate --pki-root "${ZITI_PKI_OS_SPECIFIC}" --ca-name "${1}" \ --intermediate-name "${2}" \ --intermediate-file "${2}" --max-path-len "${3}" else @@ -167,118 +737,344 @@ function _pki_create_intermediate { fi echo " " } - -# Checks that a specific command or set of commands exist on the path -function _check_prereq { - local missing_requirements="" arg - for arg - do - if ! [[ -x "$(command -v "${arg}")" ]]; then - missing_requirements="${missing_requirements}\n* ${arg}" - fi - done - # Are requirements missing if yes, stop here and help 'em out - if ! [[ "" = "${missing_requirements}" ]]; then - echo " " - echo "You're missing one or more commands that are used in this script." - echo "Please ensure the commands listed are on the path and then try again." - echo "${missing_requirements}" - echo " " - echo " " - return 1 - fi +function printUsage() { + echo "Usage: ${1-} [cert to test] [ca pool to use]" } -# Disable shellcheck for parameter expansion error, this function supports multiple shells -# shellcheck disable=SC2296 -# Check if an environment variable is set, if not, throw an error -function _check_env_variable() { - local _error=false arg - for arg - do - # Parameter expansion is different between shells - if [[ -n "$ZSH_VERSION" ]]; then - if [[ -z "${(P)arg}" ]]; then - echo -e " * ERROR: $(RED "${arg} is not set") " - _error=true - fi - elif [[ -n "$BASH_VERSION" ]]; then - if [[ -z "${!arg}" ]]; then - echo -e " * ERROR: $(RED "${arg} is not set") " - _error=true - fi - else - echo -e " * $(RED "Unsupported shell, supply a PR or log an issue on https://github.com/openziti/ziti") " +function verifyCertAgainstPool() { + if [[ "" == "${1-}" ]] + then + printUsage "verifyCertAgainstPool" return 1 - fi - done + fi - if [[ "true" == "${_error}" ]]; then - return 1 + if [[ "" == "$2" ]] + then + printUsage "verifyCertAgainstPool" + return 1 + fi + + echo " Verifying that this certificate:" + echo " - ${1-}" + echo " is valid for this ca pool:" + echo " - $2" + echo "" + openssl verify -partial_chain -CAfile "$2" "${1-}" + # shellcheck disable=SC2181 + if [ $? -eq 0 ]; then + echo "" + echo "============ SUCCESS! ============" else - return 0 + echo "" + echo "============ FAILED TO VALIDATE ============" fi } -function _issue_preamble { - echo -e "$(PURPLE "-------------------------------------------------------------")" - echo -e "$(PURPLE " _ _ _")" - echo -e "$(PURPLE " ____ (_) | |_ (_)")" - echo -e "$(PURPLE " |_ / | | | __| | |")" - echo -e "$(PURPLE " / / | | | |_ | |")" - echo -e "$(PURPLE " /___| |_| \__| |_|")" - echo "" - echo -e "$(PURPLE "-------------------------------------------------------------")" - echo "" - echo "This script will make it trivial to set up a very simple environment locally which will allow you to start" - echo "learning ziti. This environment is suitable for development work only and is not a decent representation of" - echo "a fully redundant production-caliber network." - echo "" +function showIssuerAndSubjectForPEM() { + echo "Displaying Issuer and Subject for cert pool:" + echo " ${1-}" + openssl crl2pkcs7 -nocrl -certfile "${1-}" | openssl pkcs7 -print_certs -text -noout | grep -E "(Subject|Issuer)" } -function _issue_greeting { - echo "Please note that, by default, this script will write files to your home directory into a directory named .ziti." - echo -n "The currently configured location for these files will be: " - echo -e "$(BLUE "${ZITI_HOME}")" - echo "" - echo "" - echo " \----------------------------------\ " - echo " \ \ __ " - echo " \ Welcome To: \ | \ " - echo " > Ziti Express 2.0 >------| \ ______ " - echo " / / --- \_____/**|_|_\____ | " - echo " / / \_______ --------- __>-} " - echo " /----------------------------------/ / \_____|_____/ | " - echo " * | " - echo " {O} " - echo "" - echo "Let's get started creating your local development network!" - echo "" +function createRouterPki { + # Allow router name to be passed in as arg + router_name="${1-}" + if [[ "${router_name}" == "" ]]; then + echo -e " * ERROR: $(RED "routerName needs to be supplied") " + return 1 + fi + mkdir -p "${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}" + export ZITI_ROUTER_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/client.cert" + export ZITI_ROUTER_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.cert" + export ZITI_ROUTER_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/server.key" + export ZITI_ROUTER_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/routers/${router_name}/cas.cert" + pki_client_server "${router_name},localhost,127.0.0.1,${ZITI_NETWORK}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}" "${router_name}" } -# Clear all environment variables prefixed with ZITI_ (use -s parameter to do so without any output) -function unsetZitiEnv { - local param1 zEnvVar envvar - param1="${1-}" - for zEnvVar in $(set | grep -e "^ZITI_" | sort); do - envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)" - if [[ "-s" != "${param1-}" ]]; then echo "unsetting [${envvar}] ${zEnvVar}"; fi - unset "${envvar}" - done - # Have to explicitly unset this one (no ZITI_ prefix) - unset ZITIx_EXPRESS_COMPLETE +function createPrivateRouterConfig { + # Allow router name to be passed in as arg + router_name="${1-}" + if [[ "${router_name}" == "" ]]; then + + # If router name is not passed as arg, prompt user for input + echo -e "$(YELLOW "createPrivateRouterConfig requires a router name to be supplied") " + default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + echo -en "Enter router name (${default_router_name}):" + read -r router_name + + # Accept the default if no name provided + if [[ "${router_name}" == "" ]]; then + # Check for overwrite of default file + router_name="${default_router_name}" + if [[ -f "${ZITI_HOME-}/${router_name}.yaml" ]]; then + echo -en "This will overwrite the existing file, continue (y/N)? " + read -r + echo " ${REPLY}" + if [[ "${REPLY}" == [^Yy]* ]]; then + echo -e "$(RED " --- Cancelling overwrite ---")" + return 1 + fi + fi + fi + fi + + # Make sure necessary env variables are set + checkEnvVariable ZITI_HOME + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + output_file="${ZITI_HOME-}/${router_name}.yaml" + + getFileOverwritePermission "${output_file}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}" + echo -e "Router configuration file written to: $(BLUE "${output_file}")" } -# Checks for explicit environment variables or set as defaults, also creating directories as needed -function setupEnvironment { - local pwd_reply - echo "Populating environment variables" - # General Ziti Values - _setup_ziti_network - _setup_ziti_home +function createPki { + echo "Generating PKI" - # Get Controller Credentials - if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; else echo "ZITI_USER overridden: ${ZITI_USER}"; fi + pki_create_ca "${ZITI_CONTROLLER_ROOTCA_NAME}" + pki_create_ca "${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}" + pki_create_ca "${ZITI_SIGNING_ROOTCA_NAME}" + + ZITI_SPURIOUS_INTERMEDIATE="${ZITI_SIGNING_INTERMEDIATE_NAME}_spurious_intermediate" + pki_create_intermediate "${ZITI_CONTROLLER_ROOTCA_NAME}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" 1 + pki_create_intermediate "${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}" "${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}" 1 + pki_create_intermediate "${ZITI_SIGNING_ROOTCA_NAME}" "${ZITI_SPURIOUS_INTERMEDIATE}" 2 + pki_create_intermediate "${ZITI_SPURIOUS_INTERMEDIATE}" "${ZITI_SIGNING_INTERMEDIATE_NAME}" 1 + + echo " " + pki_allow_list_dns="${ZITI_CONTROLLER_HOSTNAME},localhost,${ZITI_NETWORK}" + if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME}" != "" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${ZITI_EDGE_CONTROLLER_HOSTNAME}"; fi + if [[ "${EXTERNAL_DNS}" != "" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${EXTERNAL_DNS}"; fi + pki_allow_list_ip="127.0.0.1" + if [[ "${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}"; fi + if [[ "${EXTERNAL_IP}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${EXTERNAL_IP}"; fi + + pki_client_server "${pki_allow_list_dns}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${pki_allow_list_ip}" "${ZITI_CONTROLLER_HOSTNAME}" + pki_client_server "${pki_allow_list_dns}" "${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}" "${pki_allow_list_ip}" "${ZITI_EDGE_CONTROLLER_HOSTNAME}" +} + + + +function createFabricRouterConfig { + # Allow router name to be passed in as arg + router_name="${1-}" + if [[ "${router_name}" == "" ]]; then + + # If router name is not passed as arg, prompt user for input + echo -e "$(YELLOW "createFabricRouterConfig requires a router name to be supplied") " + default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + echo -en "Enter router name (${default_router_name}):" + read -r router_name + + # Accept the default if no name provided + if [[ "${router_name}" == "" ]]; then + # Check for overwrite of default file + router_name="${default_router_name}" + fi + fi + + checkEnvVariable ZITI_HOME + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + output_file="${ZITI_HOME}/${router_name}.yaml" + + getFileOverwritePermission "${output_file}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + "${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}" + echo -e "Fabric router configuration file written to: $(BLUE "${output_file}")" +} + +function createEdgeRouterWssConfig { + # Allow router name to be passed in as arg + router_name="${1-}" + if [[ "${router_name}" == "" ]]; then + + # If router name is not passed as arg, prompt user for input + echo -e "$(YELLOW "createEdgeRouterWssConfig requires a router name to be supplied") " + default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + echo -en "Enter router name (${default_router_name}):" + read -r router_name + + # Accept the default if no name provided + if [[ "${router_name}" == "" ]]; then + # Check for overwrite of default file + router_name="${default_router_name}" + getFileOverwritePermission "${ZITI_HOME-}/${router_name}.yaml" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + fi + fi + + # Make sure necessary env variables are set + checkEnvVariable ZITI_HOME ZITI_BIN_DIR + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + output_file="${ZITI_HOME-}/${router_name}.yaml" + + getFileOverwritePermission "${output_file}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + "${ZITI_BIN_DIR}/ziti" create config router edge --wss --routerName "${router_name}" > "${output_file}" + echo -e "WSS Edge router wss configuration file written to: $(BLUE "${output_file}")" +} + +# shellcheck disable=SC2120 +function createEdgeRouterConfig { + # Allow router name to be passed in as arg + router_name="${1-}" + if [[ "${router_name}" == "" ]]; then + + # If router name is not passed as arg, prompt user for input + echo -e "$(YELLOW "createEdgeRouterConfig requires a router name to be supplied") " + default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + echo -en "Enter router name (${default_router_name}):" + read -r router_name + + # Accept the default if no name provided + if [[ "${router_name}" == "" ]]; then + # Check for overwrite of default file + router_name="${default_router_name}" + getFileOverwritePermission "${ZITI_HOME-}/${router_name}.yaml" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + fi + fi + + # Make sure necessary env variables are set + checkEnvVariable ZITI_HOME ZITI_BIN_DIR + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + output_file="${ZITI_HOME}/${router_name}.yaml" + + getFileOverwritePermission "${output_file}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" > "${output_file}" + echo -e "edge router configuration file written to: $(BLUE "${output_file}")" +} + +# shellcheck disable=SC2120 +function createControllerConfig { + # Allow controller name to be passed in as arg + controller_name="${1-}" + # If no controller name provided and env var is not set, prompt user for a controller name + if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then + echo -e "$(YELLOW "createControllerConfig requires a controller name to be supplied") " + echo -en "Enter controller name: " + read -r controller_name + + # Quit if no name is provided + if [[ "${controller_name}" == "" ]]; then + echo -e "$(RED " --- Invalid controller name provided ---")" + return 1 + fi + # If no controller name provided and env var is set, use env var + elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then + controller_name="${ZITI_EDGE_CONTROLLER_RAWNAME}" + fi + + # Make sure necessary env variables are set + checkEnvVariable ZITI_HOME + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + cat "${ZITI_CTRL_IDENTITY_SERVER_CERT}" > "${ZITI_CTRL_IDENTITY_CA}" + cat "${ZITI_SIGNING_CERT}" >> "${ZITI_CTRL_IDENTITY_CA}" + echo -e "wrote CA file to: $(BLUE "${ZITI_CTRL_IDENTITY_CA}")" + + output_file="${ZITI_HOME}/${controller_name}.yaml" + + getFileOverwritePermission "${output_file}" + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + "${ZITI_BIN_DIR}/ziti" create config controller > "${output_file}" + + echo -e "Controller configuration file written to: $(BLUE "${output_file}")" +} + +# shellcheck disable=SC2120 +function ziti_createEnvFile { + checkEnvVariable ZITI_HOME + retVal=$? + if [[ "${retVal}" != 0 ]]; then + if decideToUseDefaultZitiHome; then + ZITI_HOME="${DEFAULT_ZITI_HOME_LOCATION}" + else + return 1 + fi + fi + + export ZITI_HOME="${ZITI_HOME}" + if [[ "${ZITI_OSTYPE}" == "windows" ]]; then + ZITI_HOME_OS_SPECIFIC="$(cygpath -m "${ZITI_HOME}")" + export ZITI_HOME_OS_SPECIFIC + else + export ZITI_HOME_OS_SPECIFIC="${ZITI_HOME}" + fi + export ENV_FILE="${ZITI_HOME}/${ZITI_NETWORK}.env" + export ZITI_SHARED="${ZITI_HOME}" + + checkEnvVariable ENV_FILE + retVal=$? + if [[ "${retVal}" != 0 ]]; then + return 1 + fi + + if [[ "${network_name-}" != "" ]]; then + export ZITI_NETWORK="${network_name}" + fi + + if [[ "${ZITI_NETWORK-}" == "" ]]; then + if [[ "${1-}" != "" ]]; then + export ZITI_NETWORK="${1-}" + fi + if [[ "${ZITI_NETWORK-}" = "" ]]; then + echo -e "$(YELLOW "WARN: ZITI_NETWORK HAS NOT BEEN DECLARED! USING hostname: ${DEFAULT_ZITI_NETWORK}")" + # shellcheck disable=SC2155 + export ZITI_NETWORK="${DEFAULT_ZITI_NETWORK}" + fi + fi + + echo "ZITI_NETWORK set to: ${ZITI_NETWORK}" + + if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; fi if [[ "${ZITI_PWD-}" == "" ]]; then ZITI_PWD="$(LC_ALL=C tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c32)" echo -en "Do you want to keep the generated admin password '$ZITI_PWD'? (Y/n) " @@ -287,97 +1083,73 @@ function setupEnvironment { if [[ -z "${pwd_reply}" || ${pwd_reply} =~ [yY] ]]; then echo "INFO: using ZITI_PWD=${ZITI_PWD}" else - echo -en "Type the preferred admin password and press " + echo -en "Type the preferred admin password and press " read -r ZITI_PWD fi - else - echo "ZITI_PWD overridden: ${ZITI_PWD}" fi + if [[ "${ZITI_DOMAIN_SUFFIX-}" == "" ]]; then export ZITI_DOMAIN_SUFFIX=""; fi + if [[ "${ZITI_ID-}" == "" ]]; then export ZITI_ID="${ZITI_HOME}/identities.yaml"; fi - # PKI Values - if [[ "${ZITI_PKI-}" == "" ]]; then export ZITI_PKI="${ZITI_HOME}/pki"; else echo "ZITI_PKI overridden: ${ZITI_PKI}"; fi - if [[ "${ZITI_PKI_SIGNER_CERT_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_CERT_NAME="${ZITI_NETWORK}-signing"; else echo "ZITI_PKI_SIGNER_CERT_NAME overridden: ${ZITI_PKI_SIGNER_CERT_NAME}"; fi - if [[ "${ZITI_PKI_SIGNER_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_ROOTCA_NAME="${ZITI_PKI_SIGNER_CERT_NAME}-root-ca"; else echo "ZITI_PKI_SIGNER_ROOTCA_NAME overridden: ${ZITI_PKI_SIGNER_ROOTCA_NAME}"; fi - if [[ "${ZITI_PKI_SIGNER_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_SIGNER_INTERMEDIATE_NAME="${ZITI_PKI_SIGNER_CERT_NAME}-intermediate"; else echo "ZITI_PKI_SIGNER_INTERMEDIATE_NAME overridden: ${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}"; fi - if [[ "${ZITI_PKI_SIGNER_CERT}" == "" ]]; then export ZITI_PKI_SIGNER_CERT="${ZITI_PKI}/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}/certs/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}.cert"; else echo "ZITI_PKI_SIGNER_CERT overridden: ${ZITI_PKI_SIGNER_CERT}"; fi - if [[ "${ZITI_PKI_SIGNER_KEY}" == "" ]]; then export ZITI_PKI_SIGNER_KEY="${ZITI_PKI}/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}/keys/${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}.key"; else echo "ZITI_PKI_SIGNER_KEY overridden: ${ZITI_PKI_SIGNER_KEY}"; fi + export ZITI_PKI="${ZITI_SHARED}/pki" + if [[ "${ZITI_OSTYPE}" == "windows" ]]; then + ZITI_PKI_OS_SPECIFIC="$(cygpath -m "${ZITI_PKI}")" + export ZITI_PKI_OS_SPECIFIC + else + export ZITI_PKI_OS_SPECIFIC="${ZITI_PKI}" + fi + if [[ "${ZITI_EDGE_CONTROLLER_PORT-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_PORT="1280"; fi - # Run these functions to populate other pertinent environment values - _detect_architecture # ZITI_ARCH - _detect_OS # ZITI_OSTYPE - getLatestZitiVersion # ZITI_BINARIES_FILE & ZITI_BINARIES_VERSION + if [[ "${ZITI_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_CONTROLLER_HOSTNAME="${ZITI_CONTROLLER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi + if [[ "${ZITI_CTRL_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_ADVERTISED_ADDRESS="${ZITI_CONTROLLER_HOSTNAME}"; fi + if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" == "" ]]; then export ZITI_EDGE_CONTROLLER_HOSTNAME="${ZITI_EDGE_CONTROLLER_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi + if [[ "${ZITI_ZAC_HOSTNAME-}" == "" ]]; then export ZITI_ZAC_HOSTNAME="${ZITI_ZAC_RAWNAME}${ZITI_DOMAIN_SUFFIX}"; fi + if [[ "${ZITI_EDGE_CTRL_ADVERTISED-}" == "" ]]; then export ZITI_EDGE_CTRL_ADVERTISED="${ZITI_EDGE_CONTROLLER_HOSTNAME}:${ZITI_EDGE_CONTROLLER_PORT}"; fi - # Must run after the above (dependent on other variables) - _set_ziti_bin_dir + export ZITI_SIGNING_CERT_NAME="${ZITI_NETWORK}-signing" - # Controller Values - if [[ "${ZITI_CTRL_NAME-}" == "" ]]; then export ZITI_CTRL_NAME="${ZITI_NETWORK}"; else echo "ZITI_CTRL_NAME overridden: ${ZITI_CTRL_NAME}"; fi - if [[ "${ZITI_CTRL_LISTENER_PORT-}" == "" ]]; then export ZITI_CTRL_LISTENER_PORT="6262"; else echo "ZITI_CTRL_LISTENER_PORT overridden: ${ZITI_CTRL_LISTENER_PORT}"; fi - if [[ "${ZITI_CTRL_EDGE_ADVERTISED_PORT-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT="1280"; else echo "ZITI_CTRL_EDGE_ADVERTISED_PORT overridden: ${ZITI_CTRL_EDGE_ADVERTISED_PORT}"; fi - if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS-}" == "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_NETWORK-}"; else echo "ZITI_CTRL_EDGE_ADVERTISED_ADDRESS overridden: ${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}"; fi - if [[ "${ZITI_PKI_CTRL_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_ROOTCA_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-root-ca"; else echo "ZITI_PKI_CTRL_ROOTCA_NAME overridden: ${ZITI_PKI_CTRL_ROOTCA_NAME}"; fi - if [[ "${ZITI_PKI_CTRL_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_INTERMEDIATE_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-intermediate"; else echo "ZITI_PKI_CTRL_INTERMEDIATE_NAME overridden: ${ZITI_PKI_CTRL_INTERMEDIATE_NAME}"; fi - if [[ "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_EDGE_ROOTCA_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-root-ca"; else echo "ZITI_PKI_CTRL_EDGE_ROOTCA_NAME overridden: ${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}"; fi - if [[ "${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME-}" == "" ]]; then export ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-intermediate"; else echo "ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME overridden: ${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}"; fi - if [[ "${ZITI_PKI_CTRL_SERVER_CERT-}" == "" ]]; then export ZITI_PKI_CTRL_SERVER_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.chain.pem"; else echo "ZITI_PKI_CTRL_SERVER_CERT overridden: ${ZITI_PKI_CTRL_SERVER_CERT}"; fi - if [[ "${ZITI_PKI_CTRL_KEY-}" == "" ]]; then export ZITI_PKI_CTRL_KEY="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.key"; else echo "ZITI_PKI_CTRL_KEY overridden: ${ZITI_PKI_CTRL_KEY}"; fi - if [[ "${ZITI_PKI_CTRL_CA-}" == "" ]]; then export ZITI_PKI_CTRL_CA="${ZITI_PKI}/cas.pem"; else echo "ZITI_PKI_CTRL_CA overridden: ${ZITI_PKI_CTRL_CA}"; fi - if [[ "${ZITI_PKI_CTRL_CERT-}" == "" ]]; then export ZITI_PKI_CTRL_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-client.cert"; else echo "ZITI_PKI_CTRL_CERT overridden: ${ZITI_PKI_CTRL_CERT}"; fi - if [[ "${ZITI_PKI_EDGE_CERT-}" == "" ]]; then export ZITI_PKI_EDGE_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-client.cert"; else echo "ZITI_PKI_EDGE_CERT overridden: ${ZITI_PKI_EDGE_CERT}"; fi - if [[ "${ZITI_PKI_EDGE_SERVER_CERT}" == "" ]]; then export ZITI_PKI_EDGE_SERVER_CERT="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.chain.pem"; else echo "ZITI_PKI_EDGE_SERVER_CERT overridden: ${ZITI_PKI_EDGE_SERVER_CERT}"; fi - if [[ "${ZITI_PKI_EDGE_KEY}" == "" ]]; then export ZITI_PKI_EDGE_KEY="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/keys/${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}-server.key"; else echo "ZITI_PKI_EDGE_KEY overridden: ${ZITI_PKI_EDGE_KEY}"; fi - if [[ "${ZITI_PKI_EDGE_CA}" == "" ]]; then export ZITI_PKI_EDGE_CA="${ZITI_PKI}/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}/certs/${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}.cert"; else echo "ZITI_PKI_EDGE_CA overridden: ${ZITI_PKI_EDGE_CA}"; fi + export ZITI_CONTROLLER_ROOTCA_NAME="${ZITI_CONTROLLER_HOSTNAME}-root-ca" + export ZITI_CONTROLLER_INTERMEDIATE_NAME="${ZITI_CONTROLLER_HOSTNAME}-intermediate" - # Router Values - if [[ "${ZITI_EDGE_ROUTER_NAME-}" == "" ]]; then export ZITI_EDGE_ROUTER_NAME="${ZITI_NETWORK}-edge-router"; else echo "ZITI_EDGE_ROUTER_NAME overridden: ${ZITI_EDGE_ROUTER_NAME}"; fi - if [[ "${ZITI_EDGE_ROUTER_PORT-}" == "" ]]; then export ZITI_EDGE_ROUTER_PORT="3022"; else echo "ZITI_EDGE_ROUTER_PORT overridden: ${ZITI_EDGE_ROUTER_PORT}"; fi - if [[ "${EXTERNAL_DNS-}" != "" ]]; then export ZITI_EDGE_ROUTER_ADVERTISED_HOST="${EXTERNAL_DNS}"; fi + export ZITI_EDGE_CONTROLLER_ROOTCA_NAME="${ZITI_EDGE_CONTROLLER_HOSTNAME}-root-ca" + export ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME="${ZITI_EDGE_CONTROLLER_HOSTNAME}-intermediate" - # Set up directories - mkdir -p "${ZITI_HOME}" + export ZITI_SIGNING_ROOTCA_NAME="${ZITI_SIGNING_CERT_NAME}-root-ca" + export ZITI_SIGNING_INTERMEDIATE_NAME="${ZITI_SIGNING_CERT_NAME}-intermediate" + + if [[ "${ZITI_CTRL_MGMT_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_PORT="10000"; fi + if [[ "${ZITI_CTRL_MGMT_HOST_PORT-}" == "" ]]; then export ZITI_CTRL_MGMT_HOST_PORT="${ZITI_CONTROLLER_HOSTNAME}:${ZITI_CTRL_MGMT_PORT}"; fi + if [[ "${ZITI_CTRL_IDENTITY_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-client.cert"; fi + if [[ "${ZITI_CTRL_IDENTITY_SERVER_CERT-}" == "" ]]; then export ZITI_CTRL_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_CONTROLLER_HOSTNAME}-server.chain.pem"; fi + if [[ "${ZITI_CTRL_IDENTITY_KEY-}" == "" ]]; then export ZITI_CTRL_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/${ZITI_CONTROLLER_INTERMEDIATE_NAME}/keys/${ZITI_CONTROLLER_HOSTNAME}-server.key"; fi + if [[ "${ZITI_CTRL_IDENTITY_CA-}" == "" ]]; then export ZITI_CTRL_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/cas.pem"; fi + if [[ "${ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT}" == "" ]]; then export ZITI_EDGE_CTRL_ADVERTISED_HOST_PORT="${ZITI_EDGE_CONTROLLER_HOSTNAME}:${ZITI_EDGE_CONTROLLER_PORT}"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_CERT}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME}-client.cert"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.chain.pem"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_KEY}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_KEY="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/keys/${ZITI_EDGE_CONTROLLER_HOSTNAME}-server.key"; fi + if [[ "${ZITI_EDGE_CTRL_IDENTITY_CA}" == "" ]]; then export ZITI_EDGE_CTRL_IDENTITY_CA="${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert"; fi + + if [[ "${ZITI_SIGNING_CERT}" == "" ]]; then export ZITI_SIGNING_CERT="${ZITI_PKI_OS_SPECIFIC}/${ZITI_SIGNING_INTERMEDIATE_NAME}/certs/${ZITI_SIGNING_INTERMEDIATE_NAME}.cert"; fi + if [[ "${ZITI_SIGNING_KEY}" == "" ]]; then export ZITI_SIGNING_KEY="${ZITI_PKI_OS_SPECIFIC}/${ZITI_SIGNING_INTERMEDIATE_NAME}/keys/${ZITI_SIGNING_INTERMEDIATE_NAME}.key"; fi + + if [[ "${ZITI_EDGE_ROUTER_RAWNAME-}" == "" ]]; then ZITI_EDGE_ROUTER_RAWNAME="${ZITI_NETWORK}-edge-router"; fi + + mkdir -p "${ZITI_BIN_ROOT}" mkdir -p "${ZITI_HOME}/db" mkdir -p "${ZITI_PKI}" - _setup_ziti_env_path - - echo -e "$(GREEN "Your OpenZiti environment has been set up successfully.")" - echo "" -} - -# Stores environment variables prefixed with ZITI_ to a .env file -function persistEnvironmentValues { - local filepath retVal envval envvar zEnvVar - # Get the file path - filepath="${1-}" - if [[ "" == "${filepath}" ]]; then - _check_env_variable ZITI_ENV_FILE - retVal=$? - if [[ "${retVal}" != 0 ]]; then - echo -e "$(RED " --- persistEnvironment must take a parameter or have ZITI_ENV_FILE set ---")" - return 1 - else - filepath="${ZITI_ENV_FILE}" - fi - fi - - # Store all ZITI_ variables in the environment file, creating the directory if necessary - mkdir -p "$(dirname "${filepath}")" && echo "" > "${filepath}" - for zEnvVar in $(set | grep -e "^ZITI_" | sort); do - envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)" - envval="$(echo "${zEnvVar}" | cut -d '=' -f2-100)" - echo "export ${envvar}=\"${envval}\"" >> "${filepath}" - done + echo "" > "${ENV_FILE}" + for zEnvVar in $(set | grep -e "^ZITI_" | sort); do envvar="$(echo "${zEnvVar}" | cut -d '=' -f1)"; envval="$(echo "${zEnvVar}" | cut -d '=' -f2-100)"; echo "export ${envvar}=\"${envval}\"" >> "${ENV_FILE}"; done export PFXLOG_NO_JSON=true # shellcheck disable=SC2129 - echo "export PFXLOG_NO_JSON=true" >> "${filepath}" + echo "export PFXLOG_NO_JSON=true" >> "${ENV_FILE}" - echo "alias zec='ziti edge'" >> "${filepath}" - echo "alias zitiLogin='ziti edge login \"\${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:\${ZITI_CTRL_EDGE_ADVERTISED_PORT}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -y'" >> "${filepath}" - echo "alias psz='ps -ef | grep ziti'" >> "${filepath}" + echo "alias zec='ziti edge'" >> "${ENV_FILE}" + echo "alias zitiLogin='ziti edge login \"\${ZITI_EDGE_CTRL_ADVERTISED}\" -u \"\${ZITI_USER-}\" -p \"\${ZITI_PWD}\" -y'" >> "${ENV_FILE}" + echo "alias psz='ps -ef | grep ziti'" >> "${ENV_FILE}" #when sourcing the emitted file add the bin folder to the path - tee -a "${filepath}" > /dev/null <<'heredoc' + tee -a "${ENV_FILE}" > /dev/null <<'heredoc' echo " " if [[ ! "$(echo "$PATH"|grep -q "${ZITI_BIN_DIR}" && echo "yes")" == "yes" ]]; then echo "adding ${ZITI_BIN_DIR} to the path" @@ -389,671 +1161,32 @@ echo " " fi heredoc - echo -e "A file with all pertinent environment values was created here: $(BLUE "${filepath}")" - echo "" +echo -e "env file written to: $(BLUE "${ENV_FILE}")" } -# Clears environment variables prefixed with ZITI_, and removes ziti environment directories -function removeZitiEnvironment { - local specifiedVersion="" - # No need to `_check_env_variable ZITI_VERSION_OVERRIDE ZITI_BINARIES_VERSION` as this will still run if they're blank - echo -e "$(GREEN "Clearing existing Ziti variables and continuing with express install")" - - # Check if the user chose a specific version - if [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]] && [[ "${ZITI_VERSION_OVERRIDE-}" != "${ZITI_BINARIES_VERSION-}" ]]; then - # Don't allow overriding the version if ziti quickstart was already run, the DB may not be compatible - echo -e "$(RED " --- Overriding the ziti version is not supported if the version differs from one already installed. ---")" - echo -en "Would you like to continue by using the latest version? (y/N) " - read -r - echo " " - if [[ "${REPLY}" == [Yy]* ]]; then - unset ZITI_VERSION_OVERRIDE - else - return 1 - fi - elif [[ "${ZITI_VERSION_OVERRIDE-}" != "" ]]; then - echo -e "$(RED " --- You have set the ZITI_VERSION_OVERRIDE value to ${ZITI_VERSION_OVERRIDE}. ---")" - echo -en "Would you like to use this version again, choosing no will pull the latest version? (y/N) " - read -r - echo " " - if [[ "${REPLY}" == [Yy]* ]]; then - specifiedVersion="${ZITI_VERSION_OVERRIDE}" - fi - fi - - if [[ "${specifiedVersion}" != "" ]]; then - export ZITI_VERSION_OVERRIDE="${specifiedVersion}" - fi - - # Stop any devices currently running to avoid port collisions - stopRouter - stopController - - # Silently clear ziti variables (must be done after stopRouter and stopController) - unsetZitiEnv "-s" -} - -function startController { - local retVal log_file pid - _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_CTRL_NAME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - log_file="${ZITI_HOME-}/${ZITI_CTRL_NAME}.log" - "${ZITI_BIN_DIR-}/ziti" controller run "${ZITI_HOME}/${ZITI_CTRL_NAME}.yaml" &> "${log_file}" 2>&1 & - pid=$! - echo -e "ziti-controller started as process id: ${pid}. log located at: $(BLUE "${log_file}")" -} - -# Disable unused args shellcheck, the arg is optional -#shellcheck disable=SC2120 -function stopController { - local pid retVal - pid=${1-} - if [[ "${pid}" == "" ]]; then - _check_env_variable ZITI_CTRL_EDGE_ADVERTISED_PORT - retVal=$? - if [[ "${retVal}" != 0 ]]; then - echo "You will need to source the ziti env file first or set ZITI_CTRL_EDGE_ADVERTISED_PORT so that the controller process can be found" - return 1 - fi - - # Get the pid listening on the controller port - pid=$(lsof -ti:"${ZITI_CTRL_EDGE_ADVERTISED_PORT}") - fi - - if [[ -n ${pid:-} ]]; then - kill "${pid}" > /dev/null 2>&1 - if [[ $? == 0 ]]; then - echo "Controller stopped." - return 0 - else - echo "ERROR: Something went wrong while trying to stop the controller." - return 1 - fi - else - echo "No process found." - fi -} - -function startRouter { - local pid retVal log_file - _check_env_variable ZITI_HOME ZITI_EDGE_ROUTER_NAME ZITI_BIN_DIR - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - log_file="${ZITI_HOME}/${ZITI_EDGE_ROUTER_NAME}.log" - "${ZITI_BIN_DIR}/ziti" router run "${ZITI_HOME}/${ZITI_EDGE_ROUTER_NAME}.yaml" > "${log_file}" 2>&1 & - pid=$! - echo -e "Express Edge Router started as process id: ${pid}. log located at: $(BLUE "${log_file}")" -} - -# Disable unused args shellcheck, the arg is optional -#shellcheck disable=SC2120 -function stopRouter { - local pid retVal - pid=${1-} - if [[ "${pid}" == "" ]]; then - _check_env_variable ZITI_EDGE_ROUTER_PORT - retVal=$? - if [[ "${retVal}" != 0 ]]; then - echo "You will need to source the ziti env file first so that the router process can be found" - return 1 - fi - - # Get the pid listening on the controller port - pid=$(lsof -ti:"${ZITI_EDGE_ROUTER_PORT}") - fi - - if [[ -n ${pid:-} ]]; then - kill "${pid}" > /dev/null 2>&1 - if [[ $? == 0 ]]; then - echo "Router stopped." - return 0 - else - echo "ERROR: Something went wrong while trying to stop the router." >&2 - return 1 - fi - else - echo "No process found." - fi -} - -# Checks all ports intended to be used in the Ziti network -function checkZitiPorts { - local returnCnt=0 - _portCheck "ZITI_CTRL_LISTENER_PORT" "Controller" - returnCnt=$((returnCnt + $?)) - _portCheck "ZITI_EDGE_ROUTER_PORT" "Edge Router" - returnCnt=$((returnCnt + $?)) - _portCheck "ZITI_CTRL_EDGE_ADVERTISED_PORT" "Edge Controller" - returnCnt=$((returnCnt + $?)) - if [[ "${ZITI_EDGE_ROUTER_LISTENER_BIND_PORT-}" != "" ]]; then - # This port can be explicitly set but is not always, only check if set - _portCheck "ZITI_EDGE_ROUTER_LISTENER_BIND_PORT" "Router Listener Bind Port" - returnCnt=$((returnCnt + $?)) - fi - if [[ "returnCnt" -gt "0" ]]; then return 1; fi - echo -e "$(GREEN "Expected ports are all available")" - echo "" -} - -# Detect which OS the script is running on and store it in a variable -function _detect_OS { - if [ -n "${ZITI_OSTYPE}" ]; then return; fi - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - export ZITI_OSTYPE="linux" - elif [[ "$OSTYPE" == "darwin"* ]]; then - export ZITI_OSTYPE="darwin" - elif [[ "$OSTYPE" == "cygwin" ]]; then - export ZITI_OSTYPE="windows" - elif [[ "$OSTYPE" == "msys" ]]; then - export ZITI_OSTYPE="windows" - elif [[ "$OSTYPE" == "win32" ]]; then - export ZITI_OSTYPE="windows" - elif [[ "$OSTYPE" == "freebsd"* ]]; then - echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " - return 1 - else - echo -e " * ERROR: $(RED "\$OSTYPE is not set or is unknown: [$OSTYPE]. Cannot continue") " - return 1 - fi - return 0 -} - -# Detect which architecture the script is running on and store it in a variable -function _detect_architecture { - local detected_arch - if [ -n "${ZITI_ARCH}" ]; then return; fi - _detect_OS - ZITI_ARCH="amd64" - detected_arch="$(uname -m)" - # Apple M1 silicon - if [[ "${detected_arch}" == *"arm"* ]] && [[ "${ZITI_OSTYPE}" == "darwin" ]]; then - echo -e "$(YELLOW "WARN: It has been detected that you are using an Apple computer with ARM architecture. Deployment of Apple ARM architecture distributions is currently unsupported through git, the installer will pull darwin amd distribution instead.")" - # LLVM 64 bit backends have merged so some versions of *nix use aarch64 while others use arm64 for parity with Apple - elif [[ "${detected_arch}" == *"aarch64"* ]] || [[ "${detected_arch}" == *"arm64"* ]]; then - ZITI_ARCH="arm64" - elif [[ "${detected_arch}" == *"arm"* ]]; then - ZITI_ARCH="arm" - fi -} - -# Downloads and extracts ziti binaries onto the system. The latest version is used unless ZITI_VERSION_OVERRIDE is set. -function getZiti { - local retVal default_path ziti_binaries_file_abspath zitidl reply - _check_env_variable ZITI_BIN_DIR - retVal=$? - if [[ "${retVal}" != 0 ]]; then - # Prompt user for input or use default - _setup_ziti_home - getLatestZitiVersion # sets ZITI_BINARIES_FILE & ZITI_BINARIES_VERSION - default_path="${ZITI_HOME}/ziti-bin/ziti-${ZITI_BINARIES_VERSION}" - echo -en "The path for ziti binaries has not been set, use the default (${default_path})? (Y/n) " - read -r reply - if [[ -z "${reply}" || ${reply} =~ [yY]* ]]; then - echo "INFO: using the default path ${default_path}" - ZITI_BIN_DIR="${default_path}" - else - echo -en "Enter the preferred path and press (the path will be created if necessary) " - read -r ZITI_BIN_DIR - fi - fi - - echo -e "Getting OpenZiti binaries" - echo "" - - # Get the latest version unless a specific version is specified - if [[ "${ZITI_VERSION_OVERRIDE-}" == "" ]]; then - # If not overriding the version, determine the latest and populate ZITI_BINARIES_FILE ZITI_BINARIES_VERSION - if ! getLatestZitiVersion; then - return 1 - fi - else - _check_env_variable ZITI_BINARIES_FILE ZITI_BINARIES_VERSION - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - # Check if an error occurred while trying to pull desired version (happens with incorrect version or formatting issue) - if ! _verify_ziti_version_exists; then - echo -e " * $(RED "ERROR: This version of ziti (${ZITI_VERSION_OVERRIDE}) could not be found. Please check the version and try again. The version should follow the format \"vx.x.x\".") " - return 1 - fi - fi - - # Where to store the ziti binaries zip - ziti_binaries_file_abspath="${ZITI_BIN_DIR}/${ZITI_BINARIES_FILE}" - # Check if they're already downloaded or maybe the user explicitly pointed ZITI_BIN_DIR to their local bins - if ! test -f "${ZITI_BIN_DIR}/ziti"; then - # Make the directory - echo -e "No existing binary found, creating the ZITI_BIN_DIR directory ($(BLUE "${ZITI_BIN_DIR}"))" - mkdir -p "${ZITI_BIN_DIR}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR})")" - return 1 - fi - else - echo -e "ziti found in ZITI_BIN_DIR ($(BLUE "${ZITI_BIN_DIR}"))" - # Get the current version and compare with latest - local currentVersion - currentVersion="$("${ZITI_BIN_DIR}"/ziti --version) " - if [[ "${ZITI_BINARIES_VERSION}" != "${currentVersion}" ]]; then - # Prompt user for new download - echo -en "There is a newer version of OpenZiti, would you like to download it? (Y/n) " - read -r reply - if [[ -z "${reply}" || "${reply}" == [Yy]* ]]; then - # Update the ZITI_BIN_DIR path to point to the latest version - unset ZITI_BIN_DIR - _set_ziti_bin_dir - # Make the directory - mkdir -p "${ZITI_BIN_DIR}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - echo -e " * $(RED "ERROR: An error occurred generating the path (${ZITI_BIN_DIR}")" - return 1 - fi - - # Update the .env file with the new downloaded version - if ! test -f "${ZITI_ENV_FILE}"; then - echo -e " * $(YELLOW "WARN: The OpenZiti Environment file could not be found to update ziti binary related paths")" - else - sed "s/export ZITI_BIN_DIR=.*/export ZITI_BIN_DIR=${ZITI_BIN_DIR}/g" - sed "s/export ZITI_BINARIES_VERSION=.*/export ZITI_BINARIES_VERSION=${ZITI_BINARIES_VERSION}/g" - sed "s/export ZITI_BINARIES_FILE=.*/export ZITI_BINARIES_FILE=${ZITI_BINARIES_FILE}/g" - sed "s/export ZITI_BINARIES_FILE_ABSPATH=.*/d" - fi - - echo -e "$(YELLOW 'Getting latest binaries ')$(BLUE "${ZITI_BIN_DIR}")" - else - echo -e "$(YELLOW 'Using existing binaries at ')$(BLUE "${ZITI_BIN_DIR}")" - return 0 - fi - else - echo -e "$(YELLOW 'Latest binaries already exist, using existing binaries at ')$(BLUE "${ZITI_BIN_DIR}")" - return 0 - fi - fi - - # Get the download link - zitidl="https://github.com/openziti/ziti/releases/download/${ZITI_BINARIES_VERSION-}/${ZITI_BINARIES_FILE}" - echo -e 'Downloading '"$(BLUE "${zitidl}")"' to '"$(BLUE "${ziti_binaries_file_abspath}")" - curl -Ls "${zitidl}" -o "${ziti_binaries_file_abspath}" - - # Unzip the files - tar -xf "${ziti_binaries_file_abspath}" --directory "${ZITI_BIN_DIR}" - - # Files unzip to a /ziti subdirectory, move them into ZITI_BIN_DIR - # Have to rename the directory first since 'ziti' matches the filename for the 'ziti' binary - mv "${ZITI_BIN_DIR}/ziti" "${ZITI_BIN_DIR}/ziti-extract" - mv "${ZITI_BIN_DIR}/ziti-extract"/* "${ZITI_BIN_DIR}" - - # Cleanup - rm "${ziti_binaries_file_abspath}" # Remove zip - rm -rf "${ZITI_BIN_DIR}/ziti-extract" # Remove extract folder - - # Mark the files executable - chmod +x "${ZITI_BIN_DIR}/"* - - echo -e "$(GREEN "OpenZiti binaries ${ZITI_BINARIES_VERSION} successfully extracted to $(BLUE "${ZITI_BIN_DIR}")")" - echo "" -} - -# Create a custom PKI -function createPki { - local retVal pki_allow_list_dns pki_allow_list_ip ZITI_SPURIOUS_INTERMEDIATE - _check_env_variable ZITI_PKI_CTRL_ROOTCA_NAME ZITI_PKI_CTRL_EDGE_ROOTCA_NAME ZITI_PKI_SIGNER_ROOTCA_NAME \ - ZITI_PKI_SIGNER_INTERMEDIATE_NAME ZITI_PKI_CTRL_INTERMEDIATE_NAME \ - ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - echo "Generating PKI" - - _pki_create_ca "${ZITI_PKI_CTRL_ROOTCA_NAME}" - _pki_create_ca "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}" - _pki_create_ca "${ZITI_PKI_SIGNER_ROOTCA_NAME}" - - ZITI_SPURIOUS_INTERMEDIATE="${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}_spurious_intermediate" - _pki_create_intermediate "${ZITI_PKI_CTRL_ROOTCA_NAME}" "${ZITI_PKI_CTRL_INTERMEDIATE_NAME}" 1 - _pki_create_intermediate "${ZITI_PKI_CTRL_EDGE_ROOTCA_NAME}" "${ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME}" 1 - _pki_create_intermediate "${ZITI_PKI_SIGNER_ROOTCA_NAME}" "${ZITI_SPURIOUS_INTERMEDIATE}" 2 - _pki_create_intermediate "${ZITI_SPURIOUS_INTERMEDIATE}" "${ZITI_PKI_SIGNER_INTERMEDIATE_NAME}" 1 - - pki_allow_list_dns="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS},localhost,${ZITI_NETWORK}" - if [[ "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" != "" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}"; fi - if [[ "${EXTERNAL_DNS}" != "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" ]]; then pki_allow_list_dns="${pki_allow_list_dns},${EXTERNAL_DNS}"; fi - pki_allow_list_ip="127.0.0.1" - if [[ "${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${ZITI_EDGE_CONTROLLER_IP_OVERRIDE}"; fi - if [[ "${EXTERNAL_IP}" != "" ]]; then pki_allow_list_ip="${pki_allow_list_ip},${EXTERNAL_IP}"; fi - - pki_allow_list_dns="${pki_allow_list_dns},${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS},localhost,${ZITI_NETWORK}" - _pki_client_server "${pki_allow_list_dns}" "${ZITI_PKI_CTRL_INTERMEDIATE_NAME}" "${pki_allow_list_ip}" "${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}" - echo -e "$(GREEN "PKI generated successfully")" - echo -e "" -} - -# Disable shellcheck un-passed arguments (arguments are optional) -# shellcheck disable=SC2120 -# Creates a controller config file -function createControllerConfig { - local controller_name retVal file_path output_file - # Allow controller name to be passed in as arg - controller_name="${1-}" - # If no controller name provided and env var is not set, prompt user for a controller name - if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_CTRL_NAME}" ]]; then - echo -e "$(YELLOW "createControllerConfig requires a controller name to be supplied") " - echo -en "Enter controller name: " - read -r controller_name - - # Quit if no name is provided - if [[ "${controller_name}" == "" ]]; then - echo -e "$(RED " --- Invalid controller name provided ---")" - return 1 - fi - # If no controller name provided and env var is set, use env var - elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_CTRL_NAME}" ]]; then - controller_name="${ZITI_CTRL_NAME}" - fi - - # Make sure necessary env variables are set - # The following are used by ziti bin to generate the config so they need to be checked: - # ZITI_PKI_SIGNER_KEY ZITI_PKI_EDGE_CERT ZITI_PKI_EDGE_SERVER_CERT ZITI_PKI_EDGE_KEY ZITI_PKI_EDGE_CA - _check_env_variable ZITI_PKI_CTRL_SERVER_CERT ZITI_PKI_CTRL_CA ZITI_PKI_SIGNER_CERT ZITI_PKI_SIGNER_KEY ZITI_BIN_DIR \ - ZITI_PKI_EDGE_CERT ZITI_PKI_EDGE_SERVER_CERT ZITI_PKI_EDGE_KEY ZITI_PKI_EDGE_CA - retVal=$? - if [ $retVal -ne 0 ]; then - return 1 - fi - - # Use the current directory if none is set - file_path="${ZITI_HOME}" - if [[ "${ZITI_HOME-}" == "" ]]; then file_path="."; fi - - cat "${ZITI_PKI_CTRL_SERVER_CERT}" >"${ZITI_PKI_CTRL_CA}" - cat "${ZITI_PKI_SIGNER_CERT}" >>"${ZITI_PKI_CTRL_CA}" - echo -e "wrote CA file to: $(BLUE "${ZITI_PKI_CTRL_CA}")" - - output_file="${file_path}/${controller_name}.yaml" - - _get_file_overwrite_permission "${output_file}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - "${ZITI_BIN_DIR}/ziti" create config controller >"${output_file}" - - echo -e "Controller configuration file written to: $(BLUE "${output_file}")" -} - -# Helper function to create a private edge router -function createPrivateRouterConfig { - _create_router_config "${1-}" "private" -} - -# Helper function to create a public edge router -function createEdgeRouterConfig { - _create_router_config "${1-}" "public" -} - -function createEdgeRouterWssConfig { - _create_router_config "${1-}" "wss" -} - -# Helper function to create a fabric router -function createFabricRouterConfig { - _create_router_config "${1-}" "fabric" -} - -# The main create router config function, all others point to this -function _create_router_config { - local router_name router_type output_file retVal default_router_name file_path - # Allow router name and type to be passed in as arg - router_name="${1-}" - router_type="${2-}" - if [[ "${router_name}" == "" ]]; then - - # If router name is not passed as arg, prompt user for input - echo -e "$(YELLOW "createEdgeRouterConfig requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_NAME}" - echo -en "Enter router name (${default_router_name}): " - read -r router_name - - # Accept the default if no name provided - if [[ "${router_name}" == "" ]]; then - # Check for overwrite of default file - router_name="${default_router_name}" - _get_file_overwrite_permission "${ZITI_HOME-}/${router_name}.yaml" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - fi - fi - # Get router type or set as default - if [[ "${router_type}" == "" ]]; then - router_type="private" - elif [[ "private" != "${router_type}" ]] && [[ "public" != "${router_type}" ]]; then - echo -e "Unknown router type parameter provided, use 'public', 'private', 'fabric', or 'wss'" - fi - - # Make sure necessary env variables are set - # The following are used by ziti bin to generate the config so they need to be checked: - # ZITI_CTRL_EDGE_ADVERTISED_ADDRESS ZITI_CTRL_LISTENER_PORT - _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_CTRL_EDGE_ADVERTISED_ADDRESS ZITI_CTRL_LISTENER_PORT - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - # Use the current directory if none is set - file_path="${ZITI_HOME}" - if [[ "${ZITI_HOME-}" == "" ]]; then file_path="."; fi - - output_file="${file_path}/${router_name}.yaml" - - _get_file_overwrite_permission "${output_file}" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - return 1 - fi - - if [[ "public" == "${router_type}" ]]; then - "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" > "${output_file}" - elif [[ "private" == "${router_type}" ]]; then - "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --private > "${output_file}" - elif [[ "fabric" == "${router_type}" ]]; then - "${ZITI_BIN_DIR}/ziti" create config router fabric --routerName "${router_name}" > "${output_file}" - elif [[ "wss" == "${router_type}" ]]; then - "${ZITI_BIN_DIR}/ziti" create config router edge --routerName "${router_name}" --wss > "${output_file}" - fi - echo -e "${router_type} router configuration file written to: $(BLUE "${output_file}")" -} - -# Used to create a router, router config, then enroll the router. -function addRouter { - local router_name router_type retVal router_attr - # Make sure necessary env variables are set - _check_env_variable ZITI_HOME ZITI_BIN_DIR ZITI_USER ZITI_PWD - retVal=$? - if [ $retVal -ne 0 ]; then - return 1 - fi - # Allow router name and type to be passed in as arg - router_name="${1-}" - router_type="${2-}" - router_attr="${3-}" - # If no router name provided and env var is not set, prompt user for a router name - if [[ "${router_name}" == "" ]] && [[ -z "${ZITI_EDGE_ROUTER_NAME}" ]]; then - echo -e "$(YELLOW "addRouter requires a router name to be supplied") " - echo -en "Enter router name: " - read -r router_name - - # Quit if no name is provided - if [[ "${router_name}" == "" ]]; then - echo -e "$(RED " --- Invalid router name provided ---")" - return 1 - fi - # If no router name provided and env var is set, use env var - elif [[ "${router_name}" == "" ]] && [[ -n "${ZITI_EDGE_ROUTER_NAME}" ]]; then - router_name="${ZITI_EDGE_ROUTER_NAME}" - fi - - # Create router - zitiLogin - "${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${router_name}" - "${ZITI_BIN_DIR-}/ziti" edge create edge-router "${router_name}" -o "${ZITI_HOME}/${router_name}.jwt" -t -a "${router_attr}" - - # Create router config - _create_router_config "${router_name}" "${router_type}" - - # Enroll the router - "${ZITI_BIN_DIR-}/ziti" router enroll "${ZITI_HOME}/${router_name}.yaml" --jwt "${ZITI_HOME}/${router_name}.jwt" &> "${ZITI_HOME}/${router_name}.enrollment.log" - retVal=$? - if [[ "${retVal}" != 0 ]]; then - echo -e "$(RED " --- There was an error during router enrollment, check the logs at ${ZITI_HOME}/${router_name}.enrollment.log ---")" - return 1 - else - echo -e "$(GREEN "Enrollment successful")" - fi -} - -function initializeController { - local retVal log_file - _setup_ziti_home - # Make sure necessary env variables are set - _check_env_variable ZITI_HOME ZITI_CTRL_NAME ZITI_USER ZITI_PWD ZITI_PKI_CTRL_CA ZITI_BIN_DIR - retVal=$? - if [ $retVal -ne 0 ]; then - return 1 - fi - - log_file="${ZITI_HOME-}/${ZITI_CTRL_NAME}-init.log" - "${ZITI_BIN_DIR-}/ziti" controller edge init "${ZITI_HOME}/${ZITI_CTRL_NAME}.yaml" -u "${ZITI_USER-}" -p "${ZITI_PWD}" &> "${log_file}" - echo -e "${ZITI_CTRL_NAME} initialized. See $(BLUE "${log_file}") for details" -} - -function zitiLogin { - local advertised_host_port="${ZITI_CTRL_EDGE_ADVERTISED_ADDRESS}:${ZITI_CTRL_EDGE_ADVERTISED_PORT}" - "${ZITI_BIN_DIR-}/ziti" edge login "${advertised_host_port}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -y 2>&1 -} - -function expressInstall { - local retVal - # Check if expressInstall has been run before - if [[ "" != "${ZITIx_EXPRESS_COMPLETE-}" ]]; then - echo -e "$(RED " --- It looks like you've run an express install in this shell already. ---")" - echo -en "Would you like to clear existing Ziti variables and continue? (y/N) " - read -r - echo " " - if [[ "${REPLY}" == [Yy]* ]]; then - removeZitiEnvironment - else - echo -e "$(RED " --- Exiting express install ---")" - return 1 - fi - fi - export ZITIx_EXPRESS_COMPLETE="true" - _issue_preamble - - # This is redundant but better to check here to prevent going any further - _check_prereq curl jq tar hostname - retVal=$? - if [ $retVal -ne 0 ]; then - return 1 - fi - _issue_greeting - - echo -e "$(PURPLE "******** Setting Up Your OpenZiti Environment ********")" - # If a parameter was provided, set the network name to this value - if [[ "${1-}" != "" ]]; then - ZITI_NETWORK="${1-}" - fi - setupEnvironment - persistEnvironmentValues "" - - echo -e "$(PURPLE "******** Getting OpenZiti Binaries ********")" - if ! getZiti "no"; then - echo -e "$(RED "getZiti failed")" - return 1 - fi - - # Check Ports - echo -e "$(PURPLE "******** Ensure the Necessary Ports Are Open ********")" - if ! checkZitiPorts; then - echo "Please clear the unavailable ports or change their values and try again." - return 1 - fi - - # Create PKI - echo -e "$(PURPLE "******** Generating Public Key Infrastructure ********")" - createPki - - echo -e "$(PURPLE "******** Setting Up Controller ********")" - createControllerConfig - initializeController - startController - echo "waiting for the controller to come online to allow the edge router to enroll" - _wait_for_controller - echo "" - - echo -e "$(PURPLE "******** Setting Up Edge Router ********")" - zitiLogin - echo "" - echo -e "---------- Creating an edge router policy allowing all identities to connect to routers with a $(GREEN "#public") attribute" - "${ZITI_BIN_DIR-}/ziti" edge delete edge-router-policy allEdgeRouters > /dev/null - "${ZITI_BIN_DIR-}/ziti" edge create edge-router-policy allEdgeRouters --edge-router-roles '#public' --identity-roles '#all' > /dev/null - - echo -e "---------- Creating a service edge router policy allowing all services to use $(GREEN "#public") edge routers" - "${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcAllRouters > /dev/null - "${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcAllRouters --edge-router-roles '#all' --service-roles '#all' > /dev/null - echo "" - - echo "USING ZITI_EDGE_ROUTER_NAME: $ZITI_EDGE_ROUTER_NAME" - - addRouter "${ZITI_EDGE_ROUTER_NAME}" "public" - echo "" - - stopController - echo "Edge Router enrolled." - - echo "" - echo -e "$(GREEN "Congratulations. Express setup complete!")" - echo -e "Your ZITI_HOME is located here: $(BLUE "${ZITI_HOME}")" - echo -e "Your admin password is: $(BLUE "${ZITI_PWD}")" - echo "" - echo -e "Start your Ziti Controller by running the function: $(BLUE "startController")" - echo -e "Start your Ziti Edge Router by running : $(BLUE 'startRouter')" - echo "" -} - -# Gets the latest Ziti binary (the process is different for latest vs older so unfortunately two functions are needed) -function getLatestZitiVersion { - local ziti_latest - if ! _detect_OS; then - return 1 - fi - - _detect_architecture - - ziti_latest=$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/latest) - ZITI_BINARIES_FILE=$(echo "${ziti_latest}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') - ZITI_BINARIES_VERSION=$(echo "${ziti_latest}" | tr '\r\n' ' ' | jq -r '.tag_name') +function waitForController { + #devnull="/dev/null" + #if [[ "${ZITI_OSTYPE}" == "windows" ]]; then + # devnull="nul" + #fi + # shellcheck disable=SC2091 + #until $(curl -o /dev/null -sk /dev/null --fail "https://${ZITI_EDGE_CTRL_ADVERTISED}"); do + # echo "waiting for https://${ZITI_EDGE_CTRL_ADVERTISED}" + # sleep 2 + #done + while [[ "$(curl -w "%{http_code}" -m 1 -s -k -o /dev/null https://"${ZITI_EDGE_CTRL_ADVERTISED}"/version)" != "200" ]]; do + echo "waiting for https://${ZITI_EDGE_CTRL_ADVERTISED}" + sleep 3 + done } function createControllerSystemdFile { - local controller_name retVal output_file - # Allow controller name to be passed in as an arg + # Allow controller name to be passed in as arg controller_name="${1-}" # If no controller name provided and env var is not set, prompt user for a controller name - if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_CTRL_NAME}" ]]; then + if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then echo -e "$(YELLOW "createControllerSystemdFile requires a controller name to be supplied") " - echo -en "Enter controller name: " + echo -en "Enter controller name:" read -r controller_name # Quit if no name is provided @@ -1062,12 +1195,12 @@ function createControllerSystemdFile { return 1 fi # If no controller name provided and env var is set, use env var - elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_CTRL_NAME}" ]]; then - controller_name="${ZITI_CTRL_NAME}" + elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then + controller_name="${ZITI_EDGE_CONTROLLER_RAWNAME}" fi # Make sure necessary env variables are set - _check_env_variable ZITI_HOME ZITI_BIN_DIR + checkEnvVariable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1102,15 +1235,14 @@ HeredocForSystemd } function createRouterSystemdFile { - local router_name default_router_name retVal output_file - # Allow router name to be passed in as an arg + # Allow router name to be passed in as arg router_name="${1-}" if [[ "${router_name}" == "" ]]; then # If router name is not passed as arg, prompt user for input echo -e "$(YELLOW "createRouterSystemdFile requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_NAME}" - echo -en "Enter router name (${default_router_name}): " + default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + echo -en "Enter router name (${default_router_name}):" read -r router_name # Accept the default if no name provided @@ -1125,7 +1257,7 @@ function createRouterSystemdFile { fi fi - _check_env_variable ZITI_HOME ZITI_BIN_DIR + checkEnvVariable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1160,11 +1292,10 @@ HeredocForSystemd } function createControllerLaunchdFile { - local controller_name retVal output_file # Allow controller name to be passed in as arg controller_name="${1-}" # If no controller name provided and env var is not set, prompt user for a controller name - if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_CTRL_NAME}" ]]; then + if [[ "${controller_name}" == "" ]] && [[ -z "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then echo -e "$(YELLOW "createControllerLaunchdFile requires a controller name to be supplied") " echo -en "Enter controller name: " read -r controller_name @@ -1175,12 +1306,12 @@ function createControllerLaunchdFile { return 1 fi # If no controller name provided and env var is set, use env var - elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_CTRL_NAME}" ]]; then - controller_name="${ZITI_CTRL_NAME}" + elif [[ "${controller_name}" == "" ]] && [[ -n "${ZITI_EDGE_CONTROLLER_RAWNAME}" ]]; then + controller_name="${ZITI_EDGE_CONTROLLER_RAWNAME}" fi # Make sure necessary env variables are set - _check_env_variable ZITI_HOME ZITI_BIN_DIR + checkEnvVariable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1196,7 +1327,7 @@ function createControllerLaunchdFile { cat > "${output_file}" < - + Label @@ -1230,15 +1361,14 @@ HeredocForLaunchd } function createRouterLaunchdFile { - local router_name default_router_name retVal output_file # Allow router name to be passed in as arg router_name="${1-}" if [[ "${router_name}" == "" ]]; then # If router name is not passed as arg, prompt user for input echo -e "$(YELLOW "createRouterLaunchdFile requires a router name to be supplied") " - default_router_name="${ZITI_EDGE_ROUTER_NAME}" - echo -en "Enter router name (${default_router_name}): " + default_router_name="${ZITI_EDGE_ROUTER_RAWNAME}" + echo -en "Enter router name (${default_router_name}):" read -r router_name # Accept the default if no name provided @@ -1254,7 +1384,7 @@ function createRouterLaunchdFile { fi # Make sure necessary env variables are set - _check_env_variable ZITI_HOME ZITI_BIN_DIR + checkEnvVariable ZITI_HOME ZITI_BIN_DIR retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1270,7 +1400,7 @@ function createRouterLaunchdFile { cat > "${output_file}" < - + Label @@ -1312,8 +1442,8 @@ function showLaunchdMessage { } function createZacSystemdFile { - local retVal output_file node_bin - _check_env_variable ZITI_HOME + + checkEnvVariable ZITI_HOME retVal=$? if [[ "${retVal}" != 0 ]]; then return 1 @@ -1329,7 +1459,7 @@ function createZacSystemdFile { if which node >/dev/null; then # store the absolute path to the node executable because it's required by systemd on Amazon Linux, at least - node_bin=$(readlink -f "$(which node)") + NODE_BIN=$(readlink -f "$(which node)") else echo "ERROR: missing executable 'node'" >&2 return 1 @@ -1343,7 +1473,7 @@ After=network.target [Service] User=root WorkingDirectory=${ZITI_HOME}/ziti-console -ExecStart=${node_bin} "${ZITI_HOME}/ziti-console/server.js" +ExecStart=${NODE_BIN} "${ZITI_HOME}/ziti-console/server.js" Restart=always RestartSec=2 LimitNOFILE=65536 @@ -1355,158 +1485,69 @@ HeredocForSystemd echo -e "ziti-console systemd file written to: $(BLUE "${output_file}")" } -# Ensure that the version desired as specified by ZITI_VERSION_OVERRIDE exists, this returns an error in cases where -# the version doesn't exist or possibly just the version format provided in ZITI_VERSION_OVERRIDE is incorrect. -function _verify_ziti_version_exists { - local ziticurl - - if ! setOs; then - return 1 - fi - - _detect_architecture - - ziticurl="$(curl -s https://${GITHUB_TOKEN:+${GITHUB_TOKEN}@}api.github.com/repos/openziti/ziti/releases/tags/"${ZITI_VERSION_OVERRIDE}")" - ZITI_BINARIES_FILE=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.assets[] | select(.name | startswith("'"ziti-${ZITI_OSTYPE}-${ZITI_ARCH}-"'")) | .name') - ZITI_BINARIES_VERSION=$(echo "${ziticurl}" | tr '\r\n' ' ' | jq -r '.tag_name') - - # Check if there was an error while trying to get the requested version - if [[ "${ZITI_BINARIES_VERSION-}" == "null" ]]; then - echo "ERROR: response missing '.tag_name': ${ziticurl}" >&2 - return 1 - fi - - echo "The ziti version requested (${ZITI_BINARIES_VERSION}) was verified and has been stored in ZITI_BINARIES_VERSION" -} - -# Disable shellcheck for parameter expansion error, this function supports multiple shells -# shellcheck disable=SC2296 -# Check to ensure the expected ports are available -function _portCheck { - local portCheckResult envVar envVarValue - - if [[ "${1-}" == "" ]] || [[ "${2-}" == "" ]]; then - echo -e "_portCheck Usage: _portCheck " - return 0 - fi - - envVar="${1-}" - if [[ -n "$ZSH_VERSION" ]]; then - envVarValue="${(P)envVar}" - elif [[ -n "$BASH_VERSION" ]]; then - envVarValue="${!envVar}" +function setOs { + if [ -n "${ZITI_OSTYPE}" ]; then return; fi + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + export ZITI_OSTYPE="linux" + elif [[ "$OSTYPE" == "darwin"* ]]; then + export ZITI_OSTYPE="darwin" + elif [[ "$OSTYPE" == "cygwin" ]]; then + export ZITI_OSTYPE="windows" + #echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " + #return 1 + elif [[ "$OSTYPE" == "msys" ]]; then + export ZITI_OSTYPE="windows" + #echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " + #return 1 + elif [[ "$OSTYPE" == "win32" ]]; then + export ZITI_OSTYPE="windows" + elif [[ "$OSTYPE" == "freebsd"* ]]; then + echo -e " * ERROR: $(RED "\$OSTYPE [$OSTYPE] is not supported at this time") " + return 1 else - echo -e "$(YELLOW "Unknown/Unsupported shell, cannot verify availability of ${2-}'s intended port, proceed with caution")" - return 0 - fi - - echo -en "Checking ${2-}'s port (${envVarValue})" - portCheckResult=$(lsof -w -i :"${envVarValue}" 2>&1) - if [[ "${portCheckResult}" != "" ]]; then - echo -e "$(RED " ")" - echo -e "$(RED "The intended ${2-} port (${envVarValue}) is currently being used, the process using this port should be closed or the port value should be changed.")" - echo -e "$(RED "To use a different port, set the port value in ${envVar}")" - echo -e "$(RED " ")" - echo -e "$(RED "Example:")" - echo -e "$(RED "export ${envVar}=1234")" - echo -e "$(RED " ")" - return 1 - else - echo -e "$(GREEN "Open")" + echo -e " * ERROR: $(RED "\$OSTYPE is not set or is unknown: [$OSTYPE]. Cannot continue") " + return 1 fi return 0 } -# A function for upgrading an existing (<=0.28.0) network to a later (>0.28.0) network -# The binary, which relies on environment variables were extensively altered and will not work on an existing network -# without migrating it first -function performMigration { - if [[ "${1-}" == "" ]]; then - # Check if the env file is in the expected location - _setup_ziti_env_path - if ! test -f "${ZITI_ENV_FILE}"; then - echo -e "performMigration Usage: performMigration " - return 0 +function checkEnvVariable() { + + for arg + do + # Parameter expansion is different between shells + if [[ -n "$ZSH_VERSION" ]]; then + # shellcheck disable=SC2296 + if [[ -z "${(P)arg}" ]]; then + echo -e " * ERROR: $(RED "${arg} is not set") " + return 1 + fi + elif [[ -n "$BASH_VERSION" ]]; then + if [[ -z "${!arg}" ]]; then + echo -e " * ERROR: $(RED "${arg} is not set") " + return 1 + fi + else + echo -e " * $(RED "Unsupported shell, supply a PR or log an issue on https://github.com/openziti/ziti") " + return 1 fi - else - ZITI_ENV_FILE="${1-}" + done + return 0 +} + +function getFileOverwritePermission() { + file_path="${1-}" + + if [[ -f "${file_path}" ]]; then + echo -en "This will overwrite the existing file, continue (y/N)? " + read -r + if [[ "${REPLY}" == [^Yy]* ]]; then + echo -e "$(RED " --- Cancelling overwrite ---")" + return 1 + fi + + return 0 fi - - # Replace old Env Vars in the env file with new ones - # NOTE: the '' after -i is required for Mac, otherwise an error is thrown - sed -i '' 's/ZITI_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CONTROLLER_INTERMEDIATE_NAME/ZITI_PKI_CTRL_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CONTROLLER_RAWNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CONTROLLER_ROOTCA_NAME/ZITI_PKI_CTRL_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_ADVERTISED_ADDRESS/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_EDGE_PORT/ZITI_CTRL_EDGE_ADVERTISED_PORT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_IDENTITY_CA/ZITI_PKI_CTRL_CA/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_IDENTITY_CERT/ZITI_PKI_CTRL_CERT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_IDENTITY_KEY/ZITI_PKI_CTRL_KEY/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_IDENTITY_SERVER_CERT/ZITI_PKI_CTRL_SERVER_CERT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_CTRL_PORT/ZITI_CTRL_LISTENER_PORT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_HOSTNAME/ZITI_CTRL_EDGE_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME/ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_PORT/ZITI_CTRL_EDGE_ADVERTISED_PORT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_RAWNAME/ZITI_CTRL_NAME/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CONTROLLER_ROOTCA_NAME/ZITI_PKI_CTRL_EDGE_ROOTCA_NAME/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CA/ZITI_PKI_EDGE_CA/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_CERT/ZITI_PKI_EDGE_CERT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_KEY/ZITI_PKI_EDGE_KEY/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT/ZITI_PKI_EDGE_SERVER_CERT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_ROUTER_RAWNAME/ZITI_EDGE_ROUTER_NAME/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_PKI_OS_SPECIFIC/ZITI_PKI/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_SIGNING_CERT/ZITI_PKI_SIGNER_CERT/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_SIGNING_KEY/ZITI_PKI_SIGNER_KEY/g' "${ZITI_ENV_FILE}" - sed -i '' 's/ZITI_EDGE_ROUTER_HOSTNAME/ZITI_ROUTER_ADVERTISED_ADDRESS/g' "${ZITI_ENV_FILE}" - - # Update environment variables if currently set - if [[ "${ZITI_EDGE_CONTROLLER_HOSTNAME-}" != "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_ADDRESS="${ZITI_EDGE_CONTROLLER_HOSTNAME}"; fi - if [[ "${ZITI_CONTROLLER_INTERMEDIATE_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_INTERMEDIATE_NAME="${ZITI_CONTROLLER_INTERMEDIATE_NAME}"; fi - if [[ "${ZITI_CONTROLLER_ROOTCA_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_ROOTCA_NAME="${ZITI_CONTROLLER_ROOTCA_NAME}"; fi - if [[ "${ZITI_CTRL_EDGE_PORT-}" != "" ]]; then export ZITI_CTRL_EDGE_ADVERTISED_PORT="${ZITI_CTRL_EDGE_PORT}"; fi - if [[ "${ZITI_CTRL_IDENTITY_CA-}" != "" ]]; then export ZITI_PKI_CTRL_CA="${ZITI_CTRL_IDENTITY_CA}"; fi - if [[ "${ZITI_CTRL_IDENTITY_CERT-}" != "" ]]; then export ZITI_PKI_CTRL_CERT="${ZITI_CTRL_IDENTITY_CERT}"; fi - if [[ "${ZITI_CTRL_IDENTITY_KEY-}" != "" ]]; then export ZITI_PKI_CTRL_KEY="${ZITI_CTRL_IDENTITY_KEY}"; fi - if [[ "${ZITI_CTRL_IDENTITY_SERVER_CERT-}" != "" ]]; then export ZITI_PKI_CTRL_SERVER_CERT="${ZITI_CTRL_IDENTITY_SERVER_CERT}"; fi - if [[ "${ZITI_CTRL_PORT-}" != "" ]]; then export ZITI_CTRL_LISTENER_PORT="${ZITI_CTRL_PORT}"; fi - if [[ "${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_EDGE_INTERMEDIATE_NAME="${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}"; fi - if [[ "${ZITI_EDGE_CONTROLLER_RAWNAME-}" != "" ]]; then export ZITI_CTRL_NAME="${ZITI_EDGE_CONTROLLER_RAWNAME}"; fi - if [[ "${ZITI_EDGE_CONTROLLER_ROOTCA_NAME-}" != "" ]]; then export ZITI_PKI_CTRL_EDGE_ROOTCA_NAME="${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_CA-}" != "" ]]; then export ZITI_PKI_EDGE_CA="${ZITI_EDGE_CTRL_IDENTITY_CA}"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_CERT-}" != "" ]]; then export ZITI_PKI_EDGE_CERT="${ZITI_EDGE_CTRL_IDENTITY_CERT}"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_KEY-}" != "" ]]; then export ZITI_PKI_EDGE_KEY="${ZITI_EDGE_CTRL_IDENTITY_KEY}"; fi - if [[ "${ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT-}" != "" ]]; then export ZITI_EDGE_ROUTER_NAME="${ZITI_EDGE_CTRL_IDENTITY_SERVER_CERT}"; fi - if [[ "${ZITI_PKI_OS_SPECIFIC-}" != "" ]]; then export ZITI_PKI="${ZITI_PKI_OS_SPECIFIC}"; fi - if [[ "${ZITI_SIGNING_CERT-}" != "" ]]; then export ZITI_PKI_SIGNER_CERT="${ZITI_SIGNING_CERT}"; fi - if [[ "${ZITI_SIGNING_KEY-}" != "" ]]; then export ZITI_PKI_SIGNER_KEY="${ZITI_SIGNING_KEY}"; fi - if [[ "${ZITI_EDGE_ROUTER_HOSTNAME-}" != "" ]]; then export ZITI_ROUTER_ADVERTISED_ADDRESS="${ZITI_EDGE_ROUTER_HOSTNAME}"; fi - - # Update the necessary ziti binary references (others are not needed or are overwritten later) - if [[ "${ZITI_BIN_DIR-}" != "" ]]; then - sed '/^export ZITI_BIN_DIR=/d' "${ZITI_ENV_FILE}" - echo "export ZITI_BIN_DIR=${ZITI_BIN_DIR}" >> "${ZITI_ENV_FILE}" - fi - if [[ "${ZITI_BINARIES_VERSION-}" != "" ]]; then - sed '/^export ZITI_BINARIES_VERSION=/d' "${ZITI_ENV_FILE}" - echo "export ZITI_BINARIES_VERSION=${ZITI_BINARIES_VERSION}" >> "${ZITI_ENV_FILE}" - fi - - echo -e "$(GREEN "SUCCESS: Your Environment file has been updated, please use source the file for the latest values. Be sure to source the .env file as needed.")" } -# ******* Deprecated functions, refer to new functions ********** -function deprecationMessage { - echo -e "$(YELLOW "WARNING: The ${1} function has been deprecated, please use ${2} going forward")" -} - -function generateEnvFile { - deprecationMessage generateEnvFile persistEnvironmentValues - persistEnvironmentValues -} -function waitForController { - deprecationMessage waitForController _wait_for_controller - _wait_for_controller -} - -set +uo pipefail \ No newline at end of file +set +uo pipefail From 994b0fdc277f3f61a7c092aaf5bf80b0d271d7a3 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Sun, 18 Jun 2023 09:40:29 -0400 Subject: [PATCH 23/26] replace ziti-controller/ziti-router with ziti controller/ziti router --- quickstart/docker/image/ziti-cli-functions.sh | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 68aa27648..1e072bae0 100644 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -83,15 +83,15 @@ function cleanZitiController { } function initializeController { log_file="${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}-init.log" - "${ZITI_BIN_DIR-}/ziti-controller" edge init "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" -u "${ZITI_USER-}" -p "${ZITI_PWD}" &> "${log_file}" - echo -e "ziti-controller initialized. see $(BLUE "${log_file}") for details" + "${ZITI_BIN_DIR-}/ziti" controller edge init "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" -u "${ZITI_USER-}" -p "${ZITI_PWD}" &> "${log_file}" + echo -e "ziti controller initialized. see $(BLUE "${log_file}") for details" } function startController { log_file="${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}.log" # shellcheck disable=SC2034 - "${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" &> "${log_file}" & + "${ZITI_BIN_DIR-}/ziti" controller run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" &> "${log_file}" & ZITI_EXPRESS_CONTROLLER_PID=$! - echo -e "ziti-controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${log_file}")" + echo -e "ziti controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${log_file}")" } function stopController { @@ -110,7 +110,7 @@ function stopController { function startRouter { log_file="${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" - "${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${log_file}" 2>&1 & + "${ZITI_BIN_DIR}/ziti" router run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${log_file}" 2>&1 & ZITI_EXPRESS_EDGE_ROUTER_PID=$! echo -e "Express Edge Router started as process id: $ZITI_EXPRESS_EDGE_ROUTER_PID. log located at: $(BLUE "${log_file}")" @@ -582,7 +582,7 @@ function ziti_expressConfiguration { sleep 1 echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." - "${ZITI_BIN_DIR-}/ziti-router" enroll "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" --jwt "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" &> "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.enrollment.log" + "${ZITI_BIN_DIR-}/ziti" router enroll "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" --jwt "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" &> "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.enrollment.log" echo "" stopController @@ -1216,13 +1216,13 @@ function createControllerSystemdFile { cat > "${output_file}" < "${output_file}" < "${output_file}" < Label - ziti-controller-${controller_name} + ziti controller-${controller_name} ProgramArguments - $ZITI_BIN_DIR/ziti-controller + $ZITI_BIN_DIR/ziti + controller run $ZITI_HOME/${controller_name}.yaml @@ -1407,7 +1408,8 @@ cat > "${output_file}" <$router_name ProgramArguments - $ZITI_BIN_DIR/ziti-router + $ZITI_BIN_DIR/ziti + router run $ZITI_HOME/ctrl.with.edge.yml From 32e1e02e98c35d4cd550741aacce14d7a6e53fa8 Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Wed, 21 Jun 2023 10:41:38 -0400 Subject: [PATCH 24/26] Update deps and changelog --- CHANGELOG.md | 37 +++++++++++++++----- go.mod | 46 ++++++++++++------------- go.sum | 90 +++++++++++++++++++++++++------------------------ zititest/go.mod | 46 ++++++++++++------------- zititest/go.sum | 90 +++++++++++++++++++++++++------------------------ 5 files changed, 167 insertions(+), 142 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a65957692..b9b6e0647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,37 @@ ## What's New +This is a bugfix release. + ## Component Updates and Bug Fixes + +* github.com/openziti/channel/v2: [v2.0.80 -> v2.0.81](https://github.com/openziti/channel/compare/v2.0.80...v2.0.81) +* github.com/openziti/edge: [v0.24.326 -> v0.24.345](https://github.com/openziti/edge/compare/v0.24.326...v0.24.345) + * [Issue #1528](https://github.com/openziti/edge/issues/1528) - edge unbind returns incorect message if token is not suplied or invalid + * [Issue #1416](https://github.com/openziti/edge/issues/1416) - Allow MFA token name to be configured + +* github.com/openziti/edge-api: [v0.25.25 -> v0.25.29](https://github.com/openziti/edge-api/compare/v0.25.25...v0.25.29) +* github.com/openziti/fabric: [v0.23.35 -> v0.23.39](https://github.com/openziti/fabric/compare/v0.23.35...v0.23.39) + * [Issue #751](https://github.com/openziti/fabric/issues/751) - Use of Fprintf causing buffer pool corruption with amqp event output + +* github.com/openziti/foundation/v2: [v2.0.25 -> v2.0.26](https://github.com/openziti/foundation/compare/v2.0.25...v2.0.26) +* github.com/openziti/identity: [v1.0.56 -> v1.0.57](https://github.com/openziti/identity/compare/v1.0.56...v1.0.57) +* github.com/openziti/runzmd: [v1.0.25 -> v1.0.26](https://github.com/openziti/runzmd/compare/v1.0.25...v1.0.26) +* github.com/openziti/sdk-golang: [v0.20.58 -> v0.20.67](https://github.com/openziti/sdk-golang/compare/v0.20.58...v0.20.67) +* github.com/openziti/storage: [v0.2.7 -> v0.2.8](https://github.com/openziti/storage/compare/v0.2.7...v0.2.8) +* github.com/openziti/transport/v2: [v2.0.90 -> v2.0.91](https://github.com/openziti/transport/compare/v2.0.90...v2.0.91) +* github.com/openziti/metrics: [v1.2.26 -> v1.2.27](https://github.com/openziti/metrics/compare/v1.2.26...v1.2.27) +* github.com/openziti/secretstream: [v0.1.8 -> v0.1.9](https://github.com/openziti/secretstream/compare/v0.1.8...v0.1.9) * github.com/openziti/ziti: [v0.28.1 -> v0.28.2](https://github.com/openziti/ziti/compare/v0.28.1...v0.28.2) - * [Issue #986](https://github.com/openziti/ziti/issues/986) - Updated default ports in `.env` file to match documentation. - * [Issue #920](https://github.com/openziti/ziti/issues/920) - Fixed bug causing failure when re-running quickstart. - * [Issue #779](https://github.com/openziti/ziti/issues/779) - Add ability to upgrade ziti binaries using a quickstart function. - * [Issue #761](https://github.com/openziti/ziti/issues/761) - Remove Management Listener section from controller config. - * [Issue #650](https://github.com/openziti/ziti/issues/650) - Removed/Updated references to `ZITI_EDGE_CONTROLLER_API` - * Quickstart environment variable names have been cleaned up. - * IMPORTANT: If you update your OpenZiti binaries to this version or later (which can be done easily with the `getZiti()` function, you will need to migrate any existing network that has been developed using OpenZiti v0.27.5 or earlier binaries as the new binaries will expect the new environment variable names. A function `performMigration()` has been provided in the `ziti-cli-script.sh` for this purpose. Simply source the latest `ziti-cli-script.sh`, and your current network's .env file, then run `performMigration()` to update environment variable name references. If the migration process cannot find your existing environment file in the default location, you will need to provide the path to the migration function, ex: `performMigration ` - * [Issue #1030](https://github.com/openziti/ziti/issues/1030) - Provide an upgrade path for quickstart cleanup + * [Issue #1144](https://github.com/openziti/ziti/issues/1144) - DB explore subcommand panic + * [Issue #986](https://github.com/openziti/ziti/issues/986) - Updated default ports in `.env` file to match documentation. + * [Issue #920](https://github.com/openziti/ziti/issues/920) - Fixed bug causing failure when re-running quickstart. + * [Issue #779](https://github.com/openziti/ziti/issues/779) - Add ability to upgrade ziti binaries using a quickstart function. + * [Issue #761](https://github.com/openziti/ziti/issues/761) - Remove Management Listener section from controller config. + * [Issue #650](https://github.com/openziti/ziti/issues/650) - Removed/Updated references to `ZITI_EDGE_CONTROLLER_API` + * Quickstart environment variable names have been cleaned up. + * IMPORTANT: If you update your OpenZiti binaries to this version or later (which can be done easily with the `getZiti()` function, you will need to migrate any existing network that has been developed using OpenZiti v0.27.5 or earlier binaries as the new binaries will expect the new environment variable names. A function `performMigration()` has been provided in the `ziti-cli-script.sh` for this purpose. Simply source the latest `ziti-cli-script.sh`, and your current network's .env file, then run `performMigration()` to update environment variable name references. If the migration process cannot find your existing environment file in the default location, you will need to provide the path to the migration function, ex: `performMigration ` + * [Issue #1030](https://github.com/openziti/ziti/issues/1030) - Provide an upgrade path for quickstart cleanup # Release 0.28.1 diff --git a/go.mod b/go.mod index 3ca4ba1e6..e05fc82b9 100644 --- a/go.mod +++ b/go.mod @@ -21,16 +21,16 @@ require ( github.com/jedib0t/go-pretty/v6 v6.4.0 github.com/michaelquigley/pfxlog v0.6.10 github.com/openziti/agent v1.0.14 - github.com/openziti/channel/v2 v2.0.80 - github.com/openziti/edge v0.24.326 - github.com/openziti/edge-api v0.25.25 - github.com/openziti/fabric v0.23.35 - github.com/openziti/foundation/v2 v2.0.25 - github.com/openziti/identity v1.0.56 - github.com/openziti/runzmd v1.0.25 - github.com/openziti/sdk-golang v0.20.58 - github.com/openziti/storage v0.2.7 - github.com/openziti/transport/v2 v2.0.90 + github.com/openziti/channel/v2 v2.0.81 + github.com/openziti/edge v0.24.345 + github.com/openziti/edge-api v0.25.29 + github.com/openziti/fabric v0.23.39 + github.com/openziti/foundation/v2 v2.0.26 + github.com/openziti/identity v1.0.57 + github.com/openziti/runzmd v1.0.26 + github.com/openziti/sdk-golang v0.20.67 + github.com/openziti/storage v0.2.8 + github.com/openziti/transport/v2 v2.0.91 github.com/openziti/xweb/v2 v2.0.2 github.com/openziti/ziti-db-explorer v1.1.1 github.com/pkg/errors v0.9.1 @@ -43,7 +43,7 @@ require ( github.com/spf13/viper v1.10.0 github.com/stretchr/testify v1.8.4 go.etcd.io/bbolt v1.3.7 - golang.org/x/net v0.10.0 + golang.org/x/net v0.11.0 google.golang.org/grpc v1.42.0 google.golang.org/protobuf v1.30.0 gopkg.in/AlecAivazis/survey.v1 v1.8.7 @@ -86,12 +86,12 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-openapi/analysis v0.21.4 // indirect - github.com/go-openapi/errors v0.20.3 // indirect + github.com/go-openapi/errors v0.20.4 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/loads v0.21.2 // indirect github.com/go-openapi/spec v0.20.9 // indirect - github.com/go-openapi/swag v0.22.3 // indirect + github.com/go-openapi/swag v0.22.4 // indirect github.com/go-openapi/validate v0.22.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect @@ -114,7 +114,7 @@ require ( github.com/josharian/native v1.1.0 // indirect github.com/kataras/go-events v0.0.3 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect - github.com/klauspost/compress v1.16.5 // indirect + github.com/klauspost/compress v1.16.6 // indirect github.com/kr/pty v1.1.8 // indirect github.com/kyokomi/emoji/v2 v2.2.12 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect @@ -129,7 +129,7 @@ require ( github.com/mdlayher/netlink v1.7.2 // indirect github.com/mdlayher/socket v0.4.1 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/miekg/dns v1.1.54 // indirect + github.com/miekg/dns v1.1.55 // indirect github.com/miekg/pkcs11 v1.1.1 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -142,8 +142,8 @@ require ( github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/openziti/dilithium v0.3.3 // indirect github.com/openziti/jwks v1.0.3 // indirect - github.com/openziti/metrics v1.2.26 // indirect - github.com/openziti/secretstream v0.1.8 // indirect + github.com/openziti/metrics v1.2.27 // indirect + github.com/openziti/secretstream v0.1.9 // indirect github.com/openziti/x509-claims v1.0.3 // indirect github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect github.com/parallaxsecond/parsec-client-go v0.0.0-20221025095442-f0a77d263cf9 // indirect @@ -175,14 +175,14 @@ require ( go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect - golang.org/x/crypto v0.9.0 // indirect + golang.org/x/crypto v0.10.0 // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/image v0.7.0 // indirect + golang.org/x/image v0.8.0 // indirect golang.org/x/mod v0.8.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/term v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.9.0 // indirect + golang.org/x/term v0.9.0 // indirect + golang.org/x/text v0.10.0 // indirect golang.org/x/tools v0.6.0 // indirect google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect gopkg.in/ini.v1 v1.66.2 // indirect diff --git a/go.sum b/go.sum index ba86f9615..9fb62a3a0 100644 --- a/go.sum +++ b/go.sum @@ -273,8 +273,8 @@ github.com/go-openapi/analysis v0.21.4/go.mod h1:4zQ35W4neeZTqh3ol0rv/O8JBbka9Qy github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/errors v0.20.3 h1:rz6kiC84sqNQoqrtulzaL/VERgkoCyB6WdEkc2ujzUc= -github.com/go-openapi/errors v0.20.3/go.mod h1:Z3FlZ4I8jEGxjUK+bugx3on2mIAk4txuAOhlsB1FSgk= +github.com/go-openapi/errors v0.20.4 h1:unTcVm6PispJsMECE3zWgvG4xTiKda1LIR5rCRWLG6M= +github.com/go-openapi/errors v0.20.4/go.mod h1:Z3FlZ4I8jEGxjUK+bugx3on2mIAk4txuAOhlsB1FSgk= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= @@ -300,8 +300,9 @@ github.com/go-openapi/strfmt v0.21.7/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KA github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-openapi/validate v0.22.1 h1:G+c2ub6q47kfX1sOBLwIQwzBVt8qmOAARyo/9Fqs9NU= github.com/go-openapi/validate v0.22.1/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= @@ -550,8 +551,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk= +github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -652,8 +653,8 @@ github.com/michaelquigley/pfxlog v0.6.10/go.mod h1:gEiNTfKEX6cJHSwRpOuqBpc8oYrlh github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= -github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI= -github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= +github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU= github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -721,34 +722,34 @@ github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTm github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openziti/agent v1.0.14 h1:OTYhj2HeIlFwaFNcVT5BlYf7s4xa0TNmhnjmBpN8Afg= github.com/openziti/agent v1.0.14/go.mod h1:zfm53+PVWoGFzjGGgQdKby5749G6VRYHe+eQJmoVKy4= -github.com/openziti/channel/v2 v2.0.80 h1:1gDikwcVvhRKs+CO8OyUHMSJWVJarCm5+OmffZ4gPCU= -github.com/openziti/channel/v2 v2.0.80/go.mod h1:U1KSHZXWlg8VelsZ55+ZGiARYWh+XbJbD7AfN0NXUdQ= +github.com/openziti/channel/v2 v2.0.81 h1:YtFMJz4pMhhOH92zZbOKAvx/l5zaRz5TQff0lTa5G6w= +github.com/openziti/channel/v2 v2.0.81/go.mod h1:d+2+i51uXi8J6M8OsazLJg1OzSPmL+sOyzdiRUmra3I= github.com/openziti/dilithium v0.3.3 h1:PLgQ6PMNLSTzCFbX/h98cmudgz/cU6TmjdSv5NAPD8k= github.com/openziti/dilithium v0.3.3/go.mod h1:vsCjI2AU/hon9e+dLhUFbCNGesJDj2ASgkySOcpmvjo= -github.com/openziti/edge v0.24.326 h1:Y5Z3DGac2ghXivh04S/3HgTymp1UliTaSlLn5fo3qdg= -github.com/openziti/edge v0.24.326/go.mod h1:vI2HZMZa+PdiIjf25xpg19lR32X+ouLbY3idOIw+Dac= -github.com/openziti/edge-api v0.25.25 h1:1S7L9JsvXuzd8nULZEPNgafPfhnHQY4Hhqj8B00CKTw= -github.com/openziti/edge-api v0.25.25/go.mod h1:aDUHHxOGtxFXnoDaTXpNF6gq+tbDkWCURP5yaEJbdm0= -github.com/openziti/fabric v0.23.35 h1:SxdMC88E5PCm7SoE8q0q8yOaO2fC1RiJES/sOYymVe4= -github.com/openziti/fabric v0.23.35/go.mod h1:eFG042f6bv/vZSOmp48pVAqEntCfkkMJCVAbNG9GHno= -github.com/openziti/foundation/v2 v2.0.25 h1:tGb9wdu6KCpO49RJ3HX2ClOVHf8gdntplIh/7CEVaM4= -github.com/openziti/foundation/v2 v2.0.25/go.mod h1:EOqea8Q1wXd4hS9MxFYM6ngDgenKGxz8c+CJ8Svr7BI= -github.com/openziti/identity v1.0.56 h1:h8SzatjWa3TCpIG6/holKUTHSKtNAJ1MuK5CCY31ZOw= -github.com/openziti/identity v1.0.56/go.mod h1:5h08wngbQjENt6sWPp+GyWpqNkeSPwMdDFPFONf6EBE= +github.com/openziti/edge v0.24.345 h1:7anwwljort9FsriHoBAiz6DOOkPJV2XCzZJLmn/TxFo= +github.com/openziti/edge v0.24.345/go.mod h1:pjU6bCSfaAVQLajeKB/ypGYoeZnIuHw7Y75kX37WHTw= +github.com/openziti/edge-api v0.25.29 h1:DbZ0GKpch9ik+XnC0qoP1dOg1AmgUEeWH4VIyOIehrQ= +github.com/openziti/edge-api v0.25.29/go.mod h1:mqYquh1RYvHjV/M9MGO4Ng0Xq9ixAH8o8cT5kw5XCWY= +github.com/openziti/fabric v0.23.39 h1:t6npkfBsPr+8GvF9X/rTLHxGsce5FTa4NoA80MInxYc= +github.com/openziti/fabric v0.23.39/go.mod h1:px2zUzQrgObmv6sdXgGJ028Wr45aGcgpFvfIP/qgDFo= +github.com/openziti/foundation/v2 v2.0.26 h1:RISGM97aIFnnEkxrcVsO6fnGg9W4ByydSnqWAVkJAqY= +github.com/openziti/foundation/v2 v2.0.26/go.mod h1:ngdQq0KLGIDfzkQQzu1BQSMLNrsBUXdziGvsJns4cFM= +github.com/openziti/identity v1.0.57 h1:tVFYGMVFINKWi4RV75yEz7hbDuRPqRnG+AiFAEtvXHQ= +github.com/openziti/identity v1.0.57/go.mod h1:cwkBpiIy1C4S6r+dD0jPKq9mS4aj7NuABt1WJwxHon8= github.com/openziti/jwks v1.0.3 h1:hf8wkb+Cg4nH/HM0KROFd7u+C3DkRVcFZJ7tDV+4icc= github.com/openziti/jwks v1.0.3/go.mod h1:t4xxq8vlXGsPn29kiQVnZBBDDnEoOFqtJoHibkJunQQ= -github.com/openziti/metrics v1.2.26 h1:8q93bK1MYAdR9ODr0qNAJ1/BQpFtHYdxZiH0Fc9LLo8= -github.com/openziti/metrics v1.2.26/go.mod h1:Z1c9pNHQr+yZODDsOeim93rYg5Hw1kPsuHi3zdy70dA= -github.com/openziti/runzmd v1.0.25 h1:/6LVurAnU8Hl4Tcm0FcncNicTIo3gwu2eMCiViPqzNQ= -github.com/openziti/runzmd v1.0.25/go.mod h1:pYnqjgH8/geMdzU8OIxamU8RlRdRaOh00mWBxDoXPDo= -github.com/openziti/sdk-golang v0.20.58 h1:cHyzEQiZSsaeJbN/lYqAY0i5fDlt9wlFH7LtG+0qFwE= -github.com/openziti/sdk-golang v0.20.58/go.mod h1:L6mGhnsxwDuVBE7ByCVLf2kPymf5l9l6WRUMA3SfZeo= -github.com/openziti/secretstream v0.1.8 h1:AgPHLDuXTiM1apHQmBvwvSW1vbQqAm7wUJDHqkQ/6Nk= -github.com/openziti/secretstream v0.1.8/go.mod h1:qcF8EmSX5SAT8k2pzsDI4bWugopv9AA+ltgWDrcAAEw= -github.com/openziti/storage v0.2.7 h1:rQVVclnkCZyr4XXKMypIJf46HFGJX5KEYWEycUhWvtg= -github.com/openziti/storage v0.2.7/go.mod h1:bGhUs/0XDsEJnTtNTpFAIh1X4lfdKvHu0m+8Z1TFVyM= -github.com/openziti/transport/v2 v2.0.90 h1:QoddlajGdyOZZDTxhgapkd3wucosTVGJn8z5Pt3ltOM= -github.com/openziti/transport/v2 v2.0.90/go.mod h1:q8zNDI7lYqA4flQVJwJZQg8HJVNcG7kIFLnH9qfeHDc= +github.com/openziti/metrics v1.2.27 h1:Dw/FSC+QvyqkDmLeSsxzCRD0aFPwgivwQyQsxzlAgoQ= +github.com/openziti/metrics v1.2.27/go.mod h1:mhP2c8MTGL0C5H8yAsNwBq88SW1C3Mx1ICVO6heMbJQ= +github.com/openziti/runzmd v1.0.26 h1:bWJhTD0jwkRi01e/fY72UbJ+x4iNEzE2Lx5chNp1sCU= +github.com/openziti/runzmd v1.0.26/go.mod h1:Lj1MpR8DXhVKxw6MdaSU0bD6Wh8CwzNpEw5Qm/NSWfM= +github.com/openziti/sdk-golang v0.20.67 h1:atesqk/yUAM1sBe5zaMwKrRBYLzeEtUz7BQn72hFyR8= +github.com/openziti/sdk-golang v0.20.67/go.mod h1:zieqsVAB/kawb/Ske7zkArUG2TGUIOdcHyVh79NcnBA= +github.com/openziti/secretstream v0.1.9 h1:mNCMr9oYQ4JAfdU4iU79i3si4vqVVsErzrhXuKC7R3M= +github.com/openziti/secretstream v0.1.9/go.mod h1:tq0XVUwFAT0TwfBpILp4KaeEnasduNTUixOIrmUZUGA= +github.com/openziti/storage v0.2.8 h1:Rbnj6LKfcdR644kXrS4bF0ot+z17zDGCiUifd1eOvZ0= +github.com/openziti/storage v0.2.8/go.mod h1:Cd1YuhqSLbVI0vaujTQl/cHgPCECapLGh/s4bMgKczM= +github.com/openziti/transport/v2 v2.0.91 h1:eEWRSoy9+tDf6K+jJcl5TSHm6GX7IKiBQg8XxmDyELQ= +github.com/openziti/transport/v2 v2.0.91/go.mod h1:FDGkg110LTdmz4Kp1zucomvc++ld7UKXFfNWBTwQIlQ= github.com/openziti/x509-claims v1.0.3 h1:HNdQ8Nf1agB3lBs1gahcO6zfkeS4S5xoQ2/PkY4HRX0= github.com/openziti/x509-claims v1.0.3/go.mod h1:Z0WIpBm6c4ecrpRKrou6Gk2wrLWxJO/+tuUwKh8VewE= github.com/openziti/xweb/v2 v2.0.2 h1:XYlVFriTq/U1wcUrc+XPnWJGhXh9NJPhtQ7+r3aC0cU= @@ -1054,8 +1055,8 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1072,8 +1073,8 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20191206065243-da761ea9ff43/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw= -golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg= +golang.org/x/image v0.8.0 h1:agUcRXV/+w6L9ryntYYsF2x9fQTMd4T8fiiYXAVW6Jg= +golang.org/x/image v0.8.0/go.mod h1:PwLxp3opCYg4WR2WO9P0L6ESnsD6bLTWcw8zanLMVFM= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -1157,8 +1158,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1188,8 +1189,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180606202747-9527bec2660b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1278,14 +1279,15 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28= +golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1297,8 +1299,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/zititest/go.mod b/zititest/go.mod index a814a754e..f7d8669d0 100644 --- a/zititest/go.mod +++ b/zititest/go.mod @@ -8,22 +8,22 @@ require ( github.com/Jeffail/gabs v1.4.0 github.com/Jeffail/gabs/v2 v2.7.0 github.com/michaelquigley/pfxlog v0.6.10 - github.com/openziti/channel/v2 v2.0.80 - github.com/openziti/edge v0.24.326 + github.com/openziti/channel/v2 v2.0.81 + github.com/openziti/edge v0.24.345 github.com/openziti/fablab v0.4.52 - github.com/openziti/fabric v0.23.35 - github.com/openziti/foundation/v2 v2.0.25 - github.com/openziti/identity v1.0.56 - github.com/openziti/sdk-golang v0.20.58 - github.com/openziti/storage v0.2.7 - github.com/openziti/transport/v2 v2.0.90 + github.com/openziti/fabric v0.23.39 + github.com/openziti/foundation/v2 v2.0.26 + github.com/openziti/identity v1.0.57 + github.com/openziti/sdk-golang v0.20.67 + github.com/openziti/storage v0.2.8 + github.com/openziti/transport/v2 v2.0.91 github.com/openziti/ziti v0.28.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 go.etcd.io/bbolt v1.3.7 - golang.org/x/net v0.10.0 + golang.org/x/net v0.11.0 google.golang.org/protobuf v1.30.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -63,14 +63,14 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-openapi/analysis v0.21.4 // indirect - github.com/go-openapi/errors v0.20.3 // indirect + github.com/go-openapi/errors v0.20.4 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/loads v0.21.2 // indirect github.com/go-openapi/runtime v0.26.0 // indirect github.com/go-openapi/spec v0.20.9 // indirect github.com/go-openapi/strfmt v0.21.7 // indirect - github.com/go-openapi/swag v0.22.3 // indirect + github.com/go-openapi/swag v0.22.4 // indirect github.com/go-openapi/validate v0.22.1 // indirect github.com/go-resty/resty/v2 v2.7.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect @@ -100,7 +100,7 @@ require ( github.com/josharian/native v1.1.0 // indirect github.com/kataras/go-events v0.0.3 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect - github.com/klauspost/compress v1.16.5 // indirect + github.com/klauspost/compress v1.16.6 // indirect github.com/kr/fs v0.1.0 // indirect github.com/kyokomi/emoji/v2 v2.2.12 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect @@ -116,7 +116,7 @@ require ( github.com/mdlayher/socket v0.4.1 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/michaelquigley/figlet v0.0.0-20191015203154-054d06db54b4 // indirect - github.com/miekg/dns v1.1.54 // indirect + github.com/miekg/dns v1.1.55 // indirect github.com/miekg/pkcs11 v1.1.1 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -126,11 +126,11 @@ require ( github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/openziti/agent v1.0.14 // indirect - github.com/openziti/edge-api v0.25.25 // indirect + github.com/openziti/edge-api v0.25.29 // indirect github.com/openziti/jwks v1.0.3 // indirect - github.com/openziti/metrics v1.2.26 // indirect - github.com/openziti/runzmd v1.0.25 // indirect - github.com/openziti/secretstream v0.1.8 // indirect + github.com/openziti/metrics v1.2.27 // indirect + github.com/openziti/runzmd v1.0.26 // indirect + github.com/openziti/secretstream v0.1.9 // indirect github.com/openziti/x509-claims v1.0.3 // indirect github.com/openziti/xweb/v2 v2.0.2 // indirect github.com/openziti/ziti-db-explorer v1.1.1 // indirect @@ -170,14 +170,14 @@ require ( go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect - golang.org/x/crypto v0.9.0 // indirect + golang.org/x/crypto v0.10.0 // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/image v0.7.0 // indirect + golang.org/x/image v0.8.0 // indirect golang.org/x/mod v0.8.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/term v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.9.0 // indirect + golang.org/x/term v0.9.0 // indirect + golang.org/x/text v0.10.0 // indirect golang.org/x/tools v0.6.0 // indirect gopkg.in/AlecAivazis/survey.v1 v1.8.7 // indirect gopkg.in/ini.v1 v1.66.2 // indirect diff --git a/zititest/go.sum b/zititest/go.sum index a5ff3437f..c90ccf65b 100644 --- a/zititest/go.sum +++ b/zititest/go.sum @@ -228,8 +228,8 @@ github.com/go-openapi/analysis v0.21.4/go.mod h1:4zQ35W4neeZTqh3ol0rv/O8JBbka9Qy github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/errors v0.20.3 h1:rz6kiC84sqNQoqrtulzaL/VERgkoCyB6WdEkc2ujzUc= -github.com/go-openapi/errors v0.20.3/go.mod h1:Z3FlZ4I8jEGxjUK+bugx3on2mIAk4txuAOhlsB1FSgk= +github.com/go-openapi/errors v0.20.4 h1:unTcVm6PispJsMECE3zWgvG4xTiKda1LIR5rCRWLG6M= +github.com/go-openapi/errors v0.20.4/go.mod h1:Z3FlZ4I8jEGxjUK+bugx3on2mIAk4txuAOhlsB1FSgk= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= @@ -255,8 +255,9 @@ github.com/go-openapi/strfmt v0.21.7/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KA github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= -github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= +github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-openapi/validate v0.22.1 h1:G+c2ub6q47kfX1sOBLwIQwzBVt8qmOAARyo/9Fqs9NU= github.com/go-openapi/validate v0.22.1/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= @@ -491,8 +492,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= -github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk= +github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -579,8 +580,8 @@ github.com/michaelquigley/pfxlog v0.6.10 h1:IbC/H3MmSDcPlQHF1UZPQU13Dkrs0+ycWRyQ github.com/michaelquigley/pfxlog v0.6.10/go.mod h1:gEiNTfKEX6cJHSwRpOuqBpc8oYrlhMiDK/xMk/gV7D0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= -github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI= -github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= +github.com/miekg/dns v1.1.55 h1:GoQ4hpsj0nFLYe+bWiCToyrBEJXkQfOOIvFGFy0lEgo= +github.com/miekg/dns v1.1.55/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY= github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU= github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -640,34 +641,34 @@ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYr github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openziti/agent v1.0.14 h1:OTYhj2HeIlFwaFNcVT5BlYf7s4xa0TNmhnjmBpN8Afg= github.com/openziti/agent v1.0.14/go.mod h1:zfm53+PVWoGFzjGGgQdKby5749G6VRYHe+eQJmoVKy4= -github.com/openziti/channel/v2 v2.0.80 h1:1gDikwcVvhRKs+CO8OyUHMSJWVJarCm5+OmffZ4gPCU= -github.com/openziti/channel/v2 v2.0.80/go.mod h1:U1KSHZXWlg8VelsZ55+ZGiARYWh+XbJbD7AfN0NXUdQ= -github.com/openziti/edge v0.24.326 h1:Y5Z3DGac2ghXivh04S/3HgTymp1UliTaSlLn5fo3qdg= -github.com/openziti/edge v0.24.326/go.mod h1:vI2HZMZa+PdiIjf25xpg19lR32X+ouLbY3idOIw+Dac= -github.com/openziti/edge-api v0.25.25 h1:1S7L9JsvXuzd8nULZEPNgafPfhnHQY4Hhqj8B00CKTw= -github.com/openziti/edge-api v0.25.25/go.mod h1:aDUHHxOGtxFXnoDaTXpNF6gq+tbDkWCURP5yaEJbdm0= +github.com/openziti/channel/v2 v2.0.81 h1:YtFMJz4pMhhOH92zZbOKAvx/l5zaRz5TQff0lTa5G6w= +github.com/openziti/channel/v2 v2.0.81/go.mod h1:d+2+i51uXi8J6M8OsazLJg1OzSPmL+sOyzdiRUmra3I= +github.com/openziti/edge v0.24.345 h1:7anwwljort9FsriHoBAiz6DOOkPJV2XCzZJLmn/TxFo= +github.com/openziti/edge v0.24.345/go.mod h1:pjU6bCSfaAVQLajeKB/ypGYoeZnIuHw7Y75kX37WHTw= +github.com/openziti/edge-api v0.25.29 h1:DbZ0GKpch9ik+XnC0qoP1dOg1AmgUEeWH4VIyOIehrQ= +github.com/openziti/edge-api v0.25.29/go.mod h1:mqYquh1RYvHjV/M9MGO4Ng0Xq9ixAH8o8cT5kw5XCWY= github.com/openziti/fablab v0.4.52 h1:X5+NaRnfPxbzhxUh9b4IQmVNVgYWFf8/Ck2sKNz77ho= github.com/openziti/fablab v0.4.52/go.mod h1:aF8Fu3C8hnnaOJyAZz3AXGY4cMxQyBLhoIlSRJ/VVpc= -github.com/openziti/fabric v0.23.35 h1:SxdMC88E5PCm7SoE8q0q8yOaO2fC1RiJES/sOYymVe4= -github.com/openziti/fabric v0.23.35/go.mod h1:eFG042f6bv/vZSOmp48pVAqEntCfkkMJCVAbNG9GHno= -github.com/openziti/foundation/v2 v2.0.25 h1:tGb9wdu6KCpO49RJ3HX2ClOVHf8gdntplIh/7CEVaM4= -github.com/openziti/foundation/v2 v2.0.25/go.mod h1:EOqea8Q1wXd4hS9MxFYM6ngDgenKGxz8c+CJ8Svr7BI= -github.com/openziti/identity v1.0.56 h1:h8SzatjWa3TCpIG6/holKUTHSKtNAJ1MuK5CCY31ZOw= -github.com/openziti/identity v1.0.56/go.mod h1:5h08wngbQjENt6sWPp+GyWpqNkeSPwMdDFPFONf6EBE= +github.com/openziti/fabric v0.23.39 h1:t6npkfBsPr+8GvF9X/rTLHxGsce5FTa4NoA80MInxYc= +github.com/openziti/fabric v0.23.39/go.mod h1:px2zUzQrgObmv6sdXgGJ028Wr45aGcgpFvfIP/qgDFo= +github.com/openziti/foundation/v2 v2.0.26 h1:RISGM97aIFnnEkxrcVsO6fnGg9W4ByydSnqWAVkJAqY= +github.com/openziti/foundation/v2 v2.0.26/go.mod h1:ngdQq0KLGIDfzkQQzu1BQSMLNrsBUXdziGvsJns4cFM= +github.com/openziti/identity v1.0.57 h1:tVFYGMVFINKWi4RV75yEz7hbDuRPqRnG+AiFAEtvXHQ= +github.com/openziti/identity v1.0.57/go.mod h1:cwkBpiIy1C4S6r+dD0jPKq9mS4aj7NuABt1WJwxHon8= github.com/openziti/jwks v1.0.3 h1:hf8wkb+Cg4nH/HM0KROFd7u+C3DkRVcFZJ7tDV+4icc= github.com/openziti/jwks v1.0.3/go.mod h1:t4xxq8vlXGsPn29kiQVnZBBDDnEoOFqtJoHibkJunQQ= -github.com/openziti/metrics v1.2.26 h1:8q93bK1MYAdR9ODr0qNAJ1/BQpFtHYdxZiH0Fc9LLo8= -github.com/openziti/metrics v1.2.26/go.mod h1:Z1c9pNHQr+yZODDsOeim93rYg5Hw1kPsuHi3zdy70dA= -github.com/openziti/runzmd v1.0.25 h1:/6LVurAnU8Hl4Tcm0FcncNicTIo3gwu2eMCiViPqzNQ= -github.com/openziti/runzmd v1.0.25/go.mod h1:pYnqjgH8/geMdzU8OIxamU8RlRdRaOh00mWBxDoXPDo= -github.com/openziti/sdk-golang v0.20.58 h1:cHyzEQiZSsaeJbN/lYqAY0i5fDlt9wlFH7LtG+0qFwE= -github.com/openziti/sdk-golang v0.20.58/go.mod h1:L6mGhnsxwDuVBE7ByCVLf2kPymf5l9l6WRUMA3SfZeo= -github.com/openziti/secretstream v0.1.8 h1:AgPHLDuXTiM1apHQmBvwvSW1vbQqAm7wUJDHqkQ/6Nk= -github.com/openziti/secretstream v0.1.8/go.mod h1:qcF8EmSX5SAT8k2pzsDI4bWugopv9AA+ltgWDrcAAEw= -github.com/openziti/storage v0.2.7 h1:rQVVclnkCZyr4XXKMypIJf46HFGJX5KEYWEycUhWvtg= -github.com/openziti/storage v0.2.7/go.mod h1:bGhUs/0XDsEJnTtNTpFAIh1X4lfdKvHu0m+8Z1TFVyM= -github.com/openziti/transport/v2 v2.0.90 h1:QoddlajGdyOZZDTxhgapkd3wucosTVGJn8z5Pt3ltOM= -github.com/openziti/transport/v2 v2.0.90/go.mod h1:q8zNDI7lYqA4flQVJwJZQg8HJVNcG7kIFLnH9qfeHDc= +github.com/openziti/metrics v1.2.27 h1:Dw/FSC+QvyqkDmLeSsxzCRD0aFPwgivwQyQsxzlAgoQ= +github.com/openziti/metrics v1.2.27/go.mod h1:mhP2c8MTGL0C5H8yAsNwBq88SW1C3Mx1ICVO6heMbJQ= +github.com/openziti/runzmd v1.0.26 h1:bWJhTD0jwkRi01e/fY72UbJ+x4iNEzE2Lx5chNp1sCU= +github.com/openziti/runzmd v1.0.26/go.mod h1:Lj1MpR8DXhVKxw6MdaSU0bD6Wh8CwzNpEw5Qm/NSWfM= +github.com/openziti/sdk-golang v0.20.67 h1:atesqk/yUAM1sBe5zaMwKrRBYLzeEtUz7BQn72hFyR8= +github.com/openziti/sdk-golang v0.20.67/go.mod h1:zieqsVAB/kawb/Ske7zkArUG2TGUIOdcHyVh79NcnBA= +github.com/openziti/secretstream v0.1.9 h1:mNCMr9oYQ4JAfdU4iU79i3si4vqVVsErzrhXuKC7R3M= +github.com/openziti/secretstream v0.1.9/go.mod h1:tq0XVUwFAT0TwfBpILp4KaeEnasduNTUixOIrmUZUGA= +github.com/openziti/storage v0.2.8 h1:Rbnj6LKfcdR644kXrS4bF0ot+z17zDGCiUifd1eOvZ0= +github.com/openziti/storage v0.2.8/go.mod h1:Cd1YuhqSLbVI0vaujTQl/cHgPCECapLGh/s4bMgKczM= +github.com/openziti/transport/v2 v2.0.91 h1:eEWRSoy9+tDf6K+jJcl5TSHm6GX7IKiBQg8XxmDyELQ= +github.com/openziti/transport/v2 v2.0.91/go.mod h1:FDGkg110LTdmz4Kp1zucomvc++ld7UKXFfNWBTwQIlQ= github.com/openziti/x509-claims v1.0.3 h1:HNdQ8Nf1agB3lBs1gahcO6zfkeS4S5xoQ2/PkY4HRX0= github.com/openziti/x509-claims v1.0.3/go.mod h1:Z0WIpBm6c4ecrpRKrou6Gk2wrLWxJO/+tuUwKh8VewE= github.com/openziti/xweb/v2 v2.0.2 h1:XYlVFriTq/U1wcUrc+XPnWJGhXh9NJPhtQ7+r3aC0cU= @@ -912,8 +913,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -930,8 +931,8 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20191206065243-da761ea9ff43/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw= -golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg= +golang.org/x/image v0.8.0 h1:agUcRXV/+w6L9ryntYYsF2x9fQTMd4T8fiiYXAVW6Jg= +golang.org/x/image v0.8.0/go.mod h1:PwLxp3opCYg4WR2WO9P0L6ESnsD6bLTWcw8zanLMVFM= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1011,8 +1012,8 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1039,8 +1040,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180606202747-9527bec2660b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1124,14 +1125,15 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28= +golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1143,8 +1145,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From fa297c78600dc045e84a16e5e90cd1337f44121e Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Wed, 21 Jun 2023 11:20:04 -0400 Subject: [PATCH 25/26] Add fix for determining mgmt API path. Fix CLI config dir setting. --- CHANGELOG.md | 5 +++-- ziti/cmd/helpers/env_helpers.go | 1 - ziti/util/dirs.go | 15 +-------------- ziti/util/rest.go | 10 ++++++++-- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b6e0647..f25e2d0b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## What's New -This is a bugfix release. +* IMPORTANT: If you update your OpenZiti binaries to this version or later (which can be done easily with the `getZiti()` function, you will need to migrate any existing network that has been developed using OpenZiti v0.27.5 or earlier binaries as the new binaries will expect the new environment variable names. A function `performMigration()` has been provided in the `ziti-cli-script.sh` for this purpose. Simply source the latest `ziti-cli-script.sh`, and your current network's .env file, then run `performMigration()` to update environment variable name references. If the migration process cannot find your existing environment file in the default location, you will need to provide the path to the migration function, ex: `performMigration ` +* If you were using the `ZITI_HOME` environment variable to configure where your ziti CLI profiles were stored, you should now use `ZITI_CONFIG_DIR` instead. + ## Component Updates and Bug Fixes @@ -31,7 +33,6 @@ This is a bugfix release. * [Issue #761](https://github.com/openziti/ziti/issues/761) - Remove Management Listener section from controller config. * [Issue #650](https://github.com/openziti/ziti/issues/650) - Removed/Updated references to `ZITI_EDGE_CONTROLLER_API` * Quickstart environment variable names have been cleaned up. - * IMPORTANT: If you update your OpenZiti binaries to this version or later (which can be done easily with the `getZiti()` function, you will need to migrate any existing network that has been developed using OpenZiti v0.27.5 or earlier binaries as the new binaries will expect the new environment variable names. A function `performMigration()` has been provided in the `ziti-cli-script.sh` for this purpose. Simply source the latest `ziti-cli-script.sh`, and your current network's .env file, then run `performMigration()` to update environment variable name references. If the migration process cannot find your existing environment file in the default location, you will need to provide the path to the migration function, ex: `performMigration ` * [Issue #1030](https://github.com/openziti/ziti/issues/1030) - Provide an upgrade path for quickstart cleanup # Release 0.28.1 diff --git a/ziti/cmd/helpers/env_helpers.go b/ziti/cmd/helpers/env_helpers.go index 448fabd3b..193d4ed39 100644 --- a/ziti/cmd/helpers/env_helpers.go +++ b/ziti/cmd/helpers/env_helpers.go @@ -47,7 +47,6 @@ func WorkingDir() (string, error) { } func GetZitiHome() (string, error) { - // Get path from env variable retVal := os.Getenv(constants.ZitiHomeVarName) diff --git a/ziti/util/dirs.go b/ziti/util/dirs.go index 597ca5e3f..9c28744ce 100644 --- a/ziti/util/dirs.go +++ b/ziti/util/dirs.go @@ -37,7 +37,7 @@ func HomeDir() string { } func ConfigDir() (string, error) { - path := os.Getenv("ZITI_HOME") + path := os.Getenv("ZITI_CONFIG_DIR") if path != "" { return path, nil } @@ -55,19 +55,6 @@ func ConfigDir() (string, error) { return path, nil } -func FabricConfigDir() (string, error) { - h, err := ConfigDir() - if err != nil { - return "", err - } - path := filepath.Join(h, "fabric") - err = os.MkdirAll(path, DefaultWritePermissions) - if err != nil { - return "", err - } - return path, nil -} - func ZitiAppConfigDir(zitiApp string) (string, error) { h, err := ConfigDir() if err != nil { diff --git a/ziti/util/rest.go b/ziti/util/rest.go index 9d2416f7b..61af030f8 100644 --- a/ziti/util/rest.go +++ b/ziti/util/rest.go @@ -862,10 +862,16 @@ func EdgeControllerGetManagementApiBasePath(host string, cert string) string { client.SetRootCertificate(cert) } - resp, err := client.R().Get("/version") + // check v1 path first + resp, err := client.R().Get("/edge/client/v1/version") if err != nil || resp.StatusCode() != http.StatusOK { - return host + // if v1 path fails, fall back to removed /version path + resp, err = client.R().Get("/version") + + if err != nil || resp.StatusCode() != http.StatusOK { + return host + } } data, err := gabs.ParseJSON(resp.Body()) From 263ff30ce6944d427ec444818aa8225db8a837df Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Wed, 21 Jun 2023 15:11:34 -0400 Subject: [PATCH 26/26] Remove file before extracting when using ziti use --- ziti/util/rest.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ziti/util/rest.go b/ziti/util/rest.go index 61af030f8..d638a18bb 100644 --- a/ziti/util/rest.go +++ b/ziti/util/rest.go @@ -377,6 +377,10 @@ func UnTargz(tarball, target string, onlyFiles []string) error { return err } continue + } else { + if err = os.Remove(path); err != nil { + fmt.Printf("error removing [%s] (%v)", path, err) + } } file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())