How-to
Configuring MQTT TLS certificates in Node-RED on an edge PC
Short answer
Configure the MQTT node's own TLS inputs: the broker's CA chain always, the client certificate and private key when the broker requires mutual TLS. A platform certificate store is invisible to Node-RED until the installed integration exposes it, so use persistent files unless store support is verified, and renew in a staged 30-day window.
On this page
- Do certificates in the platform certificate store reach Node-RED?
- Which certificates does the MQTT TLS connection need?
- Where should the certificate files live on the edge PC?
- How do I configure the MQTT node for TLS?
- How do I confirm the connection and the data path?
- How do I renew certificates without breaking publishing?
- Why does the connection still fail with the right certificates?
- Questions asked
Configure TLS in the MQTT node itself, and start with three concrete values: the broker's TLS listener port (conventionally 8883, taken from the broker's configuration), the CA chain file you load into the node's TLS configuration, and the client certificate and private key you add only when the broker requires mutual TLS. Put the files in a persistent directory, set the private key to file mode 0600 on Linux, and start renewal 30 days before each certificate's earliest expiry date. Treat a certificate imported into the platform's certificate store as invisible to Node-RED until the installed integration demonstrably exposes it. The order below is the order you meet the problem: what crosses the connection, where the files live, the configuration steps, the confirmation test, a renewal that does not interrupt publishing, and the failures that remain.
Do certificates in the platform certificate store reach Node-RED? #
Not automatically. A certificate imported into the controller's or edge platform's certificate store is invisible to the MQTT node until the installed Node-RED integration explicitly exposes that store, so configure the node's own TLS inputs unless you have verified store support on your exact setup.
The node's TLS configuration is the decision point. It takes a CA certificate, a client certificate and a client private key as its own inputs, and it either also offers a platform-store selector or it does not. If your installed version shows only the file inputs, a certificate sitting in the controller's store never reaches the TLS handshake: the import succeeds and the connection still fails trust. Test a store selector explicitly — pick the certificate, restart the runtime, and confirm the connection completes through it before relying on that route. Otherwise use the documented file inputs at a persistent path; that route works on any Node-RED install.
Which certificates does the MQTT TLS connection need? #
Three pieces of material cross one MQTT TLS connection: the CA chain Node-RED uses to verify the broker, the client certificate and private key Node-RED presents when the broker requires mutual TLS, and the broker's own server certificate, which must chain, be current and match the hostname.
| Certificate material | Direction | Required when | Where it goes |
|---|---|---|---|
| CA certificate or chain | Node-RED verifies the broker | Every TLS connection | CA input of the node's TLS configuration |
| Client certificate | Broker verifies Node-RED | Broker requires mutual TLS | Client certificate input |
| Client private key | Pairs with the client certificate | Broker requires mutual TLS | Key input, file readable only by the runtime account |
| Server certificate | Broker presents it to Node-RED | Always, configured broker side | Broker config; must chain to the trusted CA, sit inside its validity dates and match the hostname |
The two directions are independent: a client certificate does not replace the CA chain, and a completed handshake proves nothing about MQTT authorization, because a broker can accept TLS and still refuse the client's publish or subscribe. The same three inputs serve protocol nodes built on MQTT; for the Sparkplug variant, see configuring TLS in the Node-RED Sparkplug node.
Where should the certificate files live on the edge PC? #
In a persistent directory the Node-RED runtime can read after every reboot and update, with the private key readable only by the runtime account (file mode 0600 on Linux) and never inside an exported flow, a repository or a log.
If Node-RED runs in a container, that directory must be mounted into the container and survive image upgrades; a path in the container's writable layer or under a temporary directory is gone at the next restart. Prove persistence cheaply: restart the runtime once after configuring and confirm the flow reconnects on its own without any re-edit.
How do I configure the MQTT node for TLS? #
Open the broker configuration the MQTT nodes share, enable its TLS connection, create one TLS configuration holding the CA chain and, for mutual TLS, the client certificate and key, then deploy and watch both logs for a completed handshake.
- Read the broker hostname and TLS listener port from the broker's own configuration, not from an example. Port 8883 is the conventional registered listener for MQTT over TLS, but the broker's configured port decides. Confirm DNS, routing and firewall rules let the edge PC reach that endpoint.
- Record whether the broker requires client certificates and which CA issues them. Collect the CA chain file and its expiry dates from the broker administrator or certificate authority.
- Place the CA chain, client certificate and private key in the persistent directory, and set the key's permission before the first deploy.
- In the flow editor, open the MQTT broker configuration, enable its secure connection option and add a TLS configuration: CA certificate first, then the client certificate and private key if the broker asks for them.
- Connect using the hostname the server certificate identifies; an IP address only works if the certificate carries it.
- Leave server-certificate verification switched on. Disabling it trades away broker authentication to make a failed handshake look successful.
- Deploy the flow, then read the Node-RED log and the broker log together.
How do I confirm the connection and the data path? #
When both logs show a completed TLS handshake, an accepted MQTT connection and a test publish or subscribe that returns data, the configuration works; a connection that rises and falls in a loop is a trust or authorization failure, not a success.
Check three things in order: the Node-RED side shows the broker connection as connected, the broker log names the client identity it accepted, and a message you publish on a known topic arrives where you subscribe to it. Prove the whole certificate set against a broker you control before touching production by running a secure Mosquitto lab broker with Node-RED — the same CA, client and key inputs, the same handshake, none of the production risk.
How do I renew certificates without breaking publishing? #
Start a staged renewal 30 days before each certificate's earliest expiry date, stage the new files beside the old ones, switch the TLS configuration in one deploy, and keep the previous valid pair until the broker accepts the new identity.
That window is sized to leave room to stage files, confirm broker-side acceptance and keep a rollback path before expiry; it moves with the certificate's lifetime and the broker's rollover policy. Shorten the check interval as certificates get shorter, and lengthen the lead time when the broker cannot overlap trust for old and new chains.
Example with illustrative dates: the broker's server certificate runs from 2025-01-15 to 2026-01-15, a 365-day validity; the client certificate runs from 2025-07-01 to 2026-07-01. The window opens 30 days before each expiry: 2026-01-15 minus 30 days is 2025-12-16, and 2026-07-01 minus 30 days is 2026-06-01 — day 335 of the server certificate's life (365 − 30 = 335). Act on the earliest date, 2025-12-16.
Sequence the two sides separately. When the broker rotates its server certificate, confirm Node-RED trusts the new chain before the change window; when you rotate the client certificate, confirm the broker accepts the new identity before retiring the old one, and follow the broker's documented rollover policy rather than assuming overlapping validity. What an unnoticed expiry looks like in a running flow is covered in fixing an expired x509 certificate on an edge PC. The same expiry-tracking discipline applies across protocols — see troubleshooting OPC UA certificate expiry and renewal.
Why does the connection still fail with the right certificates? #
Because the fault sits in one of four layers — reachability, certificate trust, client identity or MQTT authorization — and the log symptom at each end tells you which; change one layer at a time and never disable validation to force a pass.
| Symptom in the logs | First check |
|---|---|
| Connection timeout | DNS, route, firewall, broker listener, configured port |
| TLS alert, certificate rejected | CA chain completeness, validity dates, hostname-to-certificate match |
| Handshake starts, client rejected | Mutual TLS required, certificate and key pairing, broker trust for the client's issuer |
| TLS completes, MQTT denied | Broker authentication, client identity mapping, publish and subscribe authorization |
A key file the runtime cannot parse or read fails before any of this; see fixing an MQTT TLS private key load failure on an edge gateway. Read both ends' logs for every change you make, one layer at a time, and keep validation on throughout.
Questions asked
Does the client certificate replace the CA certificate in the MQTT node?
No, and the failure points differ. Without the CA chain the handshake stops while Node-RED verifies the broker; without the client certificate it stops after the broker asks Node-RED to identify itself. Configure the CA chain in every TLS setup and add the client certificate and private key only where the broker requires mutual TLS.
Can a wrong system clock break a TLS connection that uses valid certificates?
Yes. TLS validation reads the notBefore and notAfter dates on every X.509 certificate and compares them with the edge PC's clock, so a device that is hours off can make a valid certificate look expired or not yet valid. Synchronize the clock before touching the trust chain; a certificate that fails on one device but works elsewhere points at time, not at the chain.
Do the MQTT in and MQTT out nodes each need their own TLS configuration?
No. Both node types attach to one shared broker configuration, and the TLS setup lives there, so you build the CA chain, client certificate and key once and every MQTT node in the flow uses it. If you need two brokers or two trust setups, create a second broker configuration and assign nodes to it explicitly.
How often should certificate expiry be checked on an edge PC?
Weekly for certificates with roughly a year of validity. A weekly check gives you at least four readings inside a 30-day renewal window (30 divided by 7 is about 4), so the window cannot open and close between checks. Move to a daily check when certificates are short-lived, for example 90-day public certificates, where a 30-day window is a third of the lifetime.