Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic TCP proxying support #179

Closed
magiconair opened this issue Oct 12, 2016 · 23 comments
Closed

Add generic TCP proxying support #179

magiconair opened this issue Oct 12, 2016 · 23 comments
Milestone

Comments

@magiconair
Copy link
Contributor

This issue tracks the request from #1 to add support for generic TCP proxying support in fabio.

So far fabio supports the TCP+SNI proxy for full-end-to-end encryption but not any dynamic listeners, i.e. you cannot route MySQL traffic through fabio yet.

@nugend
Copy link

nugend commented Oct 12, 2016

@magiconair subbed, thanks.

@jbye
Copy link

jbye commented Oct 31, 2016

Subbed.
My use case is that I would like to use Fabio to load balance Thrift-based microservices that are registered in Consul.

@magiconair
Copy link
Contributor Author

@jbye why not use the consul service discovery instead? Then you don't need fabio for this. That's what we're doing.

@panga
Copy link

panga commented Dec 5, 2016

+1

@magiconair I'm using Fabio to route Docker based microservices, so it binds to random ports on host.
I would like use Fabio to route TCP based traffic through a fixed port...

@tkald
Copy link

tkald commented Jan 24, 2017

+1
I'd like to balance imap / smtp traffic

Proxy protocol support to tcp would be also awsome :)

@shantanugadgil
Copy link
Contributor

My use case is:

  • non HTTPS services; launched using Nomad and registered into Consul.
    I wanted to use Fabio to discover a named service within Consul; say "myservice" and then roundrobin between the registered backends (IP:PORT) for that single service.

*** The backend port could vary as I am using Docker with Nomad's ephemeral port logic.

Thanks and Regards,
Shantanu

@magiconair
Copy link
Contributor Author

@shantanugadgil myservice would be a non-HTTP and non-HTTPS service, right?

@shantanugadgil
Copy link
Contributor

@magiconair yes, that's correct, "myservice" would be custom app.

@magiconair magiconair added this to the 1.4 milestone Feb 21, 2017
magiconair added a commit that referenced this issue Feb 22, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCPSNI
  proxy.
* Add integration tests for the TCP and TCPSNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
magiconair added a commit that referenced this issue Feb 22, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
magiconair added a commit that referenced this issue Feb 22, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
@magiconair
Copy link
Contributor Author

The release-branch-1.4 contains a working implementation of a generic TCP proxy. It should also support TLS on the inbound socket but I haven't tested that yet. This should work by setting a certificate source with cs=name. I need to polish and document some more code but would appreciate some early feedback whether this is working in general.

The following command will start TCP proxy on port 1234 in fabio and route requests to all servers which have registered with tag urlprefix-:1234 proto=tcp

./fabio -proxy.addr ':1234;proto=tcp'

The demo/server has been updated to provide a simple TCP echo server.

cd demo/server
go build
./server -addr 127.0.0.1:5000 -proto tcp -prefix :1234 &
./server -addr 127.0.0.1:5001 -proto tcp -prefix :1234 &
...

nc 127.0.0.1 1234
Hello
[127.0.0.1:5001] Hello
^C

You can also register multiple tags to map several inbound ports to one service. You can try this with

./server -addr 127.0.0.1:5000 -proto tcp -prefix :1234,:5678

Please note however, that fabio needs to have all listening ports configured upfront. That is something that I'd like to change in a subsequent change.

One side effect which I'd like to clean up before merging is that the route commands still contain URLs as target addresses, e.g.

+ route add server :1234 http://127.0.0.1:5001/ tags "urlprefix-:1234 proto=tcp" opts "proto=tcp"
+ route add server :1234 http://127.0.0.1:5000/ tags "urlprefix-:1234 proto=tcp" opts "proto=tcp"

Feedback is very welcome!

@magiconair
Copy link
Contributor Author

One note: The release-branch-1.4 requires Go 1.8

magiconair added a commit that referenced this issue Feb 23, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
magiconair added a commit that referenced this issue Feb 23, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
magiconair added a commit that referenced this issue Feb 23, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
magiconair added a commit that referenced this issue Feb 23, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
@ptariche
Copy link

👍

@nugend
Copy link

nugend commented Feb 24, 2017

I'd like to test, but I'd have to spend some time figuring out how to install go in a custom root.

@magiconair
Copy link
Contributor Author

magiconair commented Feb 24, 2017 via email

@nugend
Copy link

nugend commented Feb 26, 2017

Yes. Thank you.

@magiconair
Copy link
Contributor Author

@nugend
Copy link

nugend commented Feb 27, 2017

Will test it out first thing tomorrow! Thanks!

@panga
Copy link

panga commented Mar 20, 2017

@magiconair,

I've tested the new TCP proxy settings, it works like I expected!

