My goal is to use traefik to serve both HTTPS and MQTTS, to have traefik terminate the TLS using letsencrypt certificates. But for this post I have removed as much I could to emphasis the problem I face:
It seems traefik will always fall back to HTTP if it can. Here is the configuration to demonstrate:
Bring it up and then try to connect with a telnet client. Hit enter a few times to provoke traefik:
$ telnet localhost 8883
Trying ::1...
Connected to localhost.
Escape character is '^]'.
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close
400 Bad RequestConnection closed by foreign host.
Yes, it's indeed a bad HTTP request, but I didn't expect it to respond HTTP at all. Remember we haven't instructed traefik anything.
When I put all the pieces back together this unexpected HTTP response confuses my MQTT clients, which is why I would rather have been without this default HTTP stuff.
Can I instruct traefik to not throw my traffic to it's HTTP engine if it not immediately understand the data?
So the endpoint indeed speaks TLS. And the traefik and mosquitto logs reveals activity as well. Of course mosquitto cant make any sense of it.
Now lets try the crazy telnet:
$ telnet mosquitto.example.com 8883
Trying xx.xx.xx.xx...
Connected to mosquitto.example.com.
Escape character is '^]'.
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close
400 Bad RequestConnection closed by foreign host.
OK, so now we are speaking plain HTTP.
Finally lets try the mosquitto_pub client:
$ mosquitto_pub --cafile /etc/ssl/certs/ca-certificates.crt -h mosquitto.example.com -p 8883 -t foo -m bar
Error: A TLS error occurred.
My guess is that mosquitto_pub tries to negotiate the connection and this somehow collides with traefik's attempt to do the same.
Thanks, it has taken me quite a fight to get to this point. I must admit the new v2 configuration is magnitudes harder to me than the old v1.7
With you nodding to the config I dug deeper and with the help of wireshark I inspected TLS headers, comparing between openssl tools and mosquitto_pub I discovered the TLS extension server_name is missing when using mosquitto tools.
A quick search unearth that SNI support has been added just a few years back, and that the versions I run are ancient...
Testing with a modern set of mosquitto tools and it works. BAM!
Now unfortunately many software stacks are bound with the older mosquitto libraries so I will have to leave SNI behind all together.
I have seen others use
HostSNI(`*`)
to make it accept every host (not sure if I got this right)
But I cant figure out how to tell it which certificate to use. How do I specify the host name?
I am fully aware that without SNI I can only serve a specific host name on a specific port, that's ok.
Hmm, that would be very annoying. I will give this thread a few days. If nobody come up with a solution I might make a new thread. Thanks to your help I will now be able to make it much more to the point, even a meaningful subject will be within reach