From 713ea286521697c0916d7ef9987618ff7087e3ba Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 9 Nov 2021 14:52:14 -0500 Subject: [PATCH 1/4] updates to express install to make starting the processes more manual for local. add helper functions to make it easier --- quickstart/docker/image/ziti-cli-functions.sh | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 9107dae3c..8584b5401 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -42,7 +42,7 @@ function BLUE { } function zitiLogin { - unused=$("${ZITI_BIN_DIR-}/ziti" edge login "${ZITI_EDGE_CONTROLLER_API}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -c "${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert") + "${ZITI_BIN_DIR-}/ziti" edge login "${ZITI_EDGE_CONTROLLER_API}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -c "${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" > /dev/null } function cleanZitiController { ziti_home="${ZITI_HOME-}" @@ -60,12 +60,20 @@ function initializeController { } function startZitiController { # shellcheck disable=SC2034 - unused=$("${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/controller.yaml" > "${ZITI_HOME_OS_SPECIFIC}/ziti-edge-controller.log" 2>&1 &) - echo -e "ziti-controller started. log located at: $(BLUE "${ZITI_HOME-}/ziti-edge-controller.log")" + ("${ZITI_BIN_DIR-}/ziti-controller" run "${ZITI_HOME_OS_SPECIFIC}/controller.yaml" > "${ZITI_HOME_OS_SPECIFIC}/ziti-edge-controller.log" 2>&1 &) + pid=$! + echo -e "ziti-controller started as process id: $pid. log located at: $(BLUE "${ZITI_HOME-}/ziti-edge-controller.log")" + return $pid } function stopZitiController { killall ziti-controller } +function startExpressEdgeRouter { + "${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" 2>&1 & + pid=$! + echo -e "Express Edge Router started as process id: $pid. log located at: $(BLUE "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log")" + return $pid +} function checkHostsFile { ctrlexists=$(grep -c "${ZITI_CONTROLLER_HOSTNAME}" /etc/hosts) edgectrlexists=$(grep -c "${ZITI_EDGE_CONTROLLER_HOSTNAME}" /etc/hosts) @@ -341,39 +349,50 @@ function ziti_expressConfiguration { createPki createControllerConfig - createControllerSystemdFile + #createControllerSystemdFile initializeController startZitiController - echo "starting the ziti controller to enroll the edge router" + ctrlPid=$? + echo "waiting for the controller to come online to allow the edge router to enroll" waitForController zitiLogin echo -e "---------- Creating an edge router policy allowing all identities to connect to routers with a $(GREEN "#public") attribute" - unused=$("${ZITI_BIN_DIR-}/ziti" edge delete edge-router-policy allEdgeRouters) - unused=$("${ZITI_BIN_DIR-}/ziti" edge create edge-router-policy allEdgeRouters --edge-router-roles '#public' --identity-roles '#all' ) + "${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" - unused=$("${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcPublicRouters) - unused=$("${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcPublicRouters --edge-router-roles '#public' --service-roles '#all') + "${ZITI_BIN_DIR-}/ziti" edge delete service-edge-router-policy allSvcPublicRouters > /dev/null + "${ZITI_BIN_DIR-}/ziti" edge create service-edge-router-policy allSvcPublicRouters --edge-router-roles '#public' --service-roles '#all' > /dev/null createRouterPki createEdgeRouterConfig "${ZITI_EDGE_ROUTER_RAWNAME}" - createRouterSystemdFile "${ZITI_EDGE_ROUTER_RAWNAME}" + #createRouterSystemdFile "${ZITI_EDGE_ROUTER_RAWNAME}" echo "---------- Creating edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." - unused=$("${ZITI_BIN_DIR-}/ziti" edge delete edge-router "${ZITI_EDGE_ROUTER_RAWNAME}") - unused=$("${ZITI_BIN_DIR-}/ziti" edge create edge-router "${ZITI_EDGE_ROUTER_RAWNAME}" -o "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.jwt" -t) + "${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 > /dev/null sleep 1 echo "---------- Enrolling edge-router ${ZITI_EDGE_ROUTER_RAWNAME}...." - unused=$("${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 "" - sleep 1 + #sleep 1 + #routerLog="" # shellcheck disable=SC2034 - unused=$("${ZITI_BIN_DIR-}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" 2>&1 &) + #"${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" 2>&1 & + #routerPid=$! + #echo -e "ziti-router started as process id: $routerPid. log located at: $(BLUE "${routerLog}")" - echo "Express setup complete!" + $(kill $ctrlPid) 2&>1 /dev/null + echo "Edge Router enrolled. Stopping controller using pid: $ctrlPid" + + 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 "" } function decideToUseDefaultZitiHome { From 67dc29d9e61d87fc787fccd81dea4a15661ebb96 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:05:11 -0500 Subject: [PATCH 2/4] tweaks to use killall vs kill by pid --- quickstart/docker/image/ziti-cli-functions.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 8584b5401..4bd91197a 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -352,7 +352,6 @@ function ziti_expressConfiguration { #createControllerSystemdFile initializeController startZitiController - ctrlPid=$? echo "waiting for the controller to come online to allow the edge router to enroll" waitForController @@ -385,8 +384,8 @@ function ziti_expressConfiguration { #routerPid=$! #echo -e "ziti-router started as process id: $routerPid. log located at: $(BLUE "${routerLog}")" - $(kill $ctrlPid) 2&>1 /dev/null - echo "Edge Router enrolled. Stopping controller using pid: $ctrlPid" + killall ziti-controller + echo "Edge Router enrolled. Controller stopped." echo "" echo -e "$(GREEN "Congratulations. Express setup complete!")" From a302c16cd9fcc81374a5b2b74b6cfdebb7298324 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:23:47 -0500 Subject: [PATCH 3/4] remove no longer needed code --- quickstart/docker/image/ziti-cli-functions.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 4bd91197a..1d2ac010d 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -377,12 +377,6 @@ 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 "" - #sleep 1 - #routerLog="" - # shellcheck disable=SC2034 - #"${ZITI_BIN_DIR}/ziti-router" run "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.yaml" > "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log" 2>&1 & - #routerPid=$! - #echo -e "ziti-router started as process id: $routerPid. log located at: $(BLUE "${routerLog}")" killall ziti-controller echo "Edge Router enrolled. Controller stopped." From cbd3f0d1c754c6a988c32c528e8132eb3bcf48a9 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:58:56 -0500 Subject: [PATCH 4/4] allow zitiLogin to show output --- quickstart/docker/image/ziti-cli-functions.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/quickstart/docker/image/ziti-cli-functions.sh b/quickstart/docker/image/ziti-cli-functions.sh index 1d2ac010d..57d1e021d 100755 --- a/quickstart/docker/image/ziti-cli-functions.sh +++ b/quickstart/docker/image/ziti-cli-functions.sh @@ -42,7 +42,7 @@ function BLUE { } function zitiLogin { - "${ZITI_BIN_DIR-}/ziti" edge login "${ZITI_EDGE_CONTROLLER_API}" -u "${ZITI_USER-}" -p "${ZITI_PWD}" -c "${ZITI_PKI_OS_SPECIFIC}/${ZITI_EDGE_CONTROLLER_ROOTCA_NAME}/certs/${ZITI_EDGE_CONTROLLER_INTERMEDIATE_NAME}.cert" > /dev/null + "${ZITI_BIN_DIR-}/ziti" edge login "${ZITI_EDGE_CONTROLLER_API}" -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 { ziti_home="${ZITI_HOME-}" @@ -74,6 +74,9 @@ function startExpressEdgeRouter { echo -e "Express Edge Router started as process id: $pid. log located at: $(BLUE "${ZITI_HOME_OS_SPECIFIC}/${ZITI_EDGE_ROUTER_RAWNAME}.log")" return $pid } +function stopAllEdgeRouters { + killall ziti-router +} function checkHostsFile { ctrlexists=$(grep -c "${ZITI_CONTROLLER_HOSTNAME}" /etc/hosts) edgectrlexists=$(grep -c "${ZITI_EDGE_CONTROLLER_HOSTNAME}" /etc/hosts)