From 12235fe7336e13d2cf661b31bbc4c9eb86d1ed82 Mon Sep 17 00:00:00 2001 From: Josh McSavaney Date: Thu, 25 Jun 2020 20:19:44 -0400 Subject: [PATCH 1/2] Perform basic validation on K3S_URL in install.sh This allows us to fail quickly if we're handed a schemeless or plain HTTP URI, rather than having the agent barf when the systemd unit starts. For an operator, this makes for a cleaner error up front and clear messaging for how to fix the situation. Signed-off-by: Josh McSavaney --- install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install.sh b/install.sh index 46ca3568b7..6b6c664e8d 100755 --- a/install.sh +++ b/install.sh @@ -153,6 +153,9 @@ setup_env() { if [ -z "${K3S_TOKEN}" ] && [ -z "${K3S_CLUSTER_SECRET}" ]; then fatal "Defaulted k3s exec command to 'agent' because K3S_URL is defined, but K3S_TOKEN or K3S_CLUSTER_SECRET is not defined." fi + if ! echo "${K3S_URL}" | grep -q "^https://"; then + fatal "Only https:// URLs are supported for K3S_URL (have ${K3S_URL})" + fi CMD_K3S=agent fi ;; From 9a5b7e2fc43627a09d1d36bd2565dec9319eca52 Mon Sep 17 00:00:00 2001 From: Josh McSavaney Date: Tue, 30 Jun 2020 12:45:01 -0400 Subject: [PATCH 2/2] Pattern match for https check instead of grep Signed-off-by: Josh McSavaney --- install.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 6b6c664e8d..a55539f48c 100755 --- a/install.sh +++ b/install.sh @@ -153,9 +153,14 @@ setup_env() { if [ -z "${K3S_TOKEN}" ] && [ -z "${K3S_CLUSTER_SECRET}" ]; then fatal "Defaulted k3s exec command to 'agent' because K3S_URL is defined, but K3S_TOKEN or K3S_CLUSTER_SECRET is not defined." fi - if ! echo "${K3S_URL}" | grep -q "^https://"; then - fatal "Only https:// URLs are supported for K3S_URL (have ${K3S_URL})" - fi + + case "${K3S_URL}" in + https://*) + ;; + *) + fatal "Only https:// URLs are supported for K3S_URL (have ${K3S_URL})" + ;; + esac CMD_K3S=agent fi ;;