Skip to content
Snippets Groups Projects
Commit 5b9343f5 authored by nimrod's avatar nimrod
Browse files

Better VPN detection in smile-exec.

- Fetch the DNS record only once.
- Check that the VPN connection and the requested environment match.
parent 973c7eeb
No related branches found
No related tags found
No related merge requests found
...@@ -19,10 +19,6 @@ vault_addr() { ...@@ -19,10 +19,6 @@ vault_addr() {
esac esac
} }
connected_to_vpn() {
[ "$(dig env.smile.config TXT)" = "$SMILE_ENV" ]
}
aws_account() { aws_account() {
case "$1" in case "$1" in
sandbox-1) echo "696774765305";; sandbox-1) echo "696774765305";;
...@@ -64,8 +60,8 @@ fi ...@@ -64,8 +60,8 @@ fi
if ! echo "$envs" | grep --quiet --fixed-strings --word-regex "$SMILE_ENV" if ! echo "$envs" | grep --quiet --fixed-strings --word-regex "$SMILE_ENV"
then then
echo "Environment $SMILE_ENV is not a valid one." >&2; echo "Environment $SMILE_ENV is not a valid one." >&2
echo "Valid environments are: $envs" echo "Valid environments are: $envs" >&2
exit 1 exit 1
fi fi
...@@ -83,9 +79,19 @@ export VAULT_ADDR="$(vault_addr "$SMILE_ENV")" ...@@ -83,9 +79,19 @@ export VAULT_ADDR="$(vault_addr "$SMILE_ENV")"
VAULT_CAPATH="$(bundle show smile-cli)/lib/vault_ca" VAULT_CAPATH="$(bundle show smile-cli)/lib/vault_ca"
export VAULT_CAPATH export VAULT_CAPATH
if [ -n "$VAULT_ADDR" ] && connected_to_vpn connected_vpn="$(dig env.smile.config TXT | xargs)"
if [ -n "$connected_vpn" ]
then
if [ "$connected_vpn" != "$SMILE_ENV" ]
then
echo 'Connected to a different VPN than the requested environment.' >&2
exit 1
fi
if [ -n "$VAULT_ADDR" ]
then then
aws-vault exec "smile-$SMILE_ENV-admin" -- \ aws-vault exec "smile-$SMILE_ENV-admin" -- \
vault login -method aws -no-print role=smile-ops vault login -method aws -no-print role=smile-ops
fi fi
fi
eval exec aws-vault exec "smile-$SMILE_ENV-admin" -- "$@" eval exec aws-vault exec "smile-$SMILE_ENV-admin" -- "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment