MQTT security guide
Secure MQTT from the device identity to the topic
A production MQTT deployment needs layered controls: TLS, client authentication, explicit ACL authorization, protected secrets, network boundaries, and evidence when something goes wrong.
Start with the failure modes MQTT cannot prevent alone
The protocol is intentionally lightweight. Security comes from the deployment choices around it.
Client impersonation
Over-broad topic access
Availability abuse
| Security boundary | Credible threat | Primary control | Residual risk |
|---|---|---|---|
| Device | Extracted secrets, cloned firmware, or a stolen unit impersonates a client. | One protected credential per device, secure boot and storage where available, and individual revocation. | A valid compromised device can still perform every action its current policy permits. |
| Broker | Credential guessing, session takeover, broad subscriptions, and resource exhaustion. | TLS, authentication, client-ID checks, default-deny topic policy, quotas, and audit events. | TLS and ACLs do not correct unsafe payload handling or eliminate availability attacks. |
| Control plane | An operator account or automation token changes policies, issues credentials, or suppresses evidence. | Strong operator authentication, least-privilege roles, change review, and immutable audit export. | A sufficiently privileged account remains a high-impact target; separate duties and recovery access. |
| Network | Interception, DNS or route manipulation, scanning, and connection floods reach the endpoint. | Certificate and hostname validation, restricted ingress, segmentation, and rate limits. | Encryption does not hide endpoint metadata or guarantee upstream network availability. |
Build the controls in the right order
- 01
Encrypt and validate transport
Require TLS 1.2 or newer, validate the broker hostname and certificate chain, and remove plain listener access from production networks.
- 02
Give every device an identity
Issue independent credentials so one compromised device can be revoked without rotating an entire fleet.
- 03
Authorize every topic action
Evaluate publish and subscribe separately, bind filters to a device role, and deny access that is not explicitly required.
Rotate and revoke
Constrain the network
Monitor the control plane
Choose identity strength from device constraints
The strongest scheme is the one the device can store, rotate, validate, and recover safely throughout its lifecycle.
| Authentication method | Best fit | Strength | Operational requirement |
|---|---|---|---|
| Unique username and password | Constrained devices and straightforward fleets | Good with validated TLS and strong unique secrets | Secure storage, rate limiting, rotation, and revocation |
| Client certificate (mTLS) | Managed hardware and high-assurance device identity | Strong cryptographic identity during the TLS handshake | PKI issuance, protected private keys, renewal, and revocation |
| Short-lived token | Gateways and applications with an identity provider | Scoped and time-limited when validated correctly | Trusted token minting, clock handling, refresh, and audience checks |
listener 8883
allow_anonymous false
password_file /etc/mosquitto/passwords
acl_file /etc/mosquitto/acl
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/broker.crt
keyfile /etc/mosquitto/certs/broker.key
tls_version tlsv1.2mosquitto_sub \
-h mqtt.example.invalid -p 8883 \
--cafile ./ca.crt \
-u sensor-042 -P 'REPLACE_ME' \
-i sensor-042-check \
-t 'factory/shanghai/line-1/sensor-042/command' \
-dMake topic policy reviewable
Express the device contract as narrow publish and subscribe filters, then test both allowed and denied topics before rollout.
# Mosquitto ACL: username is the unique device identity
pattern write factory/shanghai/line-1/%u/telemetry
pattern write factory/shanghai/line-1/%u/state
# It may receive only its own commands
pattern read factory/shanghai/line-1/%u/command
# Unlisted topics are denied by defaultRotate without creating a shared-secret outage
Broker and identity-provider APIs differ. Use this vendor-neutral sequence as an operational runbook, then map each step to your platform.
- 01
Inventory the identity and blast radius
Record the device owner, policy, last use, secret type, issue time, expiry, and a tested recovery path.
- 02
Issue a second credential with bounded overlap
Keep the old credential active only for a short migration window. Give the replacement the same or narrower topic policy, never broader access.
- 03
Prove the new path before cutover
Reconnect with full TLS validation, confirm permitted traffic, run negative topic tests, and capture the new identity in logs.
- 04
Revoke the old credential and terminate sessions
Disable the server-side identity, disconnect existing sessions, and verify that reconnect and publish attempts fail.
- 05
Close the evidence loop
Remove the old secret from devices and stores, record completion, and alert on any later use of the revoked identity.
Compromise path: revoke first, investigate second
For a suspected theft, skip planned overlap: disable the identity, end active sessions, preserve broker and control-plane logs, narrow affected policies, issue a replacement only to a re-established device, and watch for reuse.
Production MQTT security baseline
Use the release gate below, then download the full printable checklist for transport, identity, authorization, rotation, network, monitoring, and incident response.
TLS is mandatory
Secrets are device-scoped
Policies are tested
Incidents are actionable
Standards and implementation references
Protocol facts and examples in this guide are grounded in standards bodies and implementation owners. Product capabilities are stated separately below.
- OASIS MQTT 5.0 — Security (non-normative)
- Eclipse Mosquitto — ACL file plugin
- Eclipse Mosquitto — Broker configuration reference
- AWS IoT Lens — Identity and access management
- OWASP — Network Segmentation Cheat Sheet
What RunMQTT currently provides
Private RunMQTT brokers expose TLS and secure WebSocket endpoints, generated per-device username/password credentials, reusable publish/subscribe topic policies, policy testing, and immediate access removal when a device is deleted. The product does not currently expose customer-managed mTLS identities, external token authentication, network allowlists, or in-place credential rotation in the dashboard; replace a credential by creating and validating a new device identity, then deleting the old one. The public broker is a shared testing sandbox and is not a production security control.
MQTT security FAQ
Does MQTT include encryption by default?
No. MQTT defines messaging behavior, while TLS protects the transport. A plain connection on port 1883 can expose credentials, topics, and payloads to the network.
Is TLS enough to secure an MQTT deployment?
TLS protects data in transit and authenticates the broker, but it does not decide which topics a valid client may use. Pair TLS with unique identity, topic authorization, secure credential storage, and monitoring.
Can username and password authentication be secure?
Yes, when every device receives a unique strong secret, the connection validates TLS, secrets are stored safely, failed attempts are limited, and rotation and revocation are operationally possible.
How should MQTT topic permissions be modeled?
Separate publish from subscribe rights and grant only the narrow topic filters required by a device role. Avoid broad # access for field devices and test every policy against expected and denied topics.
Related MQTT resources
Apply the security model to a working client, then inspect how MQTT fits with other real-time technologies.
MQTT ACL linter
Check wildcard breadth, tenant and device boundaries, direction, and overlapping rules locally.
MQTT tutorial
Connect, publish, subscribe, and choose QoS from first principles.
Public broker testing
Practice with synthetic data and understand shared-endpoint limits.
MQTT QoS lab
Test reconnect state, duplicate handling, and the boundary of exactly-once delivery.
Browser MQTT over WSS
Separate TLS transport, MQTT identity, topic policy, and browser recovery responsibilities.
RunMQTT access controls
See how device identity and reusable topic policies fit the control plane.