(feat) Update dotfile scripts & tooling

- Update & split scripts
- Main package install script
- Fish / environment install script
- Dockerfile for testing locally
This commit is contained in:
2023-10-31 17:19:40 +01:00
parent 66fbc7eeab
commit 0456dba5d1
13 changed files with 203 additions and 104 deletions

View File

@ -0,0 +1,4 @@
# Defined in - @ line 1
function cdk --wraps='npx aws-cdk@2.x' --description 'alias cdk=npx aws-cdk@2.x'
npx aws-cdk@2.x $argv;
end

View File

@ -0,0 +1,12 @@
# Place this in your Fish functions folder to make it available immediately
# e.g. ~/.config/fish/functions/envsource.fish
#
# Usage: envsource <path/to/env>
function envsource
for line in (cat $argv | grep -v '^#')
set item (string split -m 1 '=' $line)
set -gx $item[1] $item[2]
echo "Exported key $item[1]"
end
end

View File

@ -18,7 +18,7 @@ function ssm_tunnel --description 'Access private AWS ressources via native SSM
--query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]"\
--output text)
# AWS Remote host i.e internal.s.twaice / dualstack.internal-stg-s-inter-9ov8h1o4saoa-793915940.eu-west-1.elb.amazonaws.com
# AWS Remote host i.e AWS Remote host i.e internal.x.yourdns / xxx.eu-west-1.elb.amazonaws.com
set REMOTE_HOST (string split -f1 : $argv[1])
set REMOTE_PORT (string split -f2 : $argv[1])
# Local port to bind for forwarding
@ -36,9 +36,8 @@ function ssm_tunnel --description 'Access private AWS ressources via native SSM
echo "Tunneling Session Exited."
end
# This function is for Platform Admin / Infrastructure users only.
# @TODO: It still utilized the old style of ssm tunneling -> needs c&p of new style as well
function ssm_tunnel_admin --description 'access private AWS ressources via Bastion Host'
# This function is for custom & higher privileged users only.
function ssm_tunnel_admin --description 'Access private AWS ressources via native SSM port forwarding through bastion'
if test (count $argv) -lt 2
echo "Provide an Host:Port Mapping & an Local Port"
@ -55,29 +54,21 @@ function ssm_tunnel_admin --description 'access private AWS ressources via Basti
--filter 'Name=tag:Name,Values=INSTANCE_NAME_HERE'\
--query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]"\
--output text)
# AWS Remote host i.e elastic.aws.com:80
set REMOTE_HOST $argv[1]
# Ports to bind for forwarding
# AWS Remote host i.e internal.x.yourdns / xxx.eu-west-1.elb.amazonaws.com
set REMOTE_HOST (string split -f1 : $argv[1])
set REMOTE_PORT (string split -f2 : $argv[1])
# Local port to bind for forwarding
set LOCAL_PORT $argv[2]
set REM_PORT (math (random) % 65535 + 2000)
set TIMEOUT 21600 #seconds until forwarding session times out (48h max)
# make sure jq is installed
# Start socat on the remote server
set CMD "'sudo socat TCP4-LISTEN:$REM_PORT,reuseaddr,fork TCP4:$REMOTE_HOST'"
set CMD_INVOC_ID (aws ssm send-command --instance-ids $INSTANCE_ID \
--document-name 'AWS-RunShellScript' \
--parameters "commands=$CMD,executionTimeout=$TIMEOUT" --output json | jq -r '.Command.CommandId')
# Seconds until forwarding session times out (6h max)
set TIMEOUT 21600
# Start tunnel session
echo "Starting Tunnel"
aws ssm start-session --target $INSTANCE_ID \
--document-name "AWS-StartPortForwardingSession" \
--parameters "portNumber=$REM_PORT,localPortNumber=$LOCAL_PORT"
--document-name "AWS-StartPortForwardingSessionToRemoteHost" \
--parameters "host=[$REMOTE_HOST],portNumber=[$REMOTE_PORT],localPortNumber=[$LOCAL_PORT]"
# stop socat on the bastion
aws ssm cancel-command --command-id $CMD_INVOC_ID
echo "Command Cancelled Successfully."
echo "Tunneling Session Exited."
end