markpash / tailscale-sidecar

A TCP proxy used to expose services onto a tailscale network without root. Ideal for container environments.
MIT License
137 stars 10 forks source link

Investigate TCP proxy from non-tailnet to tailnet #6

Open markpash opened 2 years ago

markpash commented 2 years ago

A little while ago, the tsnet package incorporated the ability to Dial into the tailnet. This unlocks a whole new set of features to be implemented.

One of these features is the ability to listen on non-tailnet interfaces/addresses and proxy all accepted connections to an address:port on the tailnet.

I'm not sure how I would implement this in our bindings structure, so I'm thinking I'll have to redo the structure of the configuration file.

4310V343k commented 1 year ago

This would be very useful for me! I don't see a need to change the binding structure, because nothing really changes. Sidecar still binds ONE port to ONE port We simply need to check if the destination is on the tailscale network. Or use a prefix like ts://db:3306

If it is (or there is a prefix), it's a connection from anything outside to a machine on the network, else the behavior stays as it is now

4310V343k commented 1 year ago

I forgot to tell you that in the end I came up with this: https://github.com/4310V343k/tailscale-sidecar/commit/4945b1a7e77e1970531650becae075d18e953506 This is my first time using go so i just made a working poc version. The functions are nearly the same so there is a clear way to shorten up the code, but it works!