Skip to content

Commit

Permalink
allow-multiple-concurrent-bosh-logins
Browse files Browse the repository at this point in the history
  • Loading branch information
jackjoy-gds committed Jan 9, 2024
1 parent 3862c4b commit 26c141a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/bosh-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ if [[ ! -d "${bosh_config_dir}" ]]; then
exit 1
fi

tunnel_mux='/tmp/bosh-ssh-tunnel.mux'
tunnel_mux=$(mktemp --dry-run /tmp/bosh-ssh-tunnel.mux.XXXXXXXX)

socks_port=25555
while nc -z localhost $socks_port >/dev/null 2>&1; do
socks_port=$(( socks_port + 1 ))
done

function cleanup() {
echo 'Closing SSH tunnel'
ssh -S "$tunnel_mux" -O exit a-destination &>/dev/null || true

# Avoid keeping sensitive tokens in bosh config when we don't need them.
# This will mean we have to sign in to bosh every time we run this script.
echo 'Cleaning up BOSH config'
Expand All @@ -31,7 +35,7 @@ echo 'Getting BOSH settings'
BOSH_CA_CERT="$(aws s3 cp "s3://gds-paas-${DEPLOY_ENV}-state/bosh-CA.crt" -)"

echo 'Opening SSH tunnel'
ssh -qfNC -4 -D 25555 \
ssh -qfNC -4 -D $socks_port \
-o Hostname="bosh-external.${SYSTEM_DNS_ZONE_NAME}" \
-o ExitOnForwardFailure=yes \
-o StrictHostKeyChecking=no \
Expand All @@ -42,7 +46,7 @@ ssh -qfNC -4 -D 25555 \
paas_bosh_ssh

export BOSH_CA_CERT
export BOSH_ALL_PROXY="socks5://localhost:25555"
export BOSH_ALL_PROXY="socks5://localhost:$socks_port"
export BOSH_ENVIRONMENT="bosh.${SYSTEM_DNS_ZONE_NAME}"
export BOSH_DEPLOYMENT="${DEPLOY_ENV}"
export BOSH_CONFIG="${bosh_config_dir}/config"
Expand Down

0 comments on commit 26c141a

Please sign in to comment.