From e631908c2009e7dcb011ce78b1284126b48c619d Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Mon, 21 Nov 2022 18:07:08 -0500 Subject: [PATCH 01/12] use the short hostname instead because FQDN breaks CentOS; use pkill instead of killall because it's more prevalent --- quickstart/docker/image/ziti-cli-functions.sh | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index e2e158f35..cbdfed621 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -2,8 +2,10 @@ set -uo pipefail +ZITI_HOSTNAME="$(hostname -s)" + # shellcheck disable=SC2155 -export DEFAULT_ZITI_HOME_LOCATION="${HOME}/.ziti/quickstart/$(hostname)" +export DEFAULT_ZITI_HOME_LOCATION="${HOME}/.ziti/quickstart/${ZITI_HOSTNAME}" export ZITI_QUICKSTART_ENVROOT="${HOME}/.ziti/quickstart" @@ -69,7 +71,7 @@ function startZitiController { } function stopZitiController { - killall ziti-controller + pkill ziti-controller # shellcheck disable=SC2181 if [[ $? == 0 ]]; then echo "Controller stopped."; fi } @@ -83,7 +85,7 @@ function startExpressEdgeRouter { } function stopAllEdgeRouters { - killall ziti-router + pkill ziti-router # shellcheck disable=SC2181 if [[ $? == 0 ]]; then echo "Router(s) stopped."; fi } @@ -138,7 +140,7 @@ function verifyZitiVersionExists { unset ZITI_BINARIES_VERSION - ziticurl="$(curl -s https://api.github.com/repos/openziti/ziti/releases/tags/"${ZITI_VERSION_OVERRIDE}")" + 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 @@ -146,6 +148,7 @@ function verifyZitiVersionExists { # 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 @@ -178,7 +181,7 @@ function getLatestZitiVersion { unset ZITI_BINARIES_VERSION if [[ "${ZITI_BINARIES_VERSION-}" == "" ]]; then - zitilatest=$(curl -s https://api.github.com/repos/openziti/ziti/releases/latest) + 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 @@ -323,15 +326,15 @@ function setupZitiNetwork { 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 "$(hostname)")" + echo -e "$(BLUE "${ZITI_HOSTNAME}")" echo " " - echo -en "$(echo -ne "Network Name [$(BLUE "$(hostname)")]: ")" + echo -en "$(echo -ne "Network Name [$(BLUE "${ZITI_HOSTNAME}")]: ")" read -r ZITI_NETWORK echo " " if checkControllerName; then : #clear to continue if [[ "${ZITI_NETWORK-}" == "" ]]; then - ZITI_NETWORK="$(hostname)" + ZITI_NETWORK="${ZITI_HOSTNAME}" fi echo "name: ${ZITI_NETWORK-}" else @@ -451,7 +454,7 @@ function ziti_expressConfiguration { echo " " echo -e "******** Setting Up Environment ********" if [[ "${1-}" == "" ]]; then - nw="$(hostname)" + nw="${ZITI_HOSTNAME}" else nw="${1-}" fi @@ -718,7 +721,7 @@ function createRouterPki { 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,$(hostname)" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}" "${router_name}" + pki_client_server "${router_name},localhost,127.0.0.1,${ZITI_HOSTNAME}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}" "${router_name}" } function createPrivateRouterConfig { @@ -781,7 +784,7 @@ function createPki { pki_create_intermediate "${ZITI_SPURIOUS_INTERMEDIATE}" "${ZITI_SIGNING_INTERMEDIATE_NAME}" 1 echo " " - pki_allow_list_dns="${ZITI_CONTROLLER_HOSTNAME},localhost,$(hostname)" + pki_allow_list_dns="${ZITI_CONTROLLER_HOSTNAME},localhost,${ZITI_HOSTNAME}" 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" @@ -966,7 +969,7 @@ function ziti_createEnvFile { if [[ "${retVal}" != 0 ]]; then if decideToUseDefaultZitiHome; then # shellcheck disable=SC2155 - export ZITI_NETWORK="$(hostname)" + export ZITI_NETWORK="${ZITI_HOSTNAME}" ZITI_HOME="${DEFAULT_ZITI_HOME_LOCATION}" else return 1 @@ -998,16 +1001,16 @@ function ziti_createEnvFile { export ZITI_NETWORK="${1-}" fi if [[ "${ZITI_NETWORK-}" = "" ]]; then - echo -e "$(YELLOW "WARN: ZITI_NETWORK HAS NOT BEEN DECLARED! USING hostname: $(hostname)")" + echo -e "$(YELLOW "WARN: ZITI_NETWORK HAS NOT BEEN DECLARED! USING hostname: ${ZITI_HOSTNAME}")" # shellcheck disable=SC2155 - export ZITI_NETWORK="$(hostname)" + export ZITI_NETWORK="${ZITI_HOSTNAME}" fi fi echo "ZITI_NETWORK set to: ${ZITI_NETWORK}" if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; fi - if [[ "${ZITI_PWD-}" == "" ]]; then export ZITI_PWD="admin"; fi + if [[ "${ZITI_PWD-}" == "" ]]; then export ZITI_PWD="$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c${1:-32})"; fi if [[ "${ZITI_DOMAIN_SUFFIX-}" == "" ]]; then export ZITI_DOMAIN_SUFFIX=""; fi if [[ "${ZITI_ID-}" == "" ]]; then export ZITI_ID="${ZITI_HOME}/identities.yaml"; fi From ec1b6f5e0467ca46faeef77a207c4f9d73b1bb5d Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 22 Nov 2022 16:56:07 -0500 Subject: [PATCH 02/12] embellish the functions that do initial start and stop of the controller during expressInstall and manually start and stop the router --- quickstart/docker/image/ziti-cli-functions.sh | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index cbdfed621..ebdf3e67c 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -67,13 +67,21 @@ function startZitiController { ("${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" > "${log_file}" 2>&1 &) pid=$! echo -e "ziti-controller started as process id: $pid. log located at: $(BLUE "${log_file}")" - return $pid + echo $pid # for capture by caller } function stopZitiController { - pkill ziti-controller - # shellcheck disable=SC2181 - if [[ $? == 0 ]]; then echo "Controller stopped."; fi + if (( ${#} )); then + kill "$1" + # shellcheck disable=SC2181 + if [[ $? == 0 ]]; then + echo "Controller stopped." + return 0 + fi + else + echo "ERROR: need controller PID to kill" >&2 + return 1 + fi } function startExpressEdgeRouter { @@ -81,13 +89,40 @@ function startExpressEdgeRouter { "${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${log_file}" 2>&1 & pid=$! echo -e "Express Edge Router started as process id: $pid. log located at: $(BLUE "${log_file}")" - return $pid + ZITI_EXPRESS_EDGE_ROUTER_PID="$pid" } function stopAllEdgeRouters { - pkill ziti-router - # shellcheck disable=SC2181 - if [[ $? == 0 ]]; then echo "Router(s) stopped."; fi + 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 + if which pkill &>/dev/null; then + # shellcheck disable=SC2015 + pkill ziti-router && { + echo "Router(s) stopped." + } || { + echo "ERROR: something went wrong with stopping the router(s)" >&2 + return 1 + } + elif which killall &>/dev/null; then + # shellcheck disable=SC2015 + killall ziti-router && { + echo "Router(s) stopped." + } || { + echo "ERROR: something went wrong with stopping the router(s)" >&2 + return 1 + } + else + echo "ERROR: need 'pkill' or 'killall' command to kill routers that were not started with startExpressEdgeRouter" >&2 + return 1 + fi + fi } function checkHostsFile { @@ -484,7 +519,7 @@ function ziti_expressConfiguration { createControllerConfig #createControllerSystemdFile initializeController - startZitiController + ZITI_EXPRESS_CONTROLLER_PID=$(startZitiController) echo "waiting for the controller to come online to allow the edge router to enroll" waitForController @@ -518,7 +553,7 @@ function ziti_expressConfiguration { "${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 "" - stopZitiController + [[ -n ${ZITI_EXPRESS_CONTROLLER_PID:-} ]] && stopZitiController "${ZITI_EXPRESS_CONTROLLER_PID}" echo "Edge Router enrolled. Controller stopped." echo "" From 5e759ee96e5080bfbefd853311af2a5670f8e1c0 Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 22 Nov 2022 18:01:56 -0500 Subject: [PATCH 03/12] prompt to optionally change the admin pwd --- quickstart/docker/image/ziti-cli-functions.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index ebdf3e67c..1089df75b 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -1045,7 +1045,18 @@ function ziti_createEnvFile { echo "ZITI_NETWORK set to: ${ZITI_NETWORK}" if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; fi - if [[ "${ZITI_PWD-}" == "" ]]; then export ZITI_PWD="$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c${1:-32})"; fi + if [[ "${ZITI_PWD-}" == "" ]]; then + ZITI_PWD="$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c32)" + echo -e "Do you want to keep the generated admin password '$ZITI_PWD'? (Y/n)" + # shellcheck disable=SC2162 + read ZITI_PWD_REPLY + if [[ -z "${ZITI_PWD_REPLY}" || ${ZITI_PWD_REPLY} =~ [yY] ]]; then + echo "INFO: using ZITI_PWD=${ZITI_PWD}" + else + echo "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 From 046096e46941b2bd011def56078e8f29c49d7285 Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 22 Nov 2022 18:07:30 -0500 Subject: [PATCH 04/12] send express controller initial startup pid to stop function --- 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 1089df75b..aaf0fdcf0 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -458,7 +458,7 @@ function ziti_expressConfiguration { # Stop any devices currently running to avoid port collisions stopAllEdgeRouters - stopZitiController + stopZitiController "${ZITI_EXPRESS_CONTROLLER_PID}" else echo -e "$(RED " --- Exiting express install ---")" return 1 From 6e626943ff2c21ee95f0a25ec0c689629ae9bc3b Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 22 Nov 2022 19:36:20 -0500 Subject: [PATCH 05/12] only output the PID from the function that starts the controller --- 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 aaf0fdcf0..070ec9dde 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -66,7 +66,6 @@ function startZitiController { # shellcheck disable=SC2034 ("${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" > "${log_file}" 2>&1 &) pid=$! - echo -e "ziti-controller started as process id: $pid. log located at: $(BLUE "${log_file}")" echo $pid # for capture by caller } @@ -520,6 +519,7 @@ function ziti_expressConfiguration { #createControllerSystemdFile initializeController ZITI_EXPRESS_CONTROLLER_PID=$(startZitiController) + echo "ziti-controller started as process id: $pid. log located at: $(BLUE "${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}.log")" echo "waiting for the controller to come online to allow the edge router to enroll" waitForController From 80d2823dfce4b8a4b3928e05601619e83828b070 Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 22 Nov 2022 20:07:44 -0500 Subject: [PATCH 06/12] fix functions that start and stop the controller during expressInstall --- quickstart/docker/image/ziti-cli-functions.sh | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 070ec9dde..d9cf83306 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -64,21 +64,37 @@ function initializeController { function startZitiController { 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}" 2>&1 &) - pid=$! - echo $pid # for capture by caller + "${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_RAWNAME}.yaml" &> "${log_file}" & + ZITI_EXPRESS_CONTROLLER_PID=$! + echo "ziti-controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}.log")" } function stopZitiController { - if (( ${#} )); then - kill "$1" + if [[ -n ${ZITI_EXPRESS_CONTROLLER_PID:-} ]]; then + kill "$ZITI_EXPRESS_CONTROLLER_PID" # shellcheck disable=SC2181 if [[ $? == 0 ]]; then echo "Controller stopped." return 0 fi + elif which pkill &>/dev/null; then + # shellcheck disable=SC2015 + pkill ziti-controller && { + echo "Controller stopped." + } || { + echo "ERROR: something went wrong with stopping the controller" >&2 + return 1 + } + elif which killall &>/dev/null; then + # shellcheck disable=SC2015 + killall ziti-controller && { + echo "Controller stopped." + } || { + echo "ERROR: something went wrong with stopping the controller" >&2 + return 1 + } else - echo "ERROR: need controller PID to kill" >&2 + echo "ERROR: need 'pkill' or 'killall' command to kill controller that was not started with startZitiController" >&2 return 1 fi } @@ -86,9 +102,9 @@ function stopZitiController { function startExpressEdgeRouter { 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 & - pid=$! - echo -e "Express Edge Router started as process id: $pid. log located at: $(BLUE "${log_file}")" - ZITI_EXPRESS_EDGE_ROUTER_PID="$pid" + 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 stopAllEdgeRouters { @@ -100,27 +116,25 @@ function stopAllEdgeRouters { echo "ERROR: something went wrong with stopping the router(s)" >&2 return 1 } - else - if which pkill &>/dev/null; then - # shellcheck disable=SC2015 - pkill ziti-router && { - echo "Router(s) stopped." - } || { - echo "ERROR: something went wrong with stopping the router(s)" >&2 - return 1 - } - elif which killall &>/dev/null; then - # shellcheck disable=SC2015 - killall ziti-router && { - echo "Router(s) stopped." - } || { - echo "ERROR: something went wrong with stopping the router(s)" >&2 - return 1 - } - else - echo "ERROR: need 'pkill' or 'killall' command to kill routers that were not started with startExpressEdgeRouter" >&2 + elif which pkill &>/dev/null; then + # shellcheck disable=SC2015 + pkill ziti-router && { + echo "Router(s) stopped." + } || { + echo "ERROR: something went wrong with stopping the router(s)" >&2 return 1 - fi + } + elif which killall &>/dev/null; then + # shellcheck disable=SC2015 + killall ziti-router && { + echo "Router(s) stopped." + } || { + echo "ERROR: something went wrong with stopping the router(s)" >&2 + return 1 + } + else + echo "ERROR: need 'pkill' or 'killall' command to kill routers that were not started with startExpressEdgeRouter" >&2 + return 1 fi } @@ -518,8 +532,7 @@ function ziti_expressConfiguration { createControllerConfig #createControllerSystemdFile initializeController - ZITI_EXPRESS_CONTROLLER_PID=$(startZitiController) - echo "ziti-controller started as process id: $pid. log located at: $(BLUE "${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}.log")" + startZitiController echo "waiting for the controller to come online to allow the edge router to enroll" waitForController From 4453d9288dc9e9a3c1323ed146cb7f7f2696897e Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Mon, 28 Nov 2022 16:56:06 -0500 Subject: [PATCH 07/12] focus the start/stop functions on the expressInstall experience --- quickstart/docker/image/ziti-cli-functions.sh | 40 ++----------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index d9cf83306..f722c01fd 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -77,24 +77,8 @@ function stopZitiController { echo "Controller stopped." return 0 fi - elif which pkill &>/dev/null; then - # shellcheck disable=SC2015 - pkill ziti-controller && { - echo "Controller stopped." - } || { - echo "ERROR: something went wrong with stopping the controller" >&2 - return 1 - } - elif which killall &>/dev/null; then - # shellcheck disable=SC2015 - killall ziti-controller && { - echo "Controller stopped." - } || { - echo "ERROR: something went wrong with stopping the controller" >&2 - return 1 - } else - echo "ERROR: need 'pkill' or 'killall' command to kill controller that was not started with startZitiController" >&2 + echo "ERROR: you can only stop a controller process that was started with startZitiController" >&2 return 1 fi } @@ -116,24 +100,8 @@ function stopAllEdgeRouters { echo "ERROR: something went wrong with stopping the router(s)" >&2 return 1 } - elif which pkill &>/dev/null; then - # shellcheck disable=SC2015 - pkill ziti-router && { - echo "Router(s) stopped." - } || { - echo "ERROR: something went wrong with stopping the router(s)" >&2 - return 1 - } - elif which killall &>/dev/null; then - # shellcheck disable=SC2015 - killall ziti-router && { - echo "Router(s) stopped." - } || { - echo "ERROR: something went wrong with stopping the router(s)" >&2 - return 1 - } else - echo "ERROR: need 'pkill' or 'killall' command to kill routers that were not started with startExpressEdgeRouter" >&2 + echo "ERROR: you can only stop a router process that was started with startExpressEdgeRouter" >&2 return 1 fi } @@ -471,7 +439,7 @@ function ziti_expressConfiguration { # Stop any devices currently running to avoid port collisions stopAllEdgeRouters - stopZitiController "${ZITI_EXPRESS_CONTROLLER_PID}" + stopZitiController else echo -e "$(RED " --- Exiting express install ---")" return 1 @@ -566,7 +534,7 @@ function ziti_expressConfiguration { "${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 "" - [[ -n ${ZITI_EXPRESS_CONTROLLER_PID:-} ]] && stopZitiController "${ZITI_EXPRESS_CONTROLLER_PID}" + stopZitiController echo "Edge Router enrolled. Controller stopped." echo "" From 3394d7f13830684275dbe898563ea813e88e4d28 Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Mon, 28 Nov 2022 17:24:55 -0500 Subject: [PATCH 08/12] fix echo ansi colors --- quickstart/docker/image/ziti-cli-functions.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index f722c01fd..d7b0c7cbf 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -66,7 +66,7 @@ function startZitiController { # 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 "ziti-controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${ZITI_HOME-}/${ZITI_EDGE_CONTROLLER_RAWNAME}.log")" + echo -e "ziti-controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${log_file}")" } function stopZitiController { @@ -1028,13 +1028,13 @@ function ziti_createEnvFile { if [[ "${ZITI_USER-}" == "" ]]; then export ZITI_USER="admin"; fi if [[ "${ZITI_PWD-}" == "" ]]; then ZITI_PWD="$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c32)" - echo -e "Do you want to keep the generated admin password '$ZITI_PWD'? (Y/n)" + echo -en "Do you want to keep the generated admin password '$ZITI_PWD'? (Y/n)" # shellcheck disable=SC2162 - read ZITI_PWD_REPLY - if [[ -z "${ZITI_PWD_REPLY}" || ${ZITI_PWD_REPLY} =~ [yY] ]]; then + read -r pwd_reply + if [[ -z "${pwd_reply}" || ${pwd_reply} =~ [yY] ]]; then echo "INFO: using ZITI_PWD=${ZITI_PWD}" else - echo "Type the preferred admin password and press " + echo -en "Type the preferred admin password and press " read -r ZITI_PWD fi fi From b26cac7f8956a90d80dddaf37937ec3a04d998fe Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 29 Nov 2022 15:31:32 -0500 Subject: [PATCH 09/12] assign ZITI_PWD to known value for tests --- quickstart/docker/image/dockerTestEntrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quickstart/docker/image/dockerTestEntrypoint.sh b/quickstart/docker/image/dockerTestEntrypoint.sh index d11b11f59..abe8610f4 100755 --- a/quickstart/docker/image/dockerTestEntrypoint.sh +++ b/quickstart/docker/image/dockerTestEntrypoint.sh @@ -6,4 +6,6 @@ fi touch runonce source "${ZITI_SCRIPTS}/ziti-cli-functions.sh" +# Set the default password to be a specific value, if not set the password will be a random string and tests will fail +export ZITI_PWD=admin expressInstall "${ZITI_NETWORK}" \ No newline at end of file From ce767e47b326830b9a014c41ed18b69756aed288 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Tue, 29 Nov 2022 19:18:30 -0500 Subject: [PATCH 10/12] Updated Simple Web Service test to use variables for the username and password now that passwords are random Signed-off-by: gberl002 --- quickstart/test/quickstart_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/quickstart/test/quickstart_test.go b/quickstart/test/quickstart_test.go index 05bf77b5b..b92e84e6b 100644 --- a/quickstart/test/quickstart_test.go +++ b/quickstart/test/quickstart_test.go @@ -300,12 +300,15 @@ func TestQuickStartEnvFile(t *testing.T) { } /* -This is a manually run test that will, with the default values, confirm the docker-compose ziti network is running as -expected. The values can be edited to confirm other ziti networks but will require an http server on the back end. +This is a manually run test that will, with the default values except the admin password, confirm the docker-compose +ziti network is running as expected. The values can be edited to confirm other ziti networks but will require an http +server on the back end. */ func TestSimpleWebService(t *testing.T) { // Wait for the controller to become available + zitiAdminUsername := "admin" + zitiAdminPassword := "admin" testerUsername := "gotester" ctrlAddress := "https://ziti-edge-controller:1280" hostingRouterName := "ziti-edge-router" @@ -328,7 +331,7 @@ func TestSimpleWebService(t *testing.T) { for _, ca := range caCerts { caPool.AddCert(ca) } - client, err := rest_util.NewEdgeManagementClientWithUpdb("admin", "admin", ctrlAddress, caPool) + client, err := rest_util.NewEdgeManagementClientWithUpdb(zitiAdminUsername, zitiAdminPassword, ctrlAddress, caPool) if err != nil { log.Fatal(err) } From f4f515c72bcef1b10d029ed2eee4713ed08259f3 Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Thu, 1 Dec 2022 18:24:56 -0500 Subject: [PATCH 11/12] use ZITI_NETWORK and DEFAULT_ZITI_NETWORK instead of ZITI_HOSTNAME --- quickstart/docker/image/ziti-cli-functions.sh | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 63aa782ed..50304fa95 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -2,10 +2,11 @@ set -uo pipefail -ZITI_HOSTNAME="$(hostname -s)" +# 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/${ZITI_HOSTNAME}" +export DEFAULT_ZITI_HOME_LOCATION="${HOME}/.ziti/quickstart/${DEFAULT_ZITI_NETWORK}" export ZITI_QUICKSTART_ENVROOT="${HOME}/.ziti/quickstart" @@ -61,7 +62,7 @@ function initializeController { "${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 startZitiController { +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}" & @@ -69,7 +70,7 @@ function startZitiController { echo -e "ziti-controller started as process id: $ZITI_EXPRESS_CONTROLLER_PID. log located at: $(BLUE "${log_file}")" } -function stopZitiController { +function stopController { if [[ -n ${ZITI_EXPRESS_CONTROLLER_PID:-} ]]; then kill "$ZITI_EXPRESS_CONTROLLER_PID" # shellcheck disable=SC2181 @@ -78,12 +79,12 @@ function stopZitiController { return 0 fi else - echo "ERROR: you can only stop a controller process that was started with startZitiController" >&2 + echo "ERROR: you can only stop a controller process that was started with startController" >&2 return 1 fi } -function startExpressEdgeRouter { +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=$! @@ -91,7 +92,7 @@ function startExpressEdgeRouter { } -function stopAllEdgeRouters { +function stopRouter { if [[ -n ${ZITI_EXPRESS_EDGE_ROUTER_PID:-} ]]; then # shellcheck disable=SC2015 kill "${ZITI_EXPRESS_EDGE_ROUTER_PID}" && { @@ -101,7 +102,7 @@ function stopAllEdgeRouters { return 1 } else - echo "ERROR: you can only stop a router process that was started with startExpressEdgeRouter" >&2 + echo "ERROR: you can only stop a router process that was started with startRouter" >&2 return 1 fi } @@ -373,15 +374,15 @@ function setupZitiNetwork { 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 "${ZITI_HOSTNAME}")" + echo -e "$(BLUE "${DEFAULT_ZITI_NETWORK}")" echo " " - echo -en "$(echo -ne "Network Name [$(BLUE "${ZITI_HOSTNAME}")]: ")" + 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="${ZITI_HOSTNAME}" + ZITI_NETWORK="${DEFAULT_ZITI_NETWORK}" fi echo "name: ${ZITI_NETWORK-}" else @@ -470,8 +471,8 @@ function ziti_expressConfiguration { fi # Stop any devices currently running to avoid port collisions - stopAllEdgeRouters - stopZitiController + stopRouter + stopController else echo -e "$(RED " --- Exiting express install ---")" return 1 @@ -502,7 +503,7 @@ function ziti_expressConfiguration { echo " " echo -e "******** Setting Up Environment ********" if [[ "${1-}" == "" ]]; then - nw="${ZITI_HOSTNAME}" + nw="${DEFAULT_ZITI_NETWORK}" else nw="${1-}" fi @@ -550,7 +551,7 @@ function ziti_expressConfiguration { createControllerConfig #createControllerSystemdFile initializeController - startZitiController + startController echo "waiting for the controller to come online to allow the edge router to enroll" waitForController @@ -584,13 +585,13 @@ function ziti_expressConfiguration { "${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 "" - stopZitiController + 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 "startZitiController")" - echo -e "Start your Ziti Edge Router by running : $(BLUE 'startExpressEdgeRouter')" + echo -e "Start your Ziti Controller by running the function: $(BLUE "startController")" + echo -e "Start your Ziti Edge Router by running : $(BLUE 'startRouter')" echo "" } @@ -787,7 +788,7 @@ function createRouterPki { 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_HOSTNAME}" "${ZITI_CONTROLLER_INTERMEDIATE_NAME}" "${ZITI_EDGE_ROUTER_IP_OVERRIDE-}" "${router_name}" + 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 { @@ -850,7 +851,7 @@ function createPki { pki_create_intermediate "${ZITI_SPURIOUS_INTERMEDIATE}" "${ZITI_SIGNING_INTERMEDIATE_NAME}" 1 echo " " - pki_allow_list_dns="${ZITI_CONTROLLER_HOSTNAME},localhost,${ZITI_HOSTNAME}" + 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" @@ -1034,8 +1035,6 @@ function ziti_createEnvFile { retVal=$? if [[ "${retVal}" != 0 ]]; then if decideToUseDefaultZitiHome; then - # shellcheck disable=SC2155 - export ZITI_NETWORK="${ZITI_HOSTNAME}" ZITI_HOME="${DEFAULT_ZITI_HOME_LOCATION}" else return 1 @@ -1067,9 +1066,9 @@ function ziti_createEnvFile { export ZITI_NETWORK="${1-}" fi if [[ "${ZITI_NETWORK-}" = "" ]]; then - echo -e "$(YELLOW "WARN: ZITI_NETWORK HAS NOT BEEN DECLARED! USING hostname: ${ZITI_HOSTNAME}")" + echo -e "$(YELLOW "WARN: ZITI_NETWORK HAS NOT BEEN DECLARED! USING hostname: ${DEFAULT_ZITI_NETWORK}")" # shellcheck disable=SC2155 - export ZITI_NETWORK="${ZITI_HOSTNAME}" + export ZITI_NETWORK="${DEFAULT_ZITI_NETWORK}" fi fi From 24a855c292bd7df4b079a574c6a4617bba322b5c Mon Sep 17 00:00:00 2001 From: Kenneth Bingham Date: Tue, 6 Dec 2022 19:46:42 -0500 Subject: [PATCH 12/12] unbotch the merge conflict resolution --- quickstart/docker/image/dockerTestEntrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickstart/docker/image/dockerTestEntrypoint.sh b/quickstart/docker/image/dockerTestEntrypoint.sh index 3cffb4e50..0389e148e 100755 --- a/quickstart/docker/image/dockerTestEntrypoint.sh +++ b/quickstart/docker/image/dockerTestEntrypoint.sh @@ -8,4 +8,4 @@ touch runonce source "${ZITI_SCRIPTS}/ziti-cli-functions.sh" # Set the default password to be a specific value, if not set the password will be a random string and tests will fail export ZITI_PWD=admin -expressInstall "${ZITI_NETWORK}" +expressInstall "localhost" \ No newline at end of file