Just a few questions:

  1. Do you plan to add support for dynamic listening ports?
  2. When do you plan to release 1.4 branch?

Thank you!!

@magiconair
Copy link
Contributor Author

@panga That's good to know. Thanks for testing this. To your questions:

  1. dynamic listening ports: yes, but that requires some more refactoring since I need to shut them down as well.
  2. I'd like to spend some more thought on how the tcp proxy support is expressed in the config language. Right now the upstream server is still referred to via http:// which is wrong. I'd also like to get an idea on the state of the TLS support. Other than that, I don't foresee any other major changes for the 1.4 branch. I'll try to find some time to clean this up this week and aim for a release next week.

@magiconair
Copy link
Contributor Author

@nugend did you also get a chance to test the tcp proxy in 1.4beta1?

@nugend
Copy link

nugend commented Mar 21, 2017

Yes! Sorry for the delay. Seems to work great! We'll probably try using it for inbound client connections when we have some time on our schedule.

magiconair added a commit that referenced this issue Mar 22, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
magiconair added a commit that referenced this issue Mar 22, 2017
Changes for 1.4beta2

* Advertise routes with 'tcp://' URL
* Update integration test for 'tcp://' URLs
* Filter urlprefix- tags from generated route commands
* Allow demo server to register additional tags
* Update UI to show TCP and HTTP routes correctly
* Update UI to limit weights to two decimal points
magiconair added a commit that referenced this issue Mar 22, 2017
Changes for 1.4beta2

* Advertise routes with 'tcp://' URL
* Update integration test for 'tcp://' URLs
* Filter urlprefix- tags from generated route commands
* Allow demo server to register additional tags
* Update UI to show TCP and HTTP routes correctly
* Update UI to limit weights to two decimal points
magiconair added a commit that referenced this issue Mar 23, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #178, #179
magiconair added a commit that referenced this issue Mar 23, 2017
Changes for 1.4beta2

* Advertise routes with 'tcp://' URL
* Update integration test for 'tcp://' URLs
* Filter urlprefix- tags from generated route commands
* Allow demo server to register additional tags
* Update UI to show TCP and HTTP routes correctly
* Update UI to limit weights to two decimal points
magiconair added a commit that referenced this issue Mar 23, 2017
Changes for 1.4rc1

* Add test for TLS TCP proxy
* Move TLSConfig creation out of the listener code and into main
@magiconair
Copy link
Contributor Author

magiconair commented Mar 23, 2017

I've added a test which verifies that TLS termination works on the TCP proxy. This now allows the following options:

  • Proxy a raw TCP connection based on ports
  • Proxy a TLS encrypted TCP connection without decryption based on SNI server name
  • Proxy a TLS encrypted TCP connection and terminate TLS on fabio

I've rebased the release-branch-v1.4 which means I had to re-roll the 1.4beta1 build. Probably, shouldn't have merged the small changes into master in the first place.

In any case, I've tagged and pushed v1.4rc1 which will become v1.4 unless someone finds a bug.

P.S.: They're also on docker hub.

magiconair added a commit that referenced this issue Mar 25, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes #1, #178, #179
magiconair added a commit that referenced this issue Mar 25, 2017
Changes for 1.4beta2

* Advertise routes with 'tcp://' URL
* Update integration test for 'tcp://' URLs
* Filter urlprefix- tags from generated route commands
* Allow demo server to register additional tags
* Update UI to show TCP and HTTP routes correctly
* Update UI to limit weights to two decimal points
magiconair added a commit that referenced this issue Mar 25, 2017
Changes for 1.4rc1

* Add test for TLS TCP proxy
* Move TLSConfig creation out of the listener code and into main
@magiconair
Copy link
Contributor Author

merged to master

raben2 pushed a commit to raben2/fabio that referenced this issue Mar 29, 2017
* Add generic TCP proxy support.
* Add support for ReadTimeout and WriteTimeout for the TCP and the TCP+SNI
  proxy.
* Add integration tests for the TCP and TCP+SNI proxy.
* Update the demo server to provide a TCP server.
* Add a tcptest package for generic TCP server testing.

Fixes fabiolb#1, fabiolb#178, fabiolb#179
raben2 pushed a commit to raben2/fabio that referenced this issue Mar 29, 2017
Changes for 1.4beta2

* Advertise routes with 'tcp://' URL
* Update integration test for 'tcp://' URLs
* Filter urlprefix- tags from generated route commands
* Allow demo server to register additional tags
* Update UI to show TCP and HTTP routes correctly
* Update UI to limit weights to two decimal points
raben2 pushed a commit to raben2/fabio that referenced this issue Mar 29, 2017
Changes for 1.4rc1

* Add test for TLS TCP proxy
* Move TLSConfig creation out of the listener code and into main
@rodrigoraval
Copy link

Guys,

I am facing some issue close to this one, could you please help me on that?

#266

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants