MQTT security: TLS, authentication and topic access control
Part of the MQTT guide
MQTT security rests on three controls, and the protocol itself supplies only part of one. Encryption comes from TLS underneath MQTT. Authentication comes from the user name and password fields in CONNECT, from a TLS client certificate, or in MQTT 5.0 from an extended exchange. Authorization, meaning which client may publish or subscribe to which topic, is not defined by the standard at all and is configured in the broker. A broker with none of these set up accepts any client and shows it every message.
This page belongs to the MQTT guide. The port side of TLS is on the MQTT ports page.
What the standard does and does not provide
| Control | In the MQTT standard | Where it comes from |
|---|---|---|
| Encryption in transit | Not in the protocol. The standard registers port 8883 for TLS | TLS, configured on the broker and each client |
| Broker identity | Not in the protocol | The broker’s TLS certificate, verified by the client |
| Client identity | User name and password fields in CONNECT; AUTH packets in 5.0 | Those fields, or a TLS client certificate |
| Authorization per topic | Not defined | Broker access control lists or an external policy service |
| Payload integrity or encryption end to end | Not defined | The application, if it is needed |
The security chapter of both the 3.1.1 and 5.0 standards is guidance, not requirements. Everything below is a deployment decision.
Encryption: TLS
Without TLS, every packet is readable on the path, including the CONNECT packet that carries the password. TLS on port 8883 encrypts the stream and lets the client verify that it reached the real broker.
That verification is the part most often switched off. Client libraries offer a setting to skip certificate checks, added during testing to get past a hostname mismatch or a private CA, and it tends to survive into production. A client that does not verify the broker’s certificate will send its credentials to anything that answers on the address. Install the CA certificate on the device and connect by the name in the broker’s certificate.
TLS protects each connection, not the message. The broker decrypts every payload and encrypts it again for each subscriber. If the broker operator must not read the data, the payload has to be encrypted by the application.
Authentication: user name and password
CONNECT has optional user name and password fields. The broker checks them and answers in CONNACK.
| MQTT 3.1.1 return code | Meaning |
|---|---|
00 | Connection accepted |
02 | Client identifier rejected |
04 | Bad user name or password |
05 | Not authorized |
MQTT 5.0 uses reason codes instead: 86 for a bad user name or password and 87 for not authorized.
Passwords work when each device has its own. A single password shared by a fleet cannot be revoked for one stolen device without reconfiguring all the others, and a password compiled into firmware is readable by anyone with the binary.
Authentication: client certificates
With mutual TLS, the client presents an X.509 certificate during the TLS handshake and proves it holds the matching private key. The broker checks the certificate against a CA it trusts before any MQTT packet is exchanged. The private key never leaves the device, there is no secret on the wire to capture, and one device’s certificate can be revoked without touching the rest.
The work moves to provisioning: each device needs its own key and certificate installed, stored where firmware extraction cannot reach it if the hardware allows, and replaced before it expires. Plan the rotation procedure before the first certificate is issued.
Enhanced authentication in MQTT 5.0
MQTT 5.0 adds an Authentication Method and Authentication Data property to CONNECT and a new packet type, AUTH. Together they allow a multi-step exchange between client and broker before the connection is accepted, which makes challenge and response mechanisms possible without sending a password. The method names are not fixed by the standard; client and broker must support the same one, and a broker that does not recognize the method refuses with reason code 8C, bad authentication method.
Authorization: who may use which topic
Authentication settles who the client is. Authorization settles what it may do, and it is specific to each broker: a list of rules that grant publish or subscribe rights on topic filters to a user, a certificate identity or a client identifier.
The useful pattern is one narrow rule per device. A device may publish under its own branch, for example site1/pump3/#, may subscribe to its own command topic, and nothing else. Design the topic tree with this in mind; rules are simple when a device’s identity appears as a topic level. The topics and wildcards page covers that design.
How a refusal shows up depends on the version. In MQTT 3.1.1 a refused subscription returns 80 in SUBACK, but a refused PUBLISH has no error to return: the broker either acknowledges it normally and discards it, or closes the connection. A device whose data silently vanishes is often publishing to a topic it has no right to. MQTT 5.0 fixes this with reason code 87, not authorized, on PUBACK and SUBACK.
Protocol features that become attack surface
Client identifier takeover. When a client connects with an identifier that is already connected, the broker disconnects the existing client. Anyone who can authenticate and choose an arbitrary identifier can knock a device offline, and with a persistent session can receive its queued messages. Tie the allowed identifier to the credential.
Wildcard subscriptions. A client allowed to subscribe to # sees every message from every device. Deny it by default.
Retained messages and wills. Both let a client leave a message behind that the broker delivers later in its name. A client with publish rights on a status or command topic can plant a retained message that every future subscriber receives. Restrict retained publishes on topics that drive actions.
$SYS topics. Many brokers publish client counts, versions and traffic statistics under $SYS/. Limit who can read them.
Resource limits. Large payloads, thousands of subscriptions and connection floods are cheap to produce. Set a maximum packet size, connection limits and rate limits on the broker.
An MQTT security checklist
- No listener on port
1883reachable from outside an isolated network. - TLS on every external listener, with certificate verification left on in every client.
- Anonymous access disabled.
- One credential per device: a certificate, or a unique user name and password.
- Client identifier bound to the credential.
- Access rules that confine each device to its own topics, with
#and$SYS/#denied by default. - A tested procedure to revoke one device and to rotate credentials.
- Devices dial out. No inbound port is opened to the plant.
How ControlCom secures MQTT
The ControlCom Connect documentation describes the following. Devices publish to the platform’s MQTT broker over TLS on port 8883. ControlCom Gateways and Generic devices authenticate with mutual TLS: creating a device provisions an X.509 certificate for it and opens a Download Certificates & Secrets dialog with the device certificate, the keys and the root certificate the device needs to verify the broker. The private key is generated once and is not offered again. A device can hold two certificates at a time, so rotation is done on the device’s Certificates tab by generating a second certificate, installing it, confirming the device connects, and then deactivating and removing the first. The device opens the connection outward, and nothing on site needs to be reachable from outside.
On site, the ControlCom Edge Server exposes its Sparkplug B broker on port 8883 over mutual TLS, and its web interface tools reach the broker with the token issued at sign-in.
The security reference covers these mechanisms alongside API keys, sessions and audit logging, and the page for controls engineers describes how devices are brought onto the platform.
Each device that publishes to ControlCom Connect has its own certificate, connects outward over TLS, and can have that certificate rotated from its device page.