Updated randomized ssm tunnel port
This commit is contained in:
@ -21,10 +21,11 @@ function ssm_tunnel --description 'access private AWS ressources via Bastion Hos
|
|||||||
|
|
||||||
# Ports to bind for forwarding
|
# Ports to bind for forwarding
|
||||||
set LOCAL_PORT $argv[2]
|
set LOCAL_PORT $argv[2]
|
||||||
|
set REM_PORT (math (random) % 65535 + 2000)
|
||||||
|
|
||||||
# make sure jq is installed
|
# make sure jq is installed
|
||||||
# Start socat on the remote server
|
# Start socat on the remote server
|
||||||
set CMD "'sudo socat TCP4-LISTEN:$LOCAL_PORT,fork TCP4:$REMOTE_HOST'"
|
set CMD "'sudo socat TCP4-LISTEN:$REM_PORT,fork TCP4:$REMOTE_HOST'"
|
||||||
set CMD_INVOC_ID (aws ssm send-command --instance-ids $INSTANCE_ID \
|
set CMD_INVOC_ID (aws ssm send-command --instance-ids $INSTANCE_ID \
|
||||||
--document-name 'AWS-RunShellScript' \
|
--document-name 'AWS-RunShellScript' \
|
||||||
--parameters commands=$CMD --output json | jq -r '.Command.CommandId')
|
--parameters commands=$CMD --output json | jq -r '.Command.CommandId')
|
||||||
@ -33,7 +34,7 @@ function ssm_tunnel --description 'access private AWS ressources via Bastion Hos
|
|||||||
echo "Starting Tunnel"
|
echo "Starting Tunnel"
|
||||||
aws ssm start-session --target $INSTANCE_ID \
|
aws ssm start-session --target $INSTANCE_ID \
|
||||||
--document-name "AWS-StartPortForwardingSession" \
|
--document-name "AWS-StartPortForwardingSession" \
|
||||||
--parameters "portNumber=$LOCAL_PORT,localPortNumber=$LOCAL_PORT"
|
--parameters "portNumber=$REM_PORT,localPortNumber=$LOCAL_PORT"
|
||||||
|
|
||||||
# stop socat on the bastion
|
# stop socat on the bastion
|
||||||
aws ssm cancel-command --command-id $CMD_INVOC_ID
|
aws ssm cancel-command --command-id $CMD_INVOC_ID
|
||||||
|
|||||||
Reference in New Issue
Block a user