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.

OrbitMQ decides who may connect with an authentication chain: an ordered list of sources declared as [[authentication]] tables. What a connected client may publish and subscribe to is decided separately, by the authorization chain ([[authorization]]). The two chains are independent: a client can log in with the password file and get its ACL from PostgreSQL.

Plain-text passwords are never stored: the password file and every database source compare the client's password with a stored hash.

How the chain works

Every CONNECT walks the enabled sources in order. Each source answers one of three things:

AnswerMeaningExamples
allowStop: the client is accepted, with this user name and superuser flag.correct password; valid token; HTTP "result": "allow"
denyStop: the client is refused with the source's reason code.wrong password for a known user (0x86); invalid token (0x86); backend error with on_error = "deny" (0x88)
ignoreNo opinion: the next source is asked.no user name; no token or certificate; unknown user with on_not_found = "ignore"; backend error with on_error = "ignore"

The first allow or deny wins. Disabled sources (enabled = false) are skipped. When every source answered ignore, the end of the chain decides:

Situation at the end of the chainResult
The client sent a user name, and the chain has at least one source (enabled or not)Refused with 0x86 Bad User Name or Password (3.x return code 4). A user name nobody vouched for never falls through to anonymous access.
The client sent no user name[auth] allow_anonymous decides: true accepts it as an anonymous client; false refuses it with 0x87 Not Authorized (3.x return code 5). Unset, it is false as soon as the chain has a source.
The chain is empty (no [[authentication]] table)Every client is accepted, as in a broker without authentication. User names are not checked.
orbitmq.toml
[auth]
allow_anonymous = false       # clients without a user name must be accepted by a source
timeout_ms = 5000             # the whole authentication of one CONNECT (the default)

[[authentication]]            # 1. operators and service accounts
kind = "password_file"
name = "local"
path = "/etc/orbitmq/passwords"

[[authentication]]            # 2. devices, from PostgreSQL
kind = "postgres"
name = "devices"
url = { env = "MQTT_AUTH_DB_URL" }
auth_query = "SELECT password_hash, is_superuser FROM mqtt_user WHERE username = %u"

With this chain, alice (in the password file) is checked against the file. sensor-17 is not in the file, so the file answers ignore (its on_not_found defaults to "ignore") and PostgreSQL decides. A user name that neither knows is refused with 0x86. A source that knows a user but receives the wrong password answers deny; it does not pass the client on.

allow_anonymous = false and superusers both require at least one [[authentication]] source; the broker refuses to start otherwise.

Anonymous access

When allow_anonymous is not set, it follows the authentication chain: a broker with no source accepts anonymous clients, so a first run works without configuration, and the first source closes anonymous access. A source counts whether it is enabled or not, and whether it comes from orbitmq.toml, the environment, the state file or the admin API. Authorization sources do not count. An explicit value always wins. Set allow_anonymous = true if clients without a user name should keep connecting next to authenticated ones.

While allow_anonymous is unset, the broker never drops back to anonymous access on its own. The admin API refuses to remove the last authentication source (409 last_source), and the broker does not start when a state file with no authentication source would replace sources in orbitmq.toml. Set allow_anonymous explicitly, or add another source. Disabling the last source is allowed, because it still counts.

While anonymous access is on, the broker logs a warning at start-up that names every listener that is not on a loopback address.

[auth] settings

KeyDefaultEnvMeaning
allow_anonymousfalse with an authentication source, true withoutORBITMQ_AUTH_ALLOW_ANONYMOUSChain end for clients without a user name (see Anonymous access).
superusers[]ORBITMQ_AUTH_SUPERUSERS (comma-separated)User names that become superusers once any source has accepted them.
timeout_ms5000ORBITMQ_AUTH_TIMEOUT_MSTime allowed for the whole authentication of one CONNECT, ACL loads included. When it runs out the client is refused with 0x88 Server Unavailable and any check still running is cancelled.
no_match"deny"ORBITMQ_AUTH_NO_MATCHAuthorization chain end; see Authorization.
state_filenext to orbitmq.tomlORBITMQ_AUTH_STATE_FILEWhere runtime changes are kept; see The state file.
verify_concurrency0 (the CPUs divided by the cores, at least 2)ORBITMQ_AUTH_VERIFY_CONCURRENCYPassword-file hash checks running at once per core; see Hashing limits.
verify_queue1024ORBITMQ_AUTH_VERIFY_QUEUEChecks waiting per core beyond those; further clients are refused with Server Busy.

[[authentication]] tables have no environment overrides, but their secrets can be read from environment variables or files. Two variables are shortcuts for containers:

VariableEffect
ORBITMQ_AUTH_PASSWORD_FILE=/pathAppends a password_file source named password_file at the end of the authentication chain.
ORBITMQ_AUTH_ACL_FILE=/pathAppends a file source named acl_file at the end of the authorization chain.

Each appends one source after those of orbitmq.toml. Names must be unique per chain, so if the file already has a password_file source without a name, give it one. While a state file exists, it replaces both chains, including sources added by these variables.

Every [auth] key and every source key is listed in the configuration reference.

What clients see

SituationMQTT 5.0 CONNACKMQTT 3.1.1 / 3.1 CONNACK
A source accepted the client, or an anonymous client with allow_anonymous = trueSuccessAccepted
Wrong or missing password for a known user; an invalid or expired JWT0x86 Bad User Name or Password4, bad user name or password
A user name no source accepted0x86 Bad User Name or Password4, bad user name or password
A source does not know the user and has on_not_found = "deny"0x86 Bad User Name or Password4, bad user name or password
No user name, no source accepted the client, allow_anonymous = false0x87 Not Authorized5, not authorized
An HTTP source answered deny for a client without a password, or an expire_at in the past0x87 Not Authorized5, not authorized
The certificate field chosen for an x509 source is missing or unusable0x87 Not Authorized5, not authorized
A source failed, timed out or was saturated, with on_error = "deny" (the default)0x88 Server Unavailable3, server unavailable
auth.timeout_ms ran out0x88 Server Unavailable3, server unavailable
The password-file verification queue of the client's core is full0x89 Server Busy3, server unavailable

A session authenticated with a JWT ends when the token expires (exp plus leeway_secs), and one accepted by an HTTP source that returned expire_at ends at that time: MQTT 5.0 clients get DISCONNECT with 0xA0 Maximum Connect Time, MQTT 3.x clients are disconnected. The client reconnects with fresh credentials.

Unknown user names cost the same as known ones. The password file verifies its first entry's hash for an unknown user, and every database source verifies the most recent real hash it has read (the same scheme and parameters as its users' hashes; a fresh Argon2id hash until it has read one), so response times do not reveal which users exist. Hash comparisons are constant time, and hashing runs off the event loop, so a slow hash never delays other clients on the same core.

Source kinds

kindChainsDecides withNetwork I/O
password_fileauthenticationa file of user names and password hashesnone
x509authenticationthe verified TLS client certificatenone
jwtbotha JSON Web Token, verified with a shared secret, a public key or a JWKS endpointonly to fetch a JWKS
httpbothan HTTP(S) service that answers allow, deny or ignoreyes
postgres, mysqlbothan SQL query returning a password hashyes
redisbotha Redis hash holding a password hashyes
mongodbbotha MongoDB document holding a password hashyes

file is the authorization-only counterpart of password_file; see Authorization sources. Keys that belong to the other chain (an acl_query on an [[authentication]] source, an auth_query on an [[authorization]] source) are errors.

The default build includes every kind; orbitmq --help lists those compiled into the binary. A kind left out of a custom build (Cargo features auth-jwt, auth-http, auth-postgres, auth-mysql, auth-redis, auth-mongodb) is a configuration error. Every network source uses the broker's own TLS stack (rustls); no system OpenSSL is needed.

Network sources run on a small separate runtime, so a slow database or service never blocks the cores that serve MQTT traffic. Connections are opened lazily: an unreachable backend does not stop the broker from starting, its checks fail according to on_error. An invalid source (unknown key, invalid URL or query, unset secret variable, unreadable file) does stop the broker at start-up, with a message that names the source and never contains a secret.

Common keys

KeyDefaultMeaning
kindrequiredOne of the kinds above.
namethe kindUnique name in the chain: 1 to 64 letters, digits, -, _ or .. Used in logs, metrics, the admin API and the dashboard.
enabledtrueDisabled sources are skipped. Can be changed at runtime.
timeout_ms3000Network kinds: time allowed for one check. A timeout is a backend error.
on_error"deny""deny": a backend error, timeout or max_in_flight overflow refuses the client with 0x88 Server Unavailable (fail closed). "ignore": the next source is asked.
on_not_found"ignore"Unknown user (not in the password file; no row, key or document; an HTTP ignore answer). "ignore": next source. "deny": refuse with 0x86.
max_in_flight256Network kinds: most checks running at once. Further clients are treated as a backend error, so a slow backend cannot pile up unbounded work.
[authentication.cache]see CachingNetwork kinds: decision cache.

[authentication.cache] and [authentication.tls] tables belong to the [[authentication]] table declared just above them. password_file and x509 sources never wait on I/O and keep no cache, so of the common keys only name, enabled and (for password_file) on_not_found have an effect on them.

Secrets

Database URLs, the JWT secret and HTTP header values are secrets. Each can be written in three ways:

url = "postgres://orbitmq:[email protected]/mqtt"   # inline
url = { env = "MQTT_AUTH_DB_URL" }                    # from an environment variable
url = { file = "/run/secrets/mqtt-auth-db-url" }      # from a file (one trailing line break is removed)

Variables and files are read when the source is built (at start-up, or when it is added or replaced at runtime). A variable that is not set or a file that cannot be read stops the broker at start-up, or refuses the API request with 400; the error names the variable or the file, never the value.

Secret files should be readable by the broker's user only. On Unix, the broker logs a warning naming the file and its mode when a secret file, a password file, a source's tls.client_key or a listener's TLS private key can be read or written by its group or by other users (chmod 600 fixes it).

Secrets are redacted whenever a configuration is printed, logged or returned by the admin API: an inline value shows as "<redacted>", a reference as the { env = … } or { file = … } it is, and user information and query strings of URLs are redacted too. The password a client sends is never logged. An inline secret sent through the admin API is stored in the state file, which is why that file is written with mode 0600; prefer { env = … } or { file = … } references there.

Placeholders

Queries, keys, filters and claim checks can refer to the connecting client:

PlaceholderValue
%uthe CONNECT user name (in ACL lookups: the authenticated user name, which a JWT or HTTP source may have replaced)
%cthe client identifier
%Cthe Common Name of the verified TLS client certificate
%athe client's IP address (from the PROXY header when the listener uses it)
%lthe listener name
%%a literal %

Any other % is literal. Client values never become query text:

  • SQL: every placeholder becomes a bind parameter ($1, $2, … for PostgreSQL, ? for MySQL). Write %u, not '%u': a placeholder inside quotes is a configuration error, as is an unterminated quote.
  • Redis: placeholders are allowed only in the key, which is sent as a separate protocol argument, so a value can never become another command or argument.
  • MongoDB: filter values are rendered as BSON strings, so a value can never become an operator ($ne, $regex, …) or change the filter's structure.
  • JWT verify_claims compares the rendered string with the claim.

When a placeholder has no value for a client (for example %u without a user name, or %C without a client certificate), the lookup is not run and the source answers ignore.

Caching

Each network source has a bounded cache of its answers, so a reconnecting client is answered without asking the backend again:

[[authentication]]
kind = "redis"
url = { env = "MQTT_AUTH_REDIS_URL" }
auth_cmd = "HMGET mqtt_user:%u password_hash is_superuser"

[authentication.cache]
ttl_secs = 60             # accepted clients (0 disables)
negative_ttl_secs = 5     # refusals and unknown users (0 disables)
max_entries = 10000       # per source; the oldest are evicted first (0 disables the cache)
  • The cache key is a keyed SHA-256 digest of everything the source sees: client identifier, user name, password, certificate CN, IP address and listener. The key is random per process, so the digests are useless outside it, and a different password never hits another password's entry.
  • A revoked or changed user can still connect for up to ttl_secs after the change. Lower it (or set 0) when revocation must take effect at once.
  • An accepted JWT is never cached past its exp, and an HTTP answer never past its expire_at.
  • Errors and timeouts are never cached.
  • [[authorization]] sources have the same table ([authorization.cache]) for the rules they load at CONNECT.

Failure policy

Sources fail closed by default: with on_error = "deny", an unreachable backend, an error, a timeout, an unusable answer or more than max_in_flight checks at once refuses the client with 0x88 Server Unavailable (3.x return code 3), and a warning naming the source and the client identifier is logged. With on_error = "ignore" the next source is asked instead, which suits a secondary source that should not block clients another source can vouch for.

on_error = "ignore" together with allow_anonymous = true is fail-open. While that source is failing it answers ignore, so a client without a user name reaches the end of the chain and connects anonymously, even one the source would have refused. Use on_error = "deny" on any source that guards such a broker, or leave anonymous access off.

Order sources so that each one sees the clients it is meant for. A source that knows a user refuses a wrong password instead of passing it on, and a jwt source refuses any token (by default, any password) that it cannot verify. Put a jwt source after the sources that should see ordinary passwords, or take the token from the user name (from = "username").

Superusers

Users listed in [auth] superusers (env ORBITMQ_AUTH_SUPERUSERS, comma-separated) become superusers once any authentication source has accepted them. Sources can also mark a client as a superuser themselves: a JWT superuser_claim, an HTTP is_superuser field, an is_superuser column or hash field, or a MongoDB superuser_field. Anonymous clients are never superusers. What a superuser may do is decided by each authorization source's superuser_bypass; see Superusers.

Password file

orbitmq.toml
[[authentication]]
kind = "password_file"
name = "local"
path = "/etc/orbitmq/passwords"
on_not_found = "ignore"     # the default: unknown users go to the next source

