From 238ff34d4763c9677ada1a006fbb9ac049f79570 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Wed, 22 Sep 2021 14:41:19 -0700 Subject: [PATCH 1/2] Look for proxy environment variables in script The install script only looked for proxy environment variables in the VM's environment. Passing these variables via agent args was not supported. Therefore, if a user tried to pass proxy variables via agent args, then the cluster-agent would see them but none of the system-agent commands would. Now, if the user passes these variables via agent args (which are included at the top of the install.sh file), then the install script will see them and include them in the environment file. --- install.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index ae71ed4e..3aae5ca7 100755 --- a/install.sh +++ b/install.sh @@ -627,10 +627,15 @@ ensure_systemd_service_stopped() { create_env_file() { FILE_SA_ENV="/etc/systemd/system/rancher-system-agent.env" info "Creating environment file ${FILE_SA_ENV}" - UMASK=$(umask) - umask 0377 - env | grep -E -i '^(NO|HTTP|HTTPS)_PROXY' | tee ${FILE_SA_ENV} >/dev/null - umask "${UMASK}" + install -m 0600 /dev/null "${FILE_SA_ENV}" + for i in "HTTP_PROXY" "HTTPS_PROXY" "NO_PROXY"; do + eval v=\"\$$i\" + if [ -z "${v}" ]; then + env | grep -E -i "^${i}" | tee -a ${FILE_SA_ENV} >/dev/null + else + echo "$i=$v" | tee -a ${FILE_SA_ENV} >/dev/null + fi + done } do_install() { From 6d7376fecebc83a2752947fe866f10db4bd758a7 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Fri, 24 Sep 2021 13:36:00 -0700 Subject: [PATCH 2/2] Only set environment variables if not already set Currently, the run.sh script will take the environment variables from rancher-system-agent.env, overwriting any variables that are already set. This makes changing any environment variables that are in the env file impossible. After this change, only the variables that are not set in the environment are set from the rancher-system-agent.env file. --- package/suc/run.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package/suc/run.sh b/package/suc/run.sh index 7334de95..6fadcc7c 100755 --- a/package/suc/run.sh +++ b/package/suc/run.sh @@ -36,7 +36,14 @@ fi export CATTLE_AGENT_BINARY_LOCAL=true export CATTLE_AGENT_BINARY_LOCAL_LOCATION=${TMPDIR}/rancher-system-agent if [ -s /host/etc/systemd/system/rancher-system-agent.env ]; then - export $(grep -v '^#' /host/etc/systemd/system/rancher-system-agent.env | xargs) + for line in $(grep -v '^#' /host/etc/systemd/system/rancher-system-agent.env); do + var=${line%%=*} + val=${line##*=} + eval v=\"\$$var\" + if [ -z "$v" ]; then + export "$var=$val" + fi + done fi chroot /host ${TMPDIR}/install.sh "$@"