[GH-ISSUE #112] [Feature Request] Add ability to Autoasign port in server and API to check available endpoints #61

Open
opened 2026-05-05 10:59:17 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @toni-moreno on GitHub (Feb 25, 2020).
Original GitHub issue: https://github.com/mmatczuk/go-http-tunnel/issues/112

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

Originally created by @toni-moreno on GitHub (Feb 25, 2020). Original GitHub issue: https://github.com/mmatczuk/go-http-tunnel/issues/112 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. ```yml 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) ```bash ./tunnel -id docker_image_1 -config tunnel.yml start-all ``` ## client 2 ```yml 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) ```bash ./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 ``` bash 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
Author
Owner

@toni-moreno commented on GitHub (Apr 11, 2020):

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"
      }
    ]
  }
]
<!-- gh-comment-id:612350425 --> @toni-moreno commented on GitHub (Apr 11, 2020): 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` ```yml 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` ```yaml 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 ```bash $ 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" } ] } ] ```
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/go-http-tunnel#61
No description provided.