The file is read when the source is built: at start-up, and again when the source is replaced through the admin API (send the same configuration with PUT to reload a changed file). A malformed line stops the broker (or refuses the API request) with an error that names the line number, never the hash.

A client without a user name gets ignore from this source. A known user with a wrong or missing password is refused with 0x86.

File format

One user per line, username:hash. Blank lines and lines starting with # are ignored. The user name is everything before the first :, so it cannot contain :; it must not start with # or have surrounding whitespace. Each user may appear only once.

/etc/orbitmq/passwords
# OrbitMQ password file
alice:$argon2id$v=19$m=19456,t=2,p=1$Y0akgAA7qKLlDaYqymiHrg$Gy8CBnBpo7mAxKpPKnxZi6Lc0AlPckPlV+Jd8dwE8Ww
bob:$2y$12$GQZhrwdnD053tH26kCCIquIj4PRQL9pU3aa8H9j./3aoxIZsSwYvm
sensor-17:$pbkdf2-sha256$i=600000,l=32$VKEWCktq60OGnzK1BjhN9g$I94Zc8Z0jiPc4wNByZi0phnZQYlTDs63YHLqwq2p8o8

Every hash above is for the password example. Generate your own with orbitmqctl passwd.

SchemeFormatPrefix
Argon2id, Argon2i, Argon2dPHC string$argon2id$, $argon2i$, $argon2d$
PBKDF2-HMAC-SHA256 or SHA512PHC string$pbkdf2-sha256$, $pbkdf2-sha512$
bcryptmodular crypt format$2a$, $2b$, $2x$, $2y$

Argon2id is recommended. bcrypt only considers the first 72 bytes of a password. The database sources accept the same hash formats.

Hashing limits

Hash parameters are bounded, so a hostile or mistaken entry cannot make every login cost gigabytes of memory or minutes of CPU:

SchemeLargest accepted parameters
Argon2m (memory) 65536 KiB (64 MiB), t (passes) 10, p (lanes) 16
bcryptcost 14
PBKDF2i (iterations) 2 000 000

A password-file line above these bounds fails the load like any malformed line; a database row above them is a backend error (on_error). The hashes orbitmqctl passwd writes are well inside them.

Each core runs at most [auth] verify_concurrency password-file verifications at once (0, the default, means the CPUs divided by the cores, at least 2) and queues at most verify_queue more (default 1024). A client that finds the queue full is refused with 0x89 Server Busy (3.x return code 3). A verification keeps its slot until the hash finishes, even if the client's authentication timed out meanwhile.

Creating entries

orbitmqctl passwd prints a complete username:hash line for the password file:

orbitmqctl passwd alice >> /etc/orbitmq/passwords                        # prompts twice, no echo
printf '%s\n' "$PW" | orbitmqctl passwd --stdin --scheme bcrypt bob     # scripts and pipes
orbitmqctl passwd [--scheme argon2id|pbkdf2-sha256|bcrypt] [--stdin] <username>
--schemeHash written
argon2id (default)$argon2id$v=19$m=19456,t=2,p=1$… (19 MiB of memory, 2 passes, 1 lane)
pbkdf2-sha256$pbkdf2-sha256$i=600000,l=32$… (600 000 iterations)
bcrypt$2b$12$… (cost 12); passwords of 72 bytes or more are refused

The hashes are made with the same libraries and parameters the broker uses, with a fresh random salt each time. The password is never accepted as a command-line argument: it is read from the terminal without echo and asked twice, or, with --stdin, taken from the first line of standard input (the line ending is removed). Without --stdin, a standard input that is not a terminal is an error. User names that the file format does not allow are refused.

To store a hash in a database instead, keep the part after the first :.

orbitmqctl is built from the sdk-cli repository (cargo build --release; the binary is target/release/orbitmqctl); see the orbitmqctl reference. Any other tool that prints one of the formats above, such as htpasswd -nBC 12, works as well.

x509 (client certificates)

Accepts clients by the verified certificate they presented on a mutual TLS listener, and uses one of its fields as the MQTT user name (available to ACL rules as %u):

[[authentication]]
kind = "x509"
name = "device-certs"
field = "cn"     # "cn" (default) | "dn" | "sha256"
fieldUser name
cnThe subject's first Common Name, for example device-1.
dnThe full subject distinguished name in RFC 4514 form, for example CN=device-1,O=Example.
sha256The lower-case hex SHA-256 fingerprint of the DER certificate.
  • Without a client certificate the source answers ignore.
  • If the CONNECT carries a user name that differs from the certificate's, the source answers ignore, so a later source decides for that user name and the certificate grants nothing under another name.
  • A field that is missing, empty, longer than 1024 bytes or contains control characters refuses the client with 0x87.
  • The certificate chain is verified against the listener's client_ca during the TLS handshake, before CONNECT is read; this source never sees an unverified certificate.

