# Mosquitto ACL file example (/etc/mosquitto/acl.conf)
# Sensor can only publish its own data
user sensor_001
topic read home/+/temperature
topic write home/sensor_001/#
# Actuator can only receive commands and publish status
user actuator_001
topic read home/commands/actuator_001
topic write home/status/actuator_001
# Dashboard can read everything but write nothing
user dashboard
topic read home/#
Security principle: Least privilege - devices only access topics they need.
1190.6.1 ACL Patterns
Pattern
Example
Description
Exact match
topic read sensors/temp
Only this specific topic
Single wildcard
topic write sensors/+/data
Any device’s data topic
Multi wildcard
topic read sensors/#
All under sensors/
Pattern substitution
topic write sensors/%u/data
%u = username
Show code
{const container =document.getElementById('kc-mqtt-security-1');if (container &&typeof InlineKnowledgeCheck !=='undefined') { container.innerHTML=''; container.appendChild(InlineKnowledgeCheck.create({question:"Your company deploys MQTT sensors in customer buildings. A sensor is configured with client_id='sensor' and username='device' with a shared password. What's the main security risk?",options: [ {text:"No risk - the password protects the connection",correct:false,feedback:"Shared credentials create multiple vulnerabilities: if one device is compromised, all are compromised."}, {text:"Multiple sensors using the same client_id will disconnect each other",correct:true,feedback:"Correct! MQTT brokers only allow one connection per client_id. When a second sensor connects with 'sensor', the first gets disconnected. This causes connection loops and data loss."}, {text:"The sensor can subscribe to any topic",correct:false,feedback:"This is a separate ACL issue, not related to shared client_id."}, {text:"TLS is not being used",correct:false,feedback:"TLS wasn't mentioned in the scenario. The immediate risk is the shared client_id."} ],difficulty:"medium",topic:"mqtt-security" })); }}
1190.7 Production Security Checklist
WarningBefore Deploying MQTT in Production
1190.8 Broker Hardening
1190.8.1 Mosquitto Configuration Example
# /etc/mosquitto/mosquitto.conf# Require authenticationallow_anonymousfalsepassword_file/etc/mosquitto/passwd# Enable TLSlistener8883cafile/etc/mosquitto/certs/ca.crtcertfile/etc/mosquitto/certs/server.crtkeyfile/etc/mosquitto/certs/server.key# Disable unencrypted listener# listener 1883 # COMMENTED OUT - DO NOT ENABLE IN PRODUCTION# Access controlacl_file/etc/mosquitto/acl.conf# Limit message sizemessage_size_limit102400# 100KB max# Connection limitsmax_connections10000max_inflight_messages100# Logging for security monitoringlog_destfile/var/log/mosquitto/mosquitto.loglog_typeerrorlog_typewarninglog_typenoticelog_typeinformation
1190.9 Common Security Pitfalls
CautionPitfall: Hardcoded Credentials
The Mistake: Embedding MQTT credentials directly in source code or firmware.