MQTT Authentication
Intra-Cluster Communication
The above image shows how intra-cluster communication takes place. Nodes send application status and node health reports to the cluster-service-manager. The cluster-service-manager then appropriately propagates this information to other nodes and the root-service-manager. Since the nodes report sensitive information, such as IP Addresses, we highly recommend securing the MQTT channels.
MQTT
MQTT is a lightweight messaging protocol that supports publishing/subscribing to named channels. Oakestra uses MQTT due to its minimal network usage and low processing overhead. More information at mqtt.org.
MQTTS
MQTT supports exchanging certificates to establish a TLS-secured channel. For this, the server (MQTT Broker) and every client require a certificate-key file pair signed against the same certificate Authority (CA). The MQTT broker can be configured to only accept incoming secured connections and to identify devices by their certificate common name (CN) entry. MQTT supports the exchanging of certificates to establish a TLS secured channel. For this the server (MQTT Broker) and every client require a certificate-keyfile pair singed against the same certificate Authority (CA). The MQTT broker can be configured to only accept incoming secured connection, and to identify devices by their certificate common name (CN) entry.
Enable Mosquitto Authentication
Requirements
- You have a running Oakestra deployment
- You have at least one worker node registered
- (Optional) The NetManager is installed and properly configured
Getting Started Guide
Check out the Getting Started guide to set up your first cluster
Configuring the Cluster Manager
Navigate into the cluster_orchestrator
directory in the oakestra repository.
Configure the MQTT Broker by adding the following lines to the
mosquitto/mosquitto.conf
file:Generate the certificates in the
./certs
directory- MQTTS (Server):
- Generate CA authority key:
- Generate a server key:
- Generate a certificate signing request including the URL as a SAN:When prompted for the CN, enter
mqtts
- Send the CSR to the CA:
- Grant permissions to read the server keyfile:
- Cluster Manager (Client):
- Generate a client key:
- Generate a certificate signing request:When prompted for the CN, enter
cluster_manager
- Send the CSR to the CA:
- Export the keyfile password as an environment variable:
- Cluster Service Manager (Client):
- Generate a client key:
- Generate a certificate signing request:When prompted for the CN, enter
cluster_service_manager
- Send the CSR to the CA:
- Export the keyfile password as an environment variable:
- MQTTS (Server):
Deploy the cluster with the MQTTS override
Configuring a Node
- Copy the
ca.crt
andca.key
files to the worker node. - Generate the certificates
- Generate a client key:
- Generate a certificate signing request:When prompted for the CN, enter the public IP of the machine
- Send the CSR to the CA:
- Decrypt the keyfile:
- Tell your OS to trust the certificate authority by placing the ca.crt file in the
/etc/ssl/certs/
directory
- Run the NodeEngine:
- (Optional) Configure the NetManager:
- Edit the
/etc/netmanager/netcfg.json
file so that the"MqttCert"
and"MqttKey"
fields specify the path to the node certificate and key files (The NetManager should use the same certificate-keyfile pair as the NodeEngine) - Run the NetManager:
- Run the NodeEngine:
- Edit the
Did you know?
The Oakestra automation repository contains many useful scripts such as ones for creating MQTTS certificate files.
Finishing up
Let’s check if all the components succesfully registered with the MQTT Broker via TLS.
- Cluster Manager: Check the docker compose logs withLook for the following lines:
- Node: Both the NodeEngine and NetManager should display the following log line after execution:
If everything looks good then Congrats 🎉, your MQTT channels are now secured! When adding any further components, be sure to always give them a unique CN, as this is used to identify the device.