JWT

Accepts clients that present a valid JSON Web Token, by default as the CONNECT password:

[[authentication]]
kind = "jwt"
name = "device-tokens"
jwks_url = "https://auth.example.com/keys.json"
algorithms = ["RS256", "ES256"]
issuer = ["https://auth.example.com/"]
audience = ["mqtt"]
username_claim = "sub"
verify_claims = { clientid = "%c" }
superuser_claim = "mqtt_admin"

A token for this source might carry:

{
  "iss": "https://auth.example.com/",
  "aud": "mqtt",
  "sub": "device-1",
  "clientid": "device-1",
  "exp": 1798761600
}
KeyDefaultMeaning
from"password"Where the token is: "password" or "username". A client without one gets ignore. With "username", username_claim is required, so the token itself never becomes the user name (it would show in logs, the admin API and %u).
secretHMAC secret (secret), at least 32 bytes (after base64 decoding); a shorter one is refused.
secret_base64falseWhether secret is base64 encoded.
public_key_filePEM public key: RSA, EC or Ed25519.
jwks_urlJWKS endpoint: HTTPS, or HTTP on a loopback address.
jwks_refresh_secs300Periodic JWKS refresh (at least 10 seconds). A failed refresh keeps the previous keys.
jwks_min_refresh_secs30Least time between two refreshes triggered by a token whose kid is unknown.
[authentication.tls]TLS options for jwks_url (see TLS for outgoing connections).
algorithmssee belowAccepted alg values.
leeway_secs30Clock skew allowed for exp and nbf.
require_exptrueRefuse tokens without exp. exp and nbf are always checked when present.
issuer[]Accepted iss values; empty means not checked (a warning is logged at start-up).
audience[]Accepted aud values; empty means not checked (a warning is logged at start-up).
username_claimClaim used as the session's user name (%u in ACLs); a token without it is refused. Unset, the CONNECT user name is kept.
verify_claims{}Claims that must equal a placeholder template, for example { clientid = "%c", username = "%u" }.
superuser_claimClaim that makes the client a superuser when true (true, a non-zero number, or "true", "1", "yes").

Set exactly one of secret, public_key_file and jwks_url. To take the client's ACL from a token claim, add a jwt source with acl_claim to the authorization chain.

  • Algorithms: HS256, HS384, HS512 (with secret only), RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384 and EdDSA (with a public key or JWKS only). Without algorithms, a secret accepts the three HMAC algorithms and a public key or JWKS accepts every asymmetric one. none is never accepted, and mixing HMAC with public keys is a configuration error, so a public key can never be used as an HMAC secret.
  • JWKS: keys are fetched on first use and refreshed every jwks_refresh_secs. A token whose kid is not in the current set triggers an early refresh, at most once every jwks_min_refresh_secs. Keys marked for encryption are ignored, and a key's own alg, when present, must match the token's. A JWKS request (connect, response and body) times out after 10 seconds. A JWKS endpoint that cannot be reached when no keys are loaded yet is a backend error (on_error).
  • Expiry: the session ends when the token expires, at exp plus leeway_secs: MQTT 5.0 clients get DISCONNECT 0xA0 Maximum Connect Time, MQTT 3.x clients are disconnected. Clients reconnect with a fresh token.
  • Issuer and audience: set both, so tokens issued for other services, or by other issuers sharing the key, are refused. A warning is logged at start-up while either is unchecked.
  • Any token that fails verification (signature, algorithm, exp, nbf, iss, aud, verify_claims, a missing username_claim) is refused with 0x86. Tokens larger than 16 KiB are refused.

HMAC with a secret from the environment:

[[authentication]]
kind = "jwt"
secret = { env = "MQTT_JWT_SECRET" }
verify_claims = { username = "%u" }

HTTP

Sends every CONNECT that reaches it to an HTTP(S) service, which decides:

[[authentication]]
kind = "http"
name = "auth-service"
url = "https://auth.internal.example/mqtt/auth"
headers = { Authorization = { env = "MQTT_AUTH_SERVICE_TOKEN" } }
timeout_ms = 2000
KeyDefaultMeaning
urlrequiredEndpoint receiving POST requests. HTTPS, or HTTP on a loopback address.
allow_insecure_httpfalseAllow plain HTTP to a non-loopback host. Credentials then travel in clear text, and a warning is logged when the source is built. Without it, such a URL is refused.
headers{}Extra request headers; the values are secrets.
pool_max_idle32Idle connections kept per host.
max_response_bytes65536Largest accepted response body.
[authentication.tls]TLS options.

