go-http-tunnel icon indicating copy to clipboard operation
go-http-tunnel copied to clipboard

[Feature Request] Add ability to Autoasign port in server and API to check available endpoints

Open toni-moreno opened this issue 4 years ago • 1 comments

Use case:

This feature request could be useful on cloud environments, where docker images could be created and ended.

In this context.

Supose you have two docker images starting a tunnel client

client 1

With this config.

server_addr: tunnelserver.myclound.mydomain.com:5223
tunnels:
  webdriver:
    proto: tcp
    addr: localhost:4444
  
  ssh:
    proto: tcp  remote_addr: AUTO
    addr: localhost:22
    remote_addr:  AUTO

(executing and adding an -id option)

./tunnel -id docker_image_1 -config tunnel.yml start-all

client 2

server_addr: tunnelserver.myclound.mydomain.com:5223
tunnels:
  webdriver:
    proto: tcp
    addr: localhost:4444
    remote_addr: AUTO
  ssh:
    proto: tcp
    addr: localhost:22
    remote_addr:  AUTO

(executing and adding an -id option)

./tunnel -id docker_image_2 -config tunnel.yml start-all

Server Side

In the server side once each client is connected , the endpoint should be able to asign as TCP connection endpoint to any free port (from a port range). And add a REST endpoint to check how many connections exist and what IP:PORT shoud use to connect them.

with any HTTP GET client could get this list in json format

curl  -XGET  tunnelserver.myclound.mydomain.com:5223/api/endpoints
{
   [ 
     { "endpoint_id" : "docker_image_1:webdriver" },
     { "endpoint_address":  0.0.0.0:4201}
   ], [ 
     { "endpoint_id" : "docker_image_1:ssh" },
     { "endpoint_address":  0.0.0.0:4202}
   ],[ 
     { "endpoint_id" : "docker_image_2:webdriver" },
     { "endpoint_address":  0.0.0.0:4203 }
   ],[ 
     { "endpoint_id" : "docker_image_1:ssh" },
     { "endpoint_address":  0.0.0.0:4204 }
   ]
}

With this new feature any ssh/webdriver/XXXX client could connect to any image thougth tunnel server without any client specific config

toni-moreno avatar Feb 25 '20 15:02 toni-moreno

Hello! ,to everybody.

I'm proud to announce a first release working as described before. Here: https://github.com/datadope-io/go-http-tunnel/tree/added_port_auto_assignation

Only tested with tcp connections, this branch is functional to me (working only with tcp ) , but not sure if working with http/sni protocol types.( not tested)

Client/Server Config

I've configured 2 clients on the same host.

client 1

tunnel -id probe-xxx -config ./client1_cfg/tunnel.yml start-all

server_addr: localhost:5223
tunnels:
  webdriver:
    proto: tcp
    addr: localhost:4444
    remote_addr: 0.0.0.0:AUTO
  git:
    proto: tcp
    addr: localhost:3000
    remote_addr: 0.0.0.0:AUTO

client 2

tunnel -id probe-yyy -config client2_cfg/tunnel.yml start-all

server_addr: localhost:5223
tunnels:
  webdriver:
    proto: tcp
    addr: localhost:4444
    remote_addr: 0.0.0.0:AUTO
  git:
    proto: tcp
    addr: localhost:3000
    remote_addr: 0.0.0.0:3010

server

tunneld -tlsCrt ./server_cfg/server.crt -tlsKey ./server_cfg/server.key -httpsAddr -httpAddr -tunnelAddr localhost:5223 -portRange 6010:6050 -apiAddr :8080

Result

$ curl localhost:8080/api/clients/list | jq
[
  {
    "Name": "probe-yyy",
    "Source": "127.0.0.1:42958",
    "Ports": [
      {
        "Name": "git",
        "LocalAddr": "[::]:3010"
      },
      {
        "Name": "webdriver",
        "LocalAddr": "[::]:6010"
      }
    ]
  },
  {
    "Name": "probe-xxx",
    "Source": "127.0.0.1:42964",
    "Ports": [
      {
        "Name": "git",
        "LocalAddr": "[::]:6011"
      },
      {
        "Name": "webdriver",
        "LocalAddr": "[::]:6012"
      }
    ]
  }
]

toni-moreno avatar Apr 11 '20 07:04 toni-moreno