From d523e1040607cb098d061c008c957c4cc682785c Mon Sep 17 00:00:00 2001 From: Alexander Babai Date: Fri, 2 Aug 2019 17:01:39 +0300 Subject: [PATCH 1/5] refactor(entrypoint): change api use ADDRESSES instead of ADDRESS --- rootfs/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh index 5cc16f8..97d2206 100755 --- a/rootfs/entrypoint.sh +++ b/rootfs/entrypoint.sh @@ -9,7 +9,7 @@ function open_ssh_tunnel { local tunnel_bindings=() local tunnel_urls=() - for address in ${ADDRESS[@]} + for address in ${ADDRESSES[@]} do local remote_hostname=$(echo $address | cut -d ':' -f 1) local tunnel_address=$tunnel_prefix-$remote_hostname:$tunnel_port From 244ef907f80211bcf60c33d145c6c91b2d4a7cd8 Mon Sep 17 00:00:00 2001 From: Alexander Babai Date: Fri, 2 Aug 2019 17:01:58 +0300 Subject: [PATCH 2/5] refactor(docker): improve compose usage example --- docker-compose.example.yml | 3 ++- docker-compose.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 723bd46..2b774a5 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -5,7 +5,8 @@ services: image: alebabai/ssh-proxy:latest build: . environment: - ADDRESS: "nginx:80" + ADDRESSES: |- + nginx:80 volumes: - ./tmp:/tmp/ssh-proxy networks: diff --git a/docker-compose.yml b/docker-compose.yml index 22bfe6f..2f23240 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,8 @@ services: image: alebabai/ssh-proxy:latest build: . environment: - ADDRESS: "localhost:80" + ADDRESSES: |- + localhost:80 volumes: - ./tmp:/tmp/ssh-proxy networks: From e4975135121b122c1e508df69710b36fc0740b4e Mon Sep 17 00:00:00 2001 From: Alexander Babai Date: Fri, 2 Aug 2019 17:51:04 +0300 Subject: [PATCH 3/5] docs(readme): describe all envs --- README.md | 6 +++++- rootfs/entrypoint.sh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3003889..d3c421c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,11 @@ ### Environment variables -- `ADDRESS` - _provide one or more `HOST:PORT` pairs separated by space for services to be exposed_ +- `ADDRESSES` - _provide one or more `HOST:PORT` pairs separated by space for services to be exposed_ +- `OUTPUT_FILE` - _prefix of the exposed url (default `$timestamp`)_ +- `SSH_TUNNEL_HOST` - _host of the service that will be used as ssh-server (default `serveo.net`)_ +- `SSH_TUNNEL_PORT` - _port of the service that will be used as ssh-server (default `443`)_ +- `SSH_TUNNEL_PREFIX` - _name of the file with exposed urls (default `/tmp/ssh-proxy/output.txt`)_ ### Docker diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh index 97d2206..1cc20ca 100755 --- a/rootfs/entrypoint.sh +++ b/rootfs/entrypoint.sh @@ -4,8 +4,8 @@ function open_ssh_tunnel { local timestamp=`date +%s` local tunnel_host=${SSH_TUNNEL_HOST:-"serveo.net"} - local tunnel_prefix=${SSH_TUNNEL_PREFIX:-$timestamp} local tunnel_port=${SSH_TUNNEL_PORT:-"443"} + local tunnel_prefix=${SSH_TUNNEL_PREFIX:-$timestamp} local tunnel_bindings=() local tunnel_urls=() From fdd8245fb4af6e54882e981a1e6c9ab8ff30ccb1 Mon Sep 17 00:00:00 2001 From: Alexander Babai Date: Mon, 12 Aug 2019 17:11:38 +0300 Subject: [PATCH 4/5] refactor(entrypoint): beautify script * create temp dir if not exist * use curly braces for variable substitution --- rootfs/entrypoint.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/rootfs/entrypoint.sh b/rootfs/entrypoint.sh index 1cc20ca..b5c785e 100755 --- a/rootfs/entrypoint.sh +++ b/rootfs/entrypoint.sh @@ -1,31 +1,32 @@ #!/bin/bash function open_ssh_tunnel { - local timestamp=`date +%s` + local timestamp=$(date +%s) local tunnel_host=${SSH_TUNNEL_HOST:-"serveo.net"} local tunnel_port=${SSH_TUNNEL_PORT:-"443"} - local tunnel_prefix=${SSH_TUNNEL_PREFIX:-$timestamp} + local tunnel_prefix=${SSH_TUNNEL_PREFIX:-${timestamp}} local tunnel_bindings=() local tunnel_urls=() for address in ${ADDRESSES[@]} do - local remote_hostname=$(echo $address | cut -d ':' -f 1) - local tunnel_address=$tunnel_prefix-$remote_hostname:$tunnel_port - tunnel_bindings+=("$tunnel_address:$address") - tunnel_urls+=("https://$tunnel_prefix-$remote_hostname.$tunnel_host") + local remote_hostname=$(echo ${address} | cut -d ':' -f 1) + local tunnel_address=${tunnel_prefix}-${remote_hostname}:${tunnel_port} + tunnel_bindings+=("${tunnel_address}:${address}") + tunnel_urls+=("https://${tunnel_prefix}-${remote_hostname}.${tunnel_host}") done - if [ -z "$tunnel_bindings" ]; then + if [ -z "${tunnel_bindings}" ]; then exit 1 else local output_file=${OUTPUT_FILE:-"/tmp/ssh-proxy/output.txt"} - printf "%s\n" ${tunnel_urls[@]} > $output_file + mkdir -p $(dirname ${output_file}) + printf "%s\n" ${tunnel_urls[@]} > ${output_file} - local cmd="ssh -T -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $SSH_ARGS $(printf " -R %s" ${tunnel_bindings[@]}) $tunnel_host" - echo $cmd - exec $cmd + local cmd="ssh -T -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${SSH_ARGS} $(printf " -R %s" ${tunnel_bindings[@]}) ${tunnel_host}" + echo ${cmd} + exec ${cmd} fi } From 9fe8d1cb7aa16899081a830cf03303eadc3e5431 Mon Sep 17 00:00:00 2001 From: Alexander Babai Date: Tue, 13 Aug 2019 15:47:12 +0300 Subject: [PATCH 5/5] docs(readme): updates --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3c421c..d2fa5dc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ### Environment variables -- `ADDRESSES` - _provide one or more `HOST:PORT` pairs separated by space for services to be exposed_ +- `ADDRESSES` - _provide one or more `HOST:PORT` pairs separated by space or new line for services to be exposed_ - `OUTPUT_FILE` - _prefix of the exposed url (default `$timestamp`)_ - `SSH_TUNNEL_HOST` - _host of the service that will be used as ssh-server (default `serveo.net`)_ - `SSH_TUNNEL_PORT` - _port of the service that will be used as ssh-server (default `443`)_