The request is POST <url> with Content-Type: application/json, the configured headers and this body:

{
  "clientid": "device-1",
  "username": "alice",
  "password": "secret",
  "peerhost": "10.0.0.7",
  "peerport": 51234,
  "cert_cn": null,
  "listener": "default"
}

username, password and cert_cn are null when absent. A password that is not valid UTF-8 is sent as password_base64 instead of password.

The service answers status 200 with a JSON object:

{ "result": "allow", "is_superuser": false, "username": "alice", "expire_at": 1798761600 }
FieldMeaning
resultRequired. "allow"; "deny" (0x86 when the client sent a password, 0x87 otherwise); or "ignore" (unknown user: on_not_found applies).
is_superuserOptional. Makes the client a superuser when true.
usernameOptional. Replaces the session's user name (%u in ACLs).
expire_atOptional. Unix seconds; the answer is not cached past it, an allow whose expire_at has passed is refused with 0x87, and the session ends at that time (DISCONNECT 0xA0 Maximum Connect Time for MQTT 5.0, a close for 3.x).

Any other status, a body that is not a JSON object or a result other than these three, or a body larger than max_response_bytes is a backend error (on_error). The same service can also supply ACLs through an http authorization source.

PostgreSQL and MySQL

kind = "postgres" and kind = "mysql" (MySQL and MariaDB) take the same keys:

[[authentication]]
kind = "postgres"
name = "devices"
url = { env = "MQTT_AUTH_DB_URL" }   # postgres://orbitmq:…@db.internal:5432/mqtt
pool_size = 8
auth_query = "SELECT password_hash, is_superuser FROM mqtt_user WHERE username = %u"

[authentication.tls]
mode = "verify-full"
ca_file = "/etc/orbitmq/tls/db-ca.crt"
schema.sql (PostgreSQL)
CREATE TABLE mqtt_user (
  username      text PRIMARY KEY,
  password_hash text,                          -- from `orbitmqctl passwd`, the part after the first ':'
  is_superuser  boolean NOT NULL DEFAULT false
);
KeyDefaultMeaning
urlrequiredConnection URL (secret: it usually holds the database password).
pool_size8Pooled connections.
auth_queryrequiredReturns at most one row with a text password_hash column and an optional is_superuser column (boolean, integer or text). No row means an unknown user; a NULL hash never authenticates.
[authentication.tls]see belowTLS.
allow_insecure_tlsfalseAccept a TLS mode below "verify-full" to a non-loopback host; see Insecure connections.

The tls table of SQL sources:

KeyDefaultMeaning
modethe URL's sslmode (PostgreSQL) or ssl-mode (MySQL) parameter if present, otherwise "verify-full""disable" (clear text), "prefer" (TLS if offered, not verified), "require" (TLS, certificate not verified), "verify-ca" (chain verified) or "verify-full" (chain and host name verified).
roots"both""both": the root certificates bundled with the broker plus the operating system's; "bundled": only the bundled ones. SQL sources always trust the bundled roots, so "system" and "none" are refused.
ca_fileExtra trusted CA certificates (PEM), read when the source is built.
client_cert, client_keyClient certificate and key (PEM) for mutual TLS.

For MySQL, the same queries use ? bind parameters internally; write %u in the configuration either way.

Redis

[[authentication]]
kind = "redis"
url = { env = "MQTT_AUTH_REDIS_URL" }   # rediss://:[email protected]:6380
auth_cmd = "HMGET mqtt_user:%u password_hash is_superuser"
pool_size = 4
redis-cli HSET mqtt_user:alice password_hash '$argon2id$v=19$m=19456,t=2,p=1$…' is_superuser 0
KeyDefaultMeaning
urlrequiredredis:// or rediss:// (TLS) URL (secret). redis://:password@host authenticates with a password only.
auth_cmdrequiredHMGET <key> <fields…> (fields by position; password_hash must be one of them, is_superuser is optional) or HGETALL <key> (fields by name). A missing key or a missing password_hash field means an unknown user.
pool_size4Pooled connections.
[authentication.tls]TLS options for rediss://.
allow_insecure_tlsfalseAccept redis:// (plain text) to a non-loopback host; see Insecure connections.

Only these read-only commands are accepted, and placeholders are allowed only in the key. While Redis is down, the source keeps reconnecting with backoff and checks fail according to on_error.

MongoDB

MongoDB is part of the default build.

