From 789b2218c0f9215217e83b8df05fbb7f5ce1e619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?-=CB=8F=CB=8B=20Maple=20=CB=8A=CB=8E?= <74075397+Kalitsune@users.noreply.github.com> Date: Tue, 28 Mar 2023 17:39:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Improved=20documantation=20and?= =?UTF-8?q?=20added=20a=20new=20argument?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGES: - Renamed `REMOTE_IP` to `GATEWAY_IP` --- Dockerfile | 3 ++- README.md | 25 +++++++++++-------------- examples/docker-compose.yaml | 3 ++- run.sh | 13 +++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1924fa8..bb76253 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,8 @@ ENV SSH_PORT=22 ENV SSH_USER=root ENV CONTAINER_IP=127.0.0.1 ENV CONTAINER_PORT=80 -ENV REMOTE_IP="" +ENV GATEWAY_IP="" +ENV REMOTE_IP="*" ENV REMOTE_PORT=80 # Security fix for CVE-2016-0777 and CVE-2016-0778 diff --git a/README.md b/README.md index 8650348..b283288 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,21 @@ Create a lightweight Alpine Linux based SSH tunnel to a host. Uses pure SSH, no fluff. -For single TCP port applications (database/webserver/debugging access) a SSH tunnel is far faster and simpler than using a VPN like OpenVPN; see this excellent [blog post](https://blog.backslasher.net/ssh-openvpn-tunneling.html) for more info. +**Learn more about ssh tunneling [here](https://iximiuz.com/en/posts/ssh-tunnels/))** -For example I use it to create a SSH tunnel from a GCP Kubernetes cluster into an on prem bastion host in order to talk to an on prem MySQL database; it SSHs onto the internal LAN and connects me to the internal on prem MySQL server. - -Inspired by https://github.com/iadknet/docker-ssh-client-light and [GCP CloudSQL Proxy](https://cloud.google.com/sql/docs/mysql/sql-proxy) - -**FORKED FROM jujhars13/docker-ssh-tunnel/** but reversed the tunnel direction. (more details about tunneling [here](https://iximiuz.com/en/posts/ssh-tunnels/)) +FORKED FROM jujhars13/docker-ssh-tunnel but reversed the tunnel direction. ## Required Parameters -| Variable | Description | Required | -| ------------------ | ----------------------------------------------------------------- | -------- | -| `SSH_PORT` | Port number for SSH (defaults to 22) | No | -| `SSH_USER` | Username for the SSH connection (default: root) | No | -| `CONTAINER_IP` | IP address of the container (default: 127.0.0.1) | No | -| `CONTAINER_PORT` | The port you want to expose on the container (default: 80) | No | -| `REMOTE_IP` | IP/Domain of the machine that will expose your app (the host) | Yes | -| `REMOTE_PORT` | Remote port that will be exposed on the host (default: 80) | No | +| Variable | Description | default | +| ------------------ | ------------------------------------------------------------- | ---------- | +| `SSH_PORT` | Port number for SSH | 22 | +| `SSH_USER` | Username for the SSH connection | root | +| `CONTAINER_IP` | IP address of the container | 127.0.0.1 | +| `CONTAINER_PORT` | The port you want to expose on the container | 80 | +| `GATEWAY_IP` | IP/Domain of the machine that will expose your app (the host) | (required) | +| `REMOTE_PORT` | Which port should sshd listen from on the gateway | 80 | +| `REMOTE_IP` | Which IP should sshd listen from on the gateway (`*` for all) | * | Note: Remember to inject/mount your private SSH key into the container to `/ssh_key/id_rsa`. diff --git a/examples/docker-compose.yaml b/examples/docker-compose.yaml index 5614f98..81437a7 100644 --- a/examples/docker-compose.yaml +++ b/examples/docker-compose.yaml @@ -14,7 +14,8 @@ services: - SSH_USER=proxy - CONTAINER_IP=nginx-hello - CONTAINER_PORT=80 - - REMOTE_IP=openssh-server + - GATEWAY_IP=openssh-server + - REMOTE_IP=* - REMOTE_PORT=8080 nginx-hello: diff --git a/run.sh b/run.sh index e296098..3ac7736 100755 --- a/run.sh +++ b/run.sh @@ -6,22 +6,23 @@ # ENV SSH_USER=root # ENV CONTAINER_IP=127.0.0.1 # ENV CONTAINER_PORT=80 -# ENV REMOTE_IP="" +# ENV GATEWAY_IP="" +# ENV REMOTE_IP="*" # ENV REMOTE_PORT=80 -if [ -z ${REMOTE_IP+x} ] ; then - echo "please specify REMOTE_IP;"; +if [ -z ${GATEWAY_IP+x} ] ; then + echo "please specify GATEWAY_IP;"; exit 1 fi -echo "starting SSH Reverse proxy $CONTAINER_IP:$CONTAINER_PORT -> $REMOTE_IP:$REMOTE_PORT as $SSH_USER@$REMOTE_IP:$SSH_PORT" +echo "starting SSH Reverse proxy $REMOTE_IP:$REMOTE_PORT -> $CONTAINER_IP:$CONTAINER_PORT as $SSH_USER@$GATEWAY_IP:$SSH_PORT" /usr/bin/ssh \ -NTC -o ServerAliveInterval=60 \ -o GatewayPorts=yes \ -o ExitOnForwardFailure=yes \ -o StrictHostKeyChecking=no \ --R *:$REMOTE_PORT:$CONTAINER_IP:$CONTAINER_PORT \ -$SSH_USER@$REMOTE_IP \ +-R $REMOTE_IP:$REMOTE_PORT:$CONTAINER_IP:$CONTAINER_PORT \ +$SSH_USER@$GATEWAY_IP \ -p $SSH_PORT \ -i /ssh_key/id_rsa \ No newline at end of file