Live data from Hacker News

Secure your MQTT server with authentication and encryption

jurian.slui.mn

11–20 of 30 posts

Re: Secure your MQTT server with authentication and encryption

#11
You lucky guys with IP stacks and TLS! I had to secure an IoT MQTT install where the packets themselves needed encryption which meant hamfisting in an encapsulated packet scheme (plain text header, end to end encrypted payloads). Kinda painful and I would not do that again!

Re: Secure your MQTT server with authentication and encryption

#14
post #3

This is a good tutorial to get the server side of things secured. I didn't know you could use Traefik to proxy the MQTT connections as well which looks quite useful. The biggest issue I have is with the client side and its various support of TLS and getting a trusted CA certificate distributed. This is the harder part of the equation in my opinion, support is getting better with firmwares like Tasmota but getting som…

You're totally right. Although in my experience this is much easier to maintain with "upstream root certificates" (not sure how you'd call them) then self-signed certs. Applications like Home Assistant are already TLS aware and simply trust all root certs which are available on the host. With self signed certs, you have to distribute them all by yourself.

Besides this trade-off, you have to check all clients to be TLS aware on beforehand. In my setup, all clients were capable of TLS. The only hassle are my NodeMCU devices which need to swap the WifiClient to a WifiSSLClient and you need to embed the public DST Root CA X3 yourselves.

Re: Secure your MQTT server with authentication and encryption

#15

Could we MQTT in regular applications as well? or just in IOT?

(Author here)

I run it to communicate with much more applications. It just depends on your own preferences. For example, some tools provide an API (local or cloud based) and you can directly plug in into that API. In The Netherlands you can read your electricity meter yourself by a "Dutch Smart Meter Readings" and DSMR integrates into Home Assistant with MQTT. I use Z-Wave as wireless mesh technology for lights and switches, the Z-Wave controller integrates into Home Assistant with MQTT.

MQTT is so easy to setup and configure, you can use it for any messaging you want. As an example, I run Home Assistant locally to run my home automations, but also check the status of my local devices and online servers (Digital Ocean droplets). One use case is my backup script which publishes the backup results to an online MQTT server, my Home Assistant checks the topics at that server to display backup stats locally. If something went wrong, Home Assistant notifies my directly. PS. The backup script also sends out e-mails which I filter in Fastmail, the success mails are trashed and only error messages are kept in the inbox ;)

Re: Secure your MQTT server with authentication and encryption

#16

Could we MQTT in regular applications as well? or just in IOT?

In my experience MQTT works well for telemetry and one-way messaging, but it's not good at doing request-response flow like you typically do in an application using HTTP. You can certainly come up with a mechanism for doing that, but you're having to re-invent a lot of what HTTP already solves.

Re: Secure your MQTT server with authentication and encryption

#17
My approach with a recent personal project (i.e. no actual scaling required) was to have the MQTT server just listen on localhost. Application connects without TLS on the loopback interface. Clients connect over WebSocket (TLS) using their existing OAuth access token as the username and "x" as the password. The application involves an API as well so client credentials are already in use.

I used jpmens/mosquitto-auth-plug https://github.com/jpmens/mosquitto-auth-plug> for the Mosquitto side of things, with a query along the lines of:

  SELECT "hardcoded password hash" FROM oauth_access_tokens WHERE access_token = "%s" AND scope REGEXP "\bmqtt\b";

Re: Secure your MQTT server with authentication and encryption

#18
post #2

I found it to be much easier to put haproxy in TCP mode in front of mosquitto than to use mosquitto's TLS capabilities. This lets me reload the certificate without restarting mosquitto. My local devices (esp8266) can't really handle TLS well, but I want access from outside of my local network to be encrypted. This lets them operate in plain-text mode locally, with firewall rules forcing outside access to be secure.

Mosquitto 2 supports reloading the TLS cert without restarting. Send SIGHUP to reload certs.

Re: Secure your MQTT server with authentication and encryption

#19

You lucky guys with IP stacks and TLS! I had to secure an IoT MQTT install where the packets themselves needed encryption which meant hamfisting in an encapsulated packet scheme (plain text header, end to end encrypted payloads). Kinda painful and I would not do that again!

It really seems like you could squeeze IP and thus (D)TLS in there instead, definitely something to eye up if ever you do have to do this again.

For TLS you can use pre-shared key mode so there's no extra gubbins like certificates, but you get all the same guarantees about whether what you're doing is actually safe as the big guys.

Re: Secure your MQTT server with authentication and encryption

#20
post #2

I found it to be much easier to put haproxy in TCP mode in front of mosquitto than to use mosquitto's TLS capabilities. This lets me reload the certificate without restarting mosquitto. My local devices (esp8266) can't really handle TLS well, but I want access from outside of my local network to be encrypted. This lets them operate in plain-text mode locally, with firewall rules forcing outside access to be secure.

Mosquitto 2 supports reloading the TLS cert without restarting. Send SIGHUP to reload certs.

This is also good to know. Thanks, I was unaware that 2.0.x had been released!
Post reply on HN