[[authentication]]
kind = "mongodb"
url = { env = "MQTT_AUTH_MONGO_URL" }   # mongodb://orbitmq:…@mongo.internal:27017/?tls=true
database = "mqtt"
collection = "users"
filter = { username = "%u" }
KeyDefaultMeaning
urlrequiredmongodb:// URL (secret). TLS is switched on with the URL option tls=true. mongodb+srv:// URLs are not supported.
[authentication.tls]When the URL enables TLS: roots ("both" by default; see TLS for outgoing connections) and ca_file (extra trusted CAs; the URL's tlsCAFile is the alternative). On Windows, use the URL's tlsCAFile instead.
databaserequiredDatabase.
collectionrequiredUser collection.
filter{ username = "%u" }Equality filter that finds the user document; values may hold placeholders. Must not be empty.
password_hash_field"password_hash"Field holding the password hash.
superuser_field"is_superuser"Field that makes the client a superuser when true (boolean, non-zero integer, or a string such as "true").
allow_insecure_tlsfalseAccept a URL without tls=true, or with tlsInsecure or tlsAllowInvalidCertificates, to a non-loopback host; see Insecure connections.

Insecure connections

Database sources refuse, at start-up (or when added through the admin API), to talk to a host that is not on this machine in plain text or over TLS they do not fully verify:

  • PostgreSQL and MySQL: a TLS mode below "verify-full";
  • Redis: a redis:// URL;
  • MongoDB: a URL without tls=true, or with tlsInsecure or tlsAllowInvalidCertificates.

Loopback addresses, localhost and Unix sockets never leave the machine and are always accepted. To accept such a connection anyway, set allow_insecure_tls = true on that source; the broker then logs a warning when the source is built, because credentials and answers can be read or changed on the way. The http source has the same rule for http:// URLs with allow_insecure_http.

TLS for outgoing connections

The tls table of jwt (for jwks_url), http and redis sources ([authentication.tls], or [authorization.tls] in the other chain):

KeyDefaultMeaning
roots"both"Which root certificates to trust: "both" (the Mozilla list bundled with the broker plus the operating system's), "bundled", "system", or "none" (only ca_file, which is then required).
ca_fileExtra trusted CA certificates (PEM).
client_cert, client_keyClient certificate chain and key (PEM) for mutual TLS; set both or neither.

Server certificates and host names are always verified. SQL sources have their own TLS table, and MongoDB takes roots and ca_file in its tls table.

Changing the chains at runtime

Both chains can be reordered, enabled, disabled and edited while the broker runs, without a restart and without disturbing connected clients. A CONNECT that is being authenticated finishes on the chain it started with, and every PUBLISH or SUBSCRIBE check sees exactly one version of the authorization chain.

From the dashboard

The Auth & ACL page of the built-in dashboard lists both chains in priority order, with each source's kind, state (active, disabled, or failing after a backend error in the last 60 seconds) and allow / deny / ignore counters, refreshed every 5 seconds. Reorder sources by dragging a row or with its move-up and move-down buttons, then apply the new order; switch a source on or off with its toggle. Every change is confirmed before it is sent. If someone else changed the chains in the meantime, the page reports the conflict and reloads instead of overwriting their change.

Adding, replacing and removing sources is done through the admin API.

With the admin API

The endpoints live under /api/v1/auth/{chain}, where {chain} is authentication or authorization, and use the admin API's bearer tokens (see the Admin REST API guide and the reference).

Method and pathEffect
GET /api/v1/auth/{chain}The sources in order (name, kind, enabled, position, status, redacted configuration, counters), the chain end (allow_anonymous or no_match), revision, persisted and state_file.
PUT /api/v1/auth/{chain}/order{"order": [names…]}: a new order naming every source exactly once.
PATCH /api/v1/auth/{chain}/sources/{name}{"enabled": true} or false.
POST /api/v1/auth/{chain}/sources{"source": {…}, "position": n}: add a source (the keys of its TOML table, as JSON); position is 0-based, the end by default. Answers 201.
PUT /api/v1/auth/{chain}/sources/{name}{"source": {…}}: replace a source's configuration; it keeps its position.
DELETE /api/v1/auth/{chain}/sources/{name}Remove a source.
H="Authorization: Bearer $ORBITMQ_TOKEN"; API=http://127.0.0.1:18083/api/v1/auth

# Ask PostgreSQL before the password file
curl -s -X PUT -H "$H" -H 'Content-Type: application/json' \
  -d '{"order": ["devices", "local"], "revision": 4}' $API/authentication/order

# Take the HTTP source out of the chain for now
curl -s -X PATCH -H "$H" -H 'Content-Type: application/json' \
  -d '{"enabled": false}' $API/authentication/sources/auth-service

# Add a Redis ACL source in first position
curl -s -X POST -H "$H" -H 'Content-Type: application/json' \
  -d '{"source": {"kind": "redis", "name": "acl-redis", "url": {"env": "MQTT_AUTH_REDIS_URL"},
       "acl_cmd": "HGETALL mqtt_acl:%u"}, "position": 0}' $API/authorization/sources

