github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/config/scripts/setup_ssh_tunnel.sh (about) 1 #!/bin/bash 2 3 # 4 # Copyright (c) 2021, 2022, Oracle and/or its affiliates. 5 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 6 # 7 8 if [ -z "TF_VAR_api_private_key_path" ] ; then 9 echo "TF_VAR_api_private_key_path env var must be set!" 10 exit 1 11 fi 12 if [ -z "TF_VAR_compartment_id" ] ; then 13 echo "TF_VAR_compartment_id env var must be set!" 14 exit 1 15 fi 16 if [ -z "TF_VAR_label_prefix" ] ; then 17 echo "TF_VAR_label_prefix env var must be set!" 18 exit 1 19 fi 20 if [ -z "${KUBECONFIG}" ] ; then 21 echo "KUBECONFIG env var must be set!" 22 exit 1 23 fi 24 25 # install sshuttle 26 sudo yum -y install oracle-epel-release-el7 27 sudo yum -y install sshuttle 28 if [ $? -ne 0 ]; then 29 echo "Failed to install sshuttle." 30 exit 1 31 fi 32 33 # find the CIDR for the VPN 34 VCN_CIDR=$(oci network vcn list \ 35 --compartment-id "${TF_VAR_compartment_id}" \ 36 --display-name "${TF_VAR_label_prefix}-oke-vcn" \ 37 --lifecycle-state AVAILABLE \ 38 | jq -r '.data[0]."cidr-block"') 39 40 if [ -z "VCN_CIDR" ]; then 41 echo "Failed to get the CIDR for VCN ${TF_VAR_label_prefix}-oke-vcn" 42 exit 1 43 fi 44 45 # find bastion compute instance id 46 BASTION_ID=$(oci compute instance list \ 47 --compartment-id "${TF_VAR_compartment_id}" \ 48 --display-name "${TF_VAR_label_prefix}-bastion" \ 49 --lifecycle-state RUNNING \ 50 | jq -r '.data[0]."id"') 51 52 if [ -z "$BASTION_ID" ]; then 53 echo "Failed to get the OCID for compute instance ${TF_VAR_label_prefix}-bastion" 54 exit 1 55 fi 56 57 # find public IP for the bastion compute instance 58 BASTION_IP=$(oci compute instance list-vnics \ 59 --compartment-id "${TF_VAR_compartment_id}" \ 60 --instance-id "${BASTION_ID}" \ 61 | jq -r '.data[0]."public-ip"') 62 63 if [ -z "$BASTION_IP" ]; then 64 echo "Failed to get the public IP for compute instance ${TF_VAR_label_prefix}-bastion" 65 exit 1 66 fi 67 68 # run sshuttle 69 sshuttle -r opc@$BASTION_IP $VCN_CIDR --ssh-cmd 'ssh -o StrictHostKeyChecking=no -i '${OPC_USER_KEY_FILE}'' --daemon 70 if [ $? -ne 0 ]; then 71 echo "Failed to ssh tunnel to the bastion host ${TF_VAR_label_prefix}-bastion at ${BASTION_IP}" 72 exit 1 73 fi