Authorization
The ordered authorization chain (ACL file, JWT, HTTP, PostgreSQL, MySQL, Redis, MongoDB), first-decision-wins evaluation, per-source superuser bypass, rule format and topic matching.
The authorization chain decides which topics a client may publish to and which filters it may subscribe to. It
is an ordered list of sources declared as [[authorization]] tables, independent of the
authentication chain that let the client in: a client can log in with the password
file and get its rules from PostgreSQL, a JWT, or both.
Every check runs on the client's own core, with no I/O and no locks. Sources whose rules live in a database or a service load each client's rules once, at CONNECT, and keep them with the session.
How the chain works
For every PUBLISH and SUBSCRIBE, the enabled sources are asked in order and the first allow or deny wins. Each source answers:
- allow or deny when one of its rules matches, or when none matches and its own
no_matchis"allow"or"deny"; - ignore when none of its rules matches and its
no_matchis"ignore"(the default), or when it has nothing for this client (no rows loaded, no token, an HTTP"result": "ignore").
When every source answered ignore, [auth] no_match decides (default "deny", env ORBITMQ_AUTH_NO_MATCH). An
empty authorization chain (no [[authorization]] table) allows everything, as in a broker without ACLs. Disabled
sources are skipped.
[auth]
no_match = "deny" # chain end (the default)
[[authorization]] # 1. per-device rules from PostgreSQL, loaded at CONNECT
kind = "postgres"
name = "device-acl"
url = { env = "MQTT_AUTH_DB_URL" }
acl_query = "SELECT permission, action, topic FROM mqtt_acl WHERE username = %u ORDER BY id"
[[authorization]] # 2. shared rules for everyone else
kind = "file"
name = "static"
path = "/etc/orbitmq/acl.toml"Here a device whose rows allow devices/sensor-17/# may publish there; a topic none of its rows matches falls
through to the ACL file; and an action the ACL file does not match either is refused by [auth] no_match.
Source keys
Besides kind, name and enabled (see Common keys), every
[[authorization]] source takes:
| Key | Default | Meaning |
|---|---|---|
superuser_bypass | true | Allow superusers before this source's rules. |
no_match | "ignore" | This source's decision when none of its rules matches: "ignore" (the next source decides), "deny" or "allow". |
on_error | "deny" | Network kinds: a failed ACL load (error, timeout, max_in_flight overflow, more than 1024 rules or an invalid rule). "deny": this source denies every action of that session (fail closed). "ignore": it answers ignore for that session. |
timeout_ms | 3000 | Network kinds: time allowed for one ACL load. All loads of one CONNECT start at once and also share [auth] timeout_ms. |
max_in_flight | 256 | Network kinds: most ACL loads running at once. |
[authorization.cache] | see Caching | Network kinds: remembers a client's loaded rules. |
on_not_found, auth_query and the other keys of authenticating sources are errors here.
Superusers
A client is a superuser when the authentication source that accepted it says so (a JWT superuser_claim, an HTTP
is_superuser field, an is_superuser column or hash field, a MongoDB superuser_field), or when its user name is
listed in [auth] superusers:
[auth]
superusers = ["operator"] # env ORBITMQ_AUTH_SUPERUSERS=operator (comma-separated)Each authorization source decides for itself what a superuser may do:
superuser_bypass = true(the default): the source allows a superuser before looking at its rules.superuser_bypass = false: the source evaluates its rules for superusers like for anyone else. In an ACL file, rules withwho = "superuser"match them.
Because the first decision wins, order matters: a bypassing source placed before a non-bypassing one decides for
superusers. To restrict superusers with an ACL file, put that file (with superuser_bypass = false) first, or turn
the bypass off on every source before it. Anonymous clients are never superusers, and superusers requires an
[[authentication]] source.
Authorization sources
kind | Rules come from | Loaded |
|---|---|---|
file | an ACL file (TOML) | when the source is built |
jwt | a claim of the token the client presented | at CONNECT |
http | the response of an HTTP(S) service | at CONNECT |
postgres, mysql | rows returned by acl_query | at CONNECT |
redis | a Redis hash read with acl_cmd | at CONNECT |
mongodb | documents of acl_collection | at CONNECT |
How rules loaded at CONNECT behave:
- After the client is authenticated (by any source, or anonymously), every enabled authorization source with a
loader fetches the client's rules. The loads run in parallel within
[auth] timeout_ms, and%uin them is the authenticated user name (which a JWTusername_claimor an HTTPusernamemay have replaced). - The rules are kept with the session and evaluated without I/O. A rule change in the database applies to sessions
that connect afterwards, or after the source's cache TTL for reconnecting clients
(
ttl_secsin[authorization.cache], 60 seconds by default). Kick a client through the admin API to make it reconnect sooner. - No data for the client (a placeholder without a value, no token, an HTTP
"result": "ignore") makes the source answer ignore. Data without rules (no rows, a token without the claim) means none of its rules match, so the source'sno_matchapplies. - A source disabled when the client connected, or replaced through the admin API after it connected, has no rules for that session and answers ignore until the client reconnects.
A client can have at most 1024 rules per source.
Network sources here take the same connection keys as in the authentication chain, including the transport checks:
plain text or unverified TLS to a host that is not on this machine is refused unless the source sets
allow_insecure_tls = true (databases) or allow_insecure_http = true (http). See
Insecure connections.
ACL file
[[authorization]]
kind = "file"
path = "/etc/orbitmq/acl.toml"
superuser_bypass = true # the default
no_match = "ignore" # the default: the next source, then [auth] no_match, decidesThe file is read when the source is built: at start-up, and again when the source is replaced through the admin API. Rules apply to every client; see File format.
JWT
Takes the rules from a claim of the token, verified like an authenticating jwt source
(the same keys, except username_claim and superuser_claim, which belong to authentication):
[[authorization]]
kind = "jwt"
name = "token-acl"
jwks_url = "https://auth.example.com/keys.json"
audience = ["mqtt"]
acl_claim = "mqtt_acl" # required here
no_match = "deny" # token holders get exactly what their token says{ "sub": "device-1", "exp": 1798761600, "mqtt_acl": { "pub": ["devices/device-1/#"], "sub": ["commands/device-1/#"] } }The token is taken from the CONNECT password (or the user name with from = "username"). A client without a token,
or with a token this source cannot verify, gets ignore from it. The claim uses the JSON rule form.
HTTP
Sends one request per CONNECT to an HTTP(S) service, with the same keys and request body as an
authenticating http source, except that password is always null and
username is the authenticated user name:
[[authorization]]
kind = "http"
name = "acl-service"
url = "https://auth.internal.example/mqtt/acl"
headers = { Authorization = { env = "MQTT_AUTH_SERVICE_TOKEN" } }The service answers status 200 with the client's rules in the JSON rule form:
{ "acl": [{ "permission": "allow", "action": "publish", "topic": "devices/%c/#" }] }or {"result": "ignore"} when it has nothing for the client. Any other status, or a body with neither acl nor
"result": "ignore", is a backend error (on_error).
PostgreSQL and MySQL
[[authorization]]
kind = "postgres" # or "mysql"
url = { env = "MQTT_AUTH_DB_URL" }
acl_query = "SELECT permission, action, topic FROM mqtt_acl WHERE username = %u ORDER BY id"CREATE TABLE mqtt_acl (
id serial PRIMARY KEY,
username text NOT NULL,
permission text NOT NULL, -- allow | deny
action text NOT NULL, -- publish | subscribe | both
topic text NOT NULL
);acl_query (required) returns rows with text permission, action and topic columns, in rule order. url,
pool_size and the [authorization.tls] table are the same as for
authenticating SQL sources.
Redis
[[authorization]]
kind = "redis"
url = { env = "MQTT_AUTH_REDIS_URL" }
acl_cmd = "HGETALL mqtt_acl:%u"redis-cli HSET mqtt_acl:alice 'devices/alice/#' both 'commands/alice/#' subscribeacl_cmd (required) is HGETALL <key>: each field is a topic filter and its value the allowed action (publish,
subscribe or both). Redis rules are allow rules. url, pool_size and [authorization.tls] are as for
authenticating Redis sources.
MongoDB
[[authorization]]
kind = "mongodb"
url = { env = "MQTT_AUTH_MONGO_URL" }
database = "mqtt"
acl_collection = "acl"
acl_filter = { username = "%u" } # the defaultacl_collection (required) holds documents with action, topic (or a topics array) and an optional permission
(default allow), applied in _id order. acl_filter is an equality filter whose values may hold
placeholders. url, database and [authorization.tls] are as for
authenticating MongoDB sources.
JSON rule form
JWT claims and HTTP responses carry rules either as a list, where permission defaults to allow and topics may
replace topic:
[
{ "permission": "allow", "action": "publish", "topic": "devices/%c/#" },
{ "permission": "deny", "action": "both", "topics": ["devices/%c/secrets/#", "admin/#"] },
{ "action": "subscribe", "topic": "commands/%c/#" }
]or as an object of allowed filters per action:
{ "pub": ["devices/%c/#"], "sub": ["commands/%c/#"], "all": ["users/%u/inbox"] }Permissions are allow or deny; actions are publish (or pub), subscribe (or sub) and both (or all,
pubsub), case-insensitive. These rules always apply to the client they were loaded for, use the same
topic matching and placeholders as the ACL file, and are checked in order: the
first matching rule decides.
File format
# Every device owns the subtree named after its client identifier.
[[rule]]
permission = "allow"
action = "both"
topic = "devices/%c/#"
# The dashboard user may read all telemetry, but nothing else.
[[rule]]
permission = "allow"
who = { user = "dashboard" }
action = "subscribe"
topic = "devices/+/telemetry"
# Nobody may publish to the command topics, except the operator account.
[[rule]]
permission = "allow"
who = { user = "operator" }
action = "publish"
topic = "commands/#"
[[rule]]
permission = "deny"
action = "both"
topic = "commands/#"
# Everyone may use their own per-user inbox.
[[rule]]
permission = "allow"
action = "both"
topic = "users/%u/inbox"The file holds only [[rule]] tables. The policy when no rule matches and the superuser bypass are keys of the
[[authorization]] source (no_match, superuser_bypass); a file that still sets default or superuser_bypass is
refused with a message saying so.
Rule keys ([[rule]])
| Key | Values | Default | Meaning |
|---|---|---|---|
permission | "allow", "deny" | required | What the rule decides when it matches. |
action | "publish", "subscribe", "both" | required | Which operations the rule applies to. |
topic | topic filter | required | MQTT topic filter, with optional %c and %u placeholders. |
who | "all", "superuser", { user = "…" }, { client = "…" } | "all" | Whom the rule applies to: everyone, superusers, one authenticated user name, or one client identifier. |
Unknown keys and invalid topic filters are errors: the broker does not start (or the API request is refused), and the message names the rule (counting from 0).
Evaluation
- Rules are checked in order; the first matching rule decides. Put specific
denyrules before broadallowrules (or the other way round) on purpose. - A rule matches when its
who(ACL file only), itsactionand its topic filter all match. - If no rule matches, the source's
no_matchapplies.
Topic matching
| Operation | An allow rule matches when… | A deny rule matches when… |
|---|---|---|
| PUBLISH to a topic name | the rule filter matches the topic | the rule filter matches the topic |
| SUBSCRIBE to a filter | the rule filter covers the requested filter: every topic the requested filter can match is also matched by the rule | the two filters overlap: some topic is matched by both |
So with allow sensors/+:
- subscribing to
sensors/temporsensors/+is allowed; - subscribing to
sensors/#or#is not allowed by this rule, because they also match topics such assensors/a/b.
And with deny secret/#, a subscription to # or +/x is refused, because it could receive secret/… messages.
Wildcard rules follow the MQTT $ rule: a rule filter that starts with + or # never matches topics that start with
$. allow # therefore does not grant $SYS/…; write a rule for that prefix explicitly.
For shared subscriptions ($share/{group}/{filter}), the chain checks the underlying {filter}.
Placeholders
| Placeholder | Replaced by |
|---|---|
%c | The client identifier. |
%u | The authenticated user name. |
A value is substituted only if it is non-empty and contains none of /, +, # or the null character. Otherwise
the rule is resolved fail-closed: an allow rule does not match, and a deny rule matches. This prevents a client
identifier such as # from turning devices/%c/# into devices/#/#, or a/b from reaching another client's subtree.
Clients without a user name (anonymous) never match rules that use %u.
Changing the chain at runtime
The authorization chain can be reordered, enabled, disabled and edited without a restart, from the dashboard's
Auth & ACL page or the /api/v1/auth/authorization endpoints; changes are kept in the auth state file. See
Changing the chains at runtime. Each source's answers
are counted in orbitmq_auth_source_decisions_total{chain="authorization"} (see
Metrics).
What clients see
| Refused operation | MQTT 5.0 | MQTT 3.1.1 | MQTT 3.1 |
|---|---|---|---|
| SUBSCRIBE | SUBACK reason code 0x87 Not Authorized | SUBACK return code 0x80 (failure) | SUBACK grants the QoS, but no subscription is created (3.1 has no failure code) |
| PUBLISH QoS 1 or 2 | PUBACK or PUBREC with 0x87 Not Authorized | Acknowledged normally, not forwarded | Acknowledged normally, not forwarded |
| PUBLISH QoS 0 | Not forwarded | Not forwarded | Not forwarded |
Refusing a publish never closes the connection.
Authentication
The ordered authentication chain (password file, X.509, JWT, HTTP, PostgreSQL, MySQL, Redis, MongoDB), its allow / deny / ignore cascade, caching, failure policy, and runtime changes from the admin API and the dashboard.
Rules and integrations
SQL rules over published messages, with republish, HTTP webhook, MQTT bridge and Kafka actions; delivery semantics, connectors, the admin API, the dashboard and metrics.