Every change returns the chain as GET shows it. Each change accepts an optional revision (in the body, or as ?revision=n for DELETE): when the chains changed since that revision, the change is refused with 409 conflict, so two people editing at once never overwrite each other. Other errors are 400 invalid (an invalid order or source configuration, a duplicate name, an unset secret variable), 404 not_found (no such chain or source) and 500 persist_failed (the state file could not be written). A refused change leaves both chains as they were.

The API never returns secrets, so a PUT must restate every secret, or reference it with {"env": …} or {"file": …}. Network connections of an added or replaced source are opened lazily, so an unreachable database does not fail the request. The broker logs every change with the new order.

How changes affect connected clients:

  • Reordering, enabling and disabling apply to the next CONNECT and the next PUBLISH or SUBSCRIBE check.
  • Authorization sources that load rules at CONNECT keep the rules they loaded for each session. A session connected while a source was disabled has no rules from it: that source answers ignore for the session until it reconnects. Likewise, a replaced source answers ignore for sessions that connected before the change.
  • Removing an authentication source does not disconnect anyone.

The state file

Runtime changes are written to [auth] state_file (env ORBITMQ_AUTH_STATE_FILE). Unset, it is orbitmq.auth-state.toml in the directory of the configuration file the broker loaded (--config, ORBITMQ_CONFIG or ./orbitmq.toml). The file holds both complete chains in the same TOML shape as orbitmq.toml, plus version = 1. It is written to a temporary file, synced and renamed, with mode 0600, because sources added through the API may hold inline secrets.

  • While it exists, it replaces every [[authentication]] and [[authorization]] table of orbitmq.toml (and the sources appended by ORBITMQ_AUTH_PASSWORD_FILE and ORBITMQ_AUTH_ACL_FILE). The broker logs a warning saying so at start-up, and the API and dashboard show from_state_file.
  • An invalid state file stops the start-up (fail closed).
  • To go back to the chains of orbitmq.toml, stop the broker, delete the state file, and start it again.
  • Without a configuration file and without state_file, changes live in memory only and the API reports "persisted": false.
  • The [auth] settings themselves (allow_anonymous, superusers, no_match, timeout_ms) are not part of the state file; they always come from orbitmq.toml and the environment.

Metrics

Each source of either chain has its own series on /metrics, with the labels chain (authentication or authorization), source (its name) and kind:

MetricTypeDescription
orbitmq_auth_source_decisions_totalcounterAnswers of the source, by result (allow, deny, ignore). For authorization sources: one per PUBLISH or SUBSCRIBE check that reached the source.
orbitmq_auth_source_checks_totalcounterNetwork sources: queries sent to the backend.
orbitmq_auth_source_errors_totalcounterNetwork sources: backend errors, timeouts and max_in_flight refusals.
orbitmq_auth_source_cache_hits_totalcounterNetwork sources: answers taken from the cache.
orbitmq_auth_source_enabledgauge1 when the source is enabled, 0 when it is skipped.
orbitmq_auth_source_positiongaugeThe source's 0-based position in its chain.

The auth_backend_errors alarm reads the same error counters; authorization sources appear in it as authorization/<name>.

Configuration changes from earlier builds

The [[authentication]] and [[authorization]] tables replace the earlier single backend list. These keys are gone. Unknown keys are errors, so a configuration that still uses them does not start; for the source and ACL-file keys the message names the replacement:

RemovedUse instead
[auth] password_filean [[authentication]] source with kind = "password_file" (or ORBITMQ_AUTH_PASSWORD_FILE)
[auth] acl_filean [[authorization]] source with kind = "file" (or ORBITMQ_AUTH_ACL_FILE)
[[auth.backend]][[authentication]] (and [[authorization]] for ACLs)
acl_query, acl_cmd, acl_collection, acl_claim on an authenticating sourcethe same key on an [[authorization]] source of the same kind
acl = true (HTTP)an [[authorization]] source with kind = "http"
acl_no_matchno_match on the [[authorization]] source
default, superuser_bypass in the ACL fileno_match and superuser_bypass on the [[authorization]] source

Notes

  • Authentication and authorization are separate: once a client is authenticated, the authorization chain decides what it may publish and subscribe to. Its user name is available to ACL rules as %u.
  • A verified TLS client certificate sets the MQTT user name only through an x509 source. Without one, it only controls who may connect to the listener (see mutual TLS).
  • MQTT 5.0 enhanced authentication (the AUTH packet exchange) is not offered; a CONNECT with an Authentication Method is refused with 0x8C Bad Authentication Method.

On this page