I have an older application that has no TLS support that needs to make TLS TCP connections to a certain IP. I was hoping to use Traefik v2 for this. Can Traefik listen for TCP connections that don't use TLS, and then make a TLS connection to a backend service? Here's how I was envisioning the configuration:
[tcp]
[tcp.routers]
[tcp.routers.FrontendTCPRouter]
entryPoints = ["EntryPoint0"]
# Catch every request (only available rule for non-tls routers. See below.)
rule = "HostSNI(`*`)"
service = "BackendTCPService"
[tcp.services]
[tcp.services.BackendTCPService.loadBalancer]
[[tcp.services.BackendTCPService.loadBalancer.servers]]
address = "localhost:8050"
tls = true
I ended up not using Traefik to solve this. I used Stunnel. It's not Dockerized and the documentation is a little clunky, but I got it working. https://www.stunnel.org
I managed to achieve this. My goal was to placing mqtt broker (rabbitmq) behind traefik, so that for single container I am exposing 3 endpoints https for management, mqtt for unencrypted TCP traffic and mqtts for encrypted TCP traffic.
Ok, that's interesting: when using the wildcard '*' it works just fine with no TLS options at all, but when using an explicit HostSNI Traefik complains about the lack of TLS option. For instance (using file provider):
The above just works and Traefik's monitor dashboard correctly states the first route (system-db) has TLS enabled while the second (gnucash-db) is non-TLS. However, if I change the second to use "HostSNI(gnucash-db.example.com)", instead of the wildcard, I get the following error:
invalid rule: "HostSNI(gnucash-db.example.com)" , has HostSNI matcher, but no TLS on router
Ah ok! I completely missed the fact that SNI is an extension of TLS!
In the docs, there even is a specific note about that:
It is important to note that the Server Name Indication is an extension of the TLS protocol.
Hence, only TLS routers will be able to specify a domain name with that rule. However, there
is one special use case for HostSNI with non-TLS routers: when one wants a non-TLS router
that matches all (non-TLS) requests, one should use the specific HostSNI(*) syntax.