ACL - Roles
Roles are named sets of ACL rules that control which MQTT topics a client can publish to or subscribe to. Instead of defining topic permissions on each client individually, you define a role once and assign it to as many clients or groups as needed.
What Roles Are
A role is a reusable permission template. It contains one or more ACL rules, each specifying:
- A topic pattern - which topic or set of topics the rule applies to
- An action - whether the rule controls publishing, subscribing, or both
- An effect - whether the action is allowed or denied
When a client attempts to publish or subscribe, Mosquitto evaluates the ACL rules from all roles assigned to that client (directly and through groups). If a matching allow rule is found, the action proceeds. If a deny rule matches first, the action is blocked.
Creating a Role
- Navigate to ACL > Roles in the sidebar.
- Click Add Role.
- Enter a Role Name - use something descriptive like
sensor-read-onlyoradmin-full-access. - Click Save to create the role.
- The role is created empty. Click on it to add ACL rules.
Adding ACL Rules to a Role
Once you have a role, open it and add rules:
- Click Add Rule.
- Enter a Topic Pattern (see topic patterns section below).
- Select the Action:
subscribe- controls the ability to subscribe to the topicpublish- controls the ability to publish to the topicall- applies to both subscribe and publish- Select the Effect:
allow- permit the actiondeny- block the action- Click Save.
Repeat for each rule you want to add to the role.
Understanding Topic Patterns
Topic patterns support two MQTT wildcards:
# - Multi-level wildcard
Matches everything from that position in the hierarchy downward.
Matches: sensor/temp, sensor/humidity, sensor/floor2/temp, sensor/floor2/room1/temp
Use # at the end of a pattern to grant access to an entire subtree.
+ - Single-level wildcard
Matches exactly one topic level.
Matches: sensor/kitchen/temperature, sensor/bedroom/temperature
Does NOT match: sensor/temperature, sensor/floor2/room1/temperature
Examples of topic patterns
| Pattern | Matches |
|---|---|
sensor/temp |
Exact topic only |
sensor/# |
All topics under sensor/ |
sensor/+/temp |
One level deep under sensor/, ending in /temp |
# |
Every topic on the broker |
home/+/+/status |
Two levels under home/, ending in /status |
Assigning a Role to a Client
- Go to ACL > Clients.
- Find the client and open its detail view.
- Click Add Role under the Roles section.
- Select the role from the dropdown.
- Set an optional priority and click Save.
The client immediately gains all permissions defined in that role.
Assigning a Role to a Group
- Go to ACL > Groups.
- Find the group and open its detail view.
- Click Add Role.
- Select the role.
- Set an optional priority and click Save.
All clients in the group immediately inherit the role's permissions.
Editing a Role
- Go to ACL > Roles.
- Click on the role name to open it.
- Add, edit, or delete individual ACL rules.
- Changes take effect immediately on all clients that have this role assigned.
Deleting a Role
- Go to ACL > Roles.
- Find the role and click Delete.
- Confirm the deletion.
Deleting a role removes it from all clients and groups that had it assigned. Those clients lose the permissions the role was granting. Make sure you are not removing access that devices depend on.
Priority and Rule Ordering
When a client has multiple roles (from direct assignment and group membership), Mosquitto evaluates rules in priority order. Higher priority numbers take precedence over lower ones.
Within a single role, rules are evaluated in the order they are listed. The first matching rule wins.
Key points:
- A
denyrule matching before anallowrule will block the action. - If no rule matches, the action is denied by default (Mosquitto's default-deny behavior).
- You can use explicit
denyrules to carve exceptions out of broadallowrules.
Best Practice Examples
sensor-read-only role
For sensors that should only publish their data and not subscribe to anything:
| Topic | Action | Effect |
|---|---|---|
sensor/+/data |
publish | allow |
actuator-write role
For actuators that receive commands:
| Topic | Action | Effect |
|---|---|---|
actuator/+/command |
subscribe | allow |
actuator/+/status |
publish | allow |
monitor-subscribe-all role
For a dashboard or monitoring tool that reads everything:
| Topic | Action | Effect |
|---|---|---|
# |
subscribe | allow |
admin-full-access role
For administrative clients that need unrestricted access:
| Topic | Action | Effect |
|---|---|---|
# |
all | allow |
Deny exception pattern
Allow everything in a subtree except one sensitive topic:
| Topic | Action | Effect | Priority |
|---|---|---|---|
home/private/# |
all | deny | 10 |
home/# |
all | allow | 5 |
Higher priority deny rule blocks the private subtree even though the broader allow rule would otherwise permit it.