NOTE 002 / SECURITY / 2026-11 / 11 MIN READ
Multi-tenant broker auth: where decentralized trust fails open
Abstract. NATS decentralized authentication lets a vendor run one shared message broker for many customers, with an account per tenant, a signed credential per node and no secret on the server. We built a reporting channel on it for a bring-your-own-cloud managed database platform, and the model held up. What it does not do is promise several properties an architect would reasonably assume, and some of the gaps fail open or fail silently. This note describes the model briefly, lists what we had to measure rather than assume on nats-server 2.12.6, and shows how each gap became a deploy-time gate, a continuous check or a test.
The model in one page
Decentralized authentication has three levels of identity, each an NKey (an Ed25519 key pair with a typed encoding) and each described by a signed JWT. The operator is the root of trust. Accounts are signed by the operator, and users are signed by their account. The server is configured with the operator JWT and a resolver that supplies account JWTs. When a client connects, the server sends a nonce, the client signs it with its user key and presents its user JWT, and the server walks the chain upwards. Nothing on the server can issue a credential: everything it holds is public verification material.
The account is the useful primitive for multi-tenancy. Identical subjects in two accounts are two different subjects, and a credential cannot name its way out of its own account however wide its permissions are. Nothing crosses an account boundary unless one account exports a subject and another imports it.
The layout we used is one account per tenant, created at the moment the tenant's first cluster is installed, with no deployment and no broker restart. Each node gets its own user, whose publish permission is confined to its own subject. Each tenant account exports its status subjects one way into a single consuming account, under a prefix that names the tenant, and the control plane reads every tenant on one connection with one credential. New accounts are pushed to a full resolver over the system account, which writes them to a directory so they survive a restart.
The lesson first: test the negative cases, and keep testing them
Every gap below has the same shape. The positive path works: a valid credential connects, a report arrives, the health endpoint answers. A suite built on those observations passes on a broker that accepts anonymous publishers, or on an account with no message store. In a trust system the properties that matter are negatives: who is refused, what is not delivered, what has not changed. We wrote them down as checks that run at deployment, on a timer and in the test suite, and confirmed each one by breaking what it guards and watching it fail.
What we had to check rather than assume
All behaviour below was measured against nats-server 2.12.6, or read in its source at that version where we say so. It describes the server at that version, not a defect in any deployment.
Start-up and the root of trust
A trust file without an operator starts an open broker. We kept the broker's main configuration separate from a generated trust file holding the operator and account material. A non-empty trust file that declares no operator, for example one holding a single comment line, starts the server cleanly. The monitoring endpoint then reports neither authentication required nor a trusted operator, and an anonymous plaintext client receives an acknowledgement to a publish. A deploy gate that only checks the file exists and is non-empty passes.
The server does not check who signed its own operator JWT. An operator JWT signed by the operator's signing key rather than its identity key, and declaring an extra signing key, starts the server, and an account signed by that extra key is admitted. Keeping the identity seed offline does not protect the root of trust on its own. Write access to the broker's trust configuration does, so file ownership became the control.
A preload is not automatically authoritative. With a full resolver, the server stores each preloaded account at start through a save-if-newer rule. A preload replaces the directory copy only if its issued-at time is not older. A pushed amendment to a preloaded account therefore survives a restart, and an older preload loses silently.
Composing accounts
Two exports of the same subject merge silently. When two tenant accounts export the same subject into one importing account without an import prefix, the server accepts the configuration with no warning and delivers both streams on the identical subject, distinguishable only by payload. The prefix is a security requirement, not a naming convention. With it, the consumer can also reject a report whose tenant prefix disagrees with the cluster it names.
JetStream is off for an account whose JWT declares no limits. The server-wide JetStream block keeps reporting normally and the health endpoint stays green, while the account reports JetStream disabled and a stream create is refused. Declaring unlimited storage (-1) in the account JWT enables it and leaves the server ceiling as the only bound.
The consuming account's JWT grows with every tenant. An import is per exporting account, so the consuming account gains about a kilobyte per tenant and is re-signed and pushed on every onboarding. It is pushed as one message, so it eventually passes max_payload: at 64 KB, that happens at around sixty tenants.
Credentials and limits
An expired credential can reconnect within its final second. The server closes an open connection from a timer armed at the expiry instant, but the connect-time check compares whole seconds. A node whose credential lapses reconnects once, publishes briefly and is dropped again, so the first symptom is a flapping connection rather than a clean refusal.
Lowering a live account's connection cap keeps the oldest connections. The newest are dropped, so a long-held connection on a leaked credential keeps its slot. The cap bounds how much one tenant can consume of the shared broker. It does not find the leak.
Two defaults are permissive. Read in the server source: unless an account disallows bearer tokens, a bearer user JWT skips nonce verification, so a copied credential file works without the private key. A user JWT with no permissions falls back to the account's defaults, and an empty default means unrestricted; a grant that sets only one direction leaves the other open. We set both account fields before issuing the first credential.
Seeing what happened
Permission violations are logged by public key, not by user name. The log names the account key and the user's public key, and the name inside the user JWT appears nowhere. Attribution needs a roster from public key to node identity, kept outside the broker.
A pushed account JWT is stored before its issuer is checked. The full resolver saves it unverified and refuses it only when it next loads the account, typically after a restart. A credential that may push can therefore plant an account that locks a tenant out later, and a successful lookup does not prove the server will accept what it holds.
| Assumption | What actually happens (nats-server 2.12.6) | Control we added |
|---|---|---|
| A broker with a trust file is authenticating | A trust file with no operator line starts an open broker | Deploy gate: the file must declare an operator and a preload, and the monitoring endpoint must report both authentication required and a trusted operator |
| Only the operator identity key can change the root of trust | The server does not check who signed its configured operator JWT | Trust file owned by root and not writable by the control plane's account, checked at deployment |
| The preload is the authoritative copy | A preload wins only if it is not older than the directory copy | The system account's directory file is removed on every broker start; other accounts are never preloaded |
| Colliding exports are refused | Without a prefix they merge silently | A tenant prefix on every import; reports whose prefix disagrees with the cluster they name are rejected and counted |
| A JetStream-enabled server enables it for every account | An account JWT with no limits has no store, with health still green | Limits declared at account creation; a test asserts the reading, ordered so a negative cannot pass early |
| The consuming account's JWT stays small | It grows per tenant and eventually passes max_payload | A rebuild over the limit is refused before it is recorded, with a warning at three quarters |
| Expiry is a clean cut-off | A reconnect in the final second is accepted | Expiry warnings well ahead of the date; a test waits out the second before asserting refusal |
| Lowering a cap evicts the intruder | The newest connections are dropped | A per-credential connection count that alerts on a second connection |
| The audit log names the user | It names a public key | The issuer emits each user's public key into a roster beside the node identity |
| The broker holds what we pushed | Any well-formed account JWT can be pushed and stored | Continuous comparison of every account against our own record |
The controls
Deploy-time gates, including a positive one
Besides the trust file and monitoring checks above, the deployment confirms that an anonymous client is refused. Under an operator that check means less than it did with static passwords: a trust file with an empty or wrong preload refuses everyone, including every real credential, and still passes. So the deployment also connects with a real credential and requires acceptance. Without that probe, a broker that locks out the whole fleet would deploy green.
A continuous comparison against our own record
The component that creates tenant accounts holds the operator signing key, so it can re-sign any existing tenant's account with a signing key of its own and issue credentials inside it. That is inherent to onboarding without a human step. We cannot prevent it from inside the system, so we made it visible.
The control plane records two JWTs per account: the one it wants the broker to hold and the last one it confirmed the broker holds. It looks every recorded account up on the system account and compares byte for byte when its system connection comes up, on a five-minute tick, and whenever a push is heard on any claims-update subject, including pushes by other system users. An absent account is pushed back from the record. The control plane's own unconfirmed push is completed. Anything else raises a security alert and pushes nothing, because overwriting a value we did not write could erase the evidence or race a legitimate operator. The consuming and system accounts are compared whole, because an attacker who adds a signing key and leaves the imports alone would otherwise be invisible.
Restoring is a deliberate operator act: push the recorded JWT and confirm it by lookup. The server applies a pushed account JWT whatever its issued-at time. In a drill, restoring an account after a rogue signing key had been added closed the rogue-signed live connection within about 1.5 seconds, refused its reconnect, and left the legitimately signed connection up.
Credential lifecycle
Node credentials are issued only after the installation step that precedes the agent has succeeded, so a failed install does not leave a valid credential behind. Every issued credential is recorded, and destroying a cluster ends with re-signing the tenant's account with all of that cluster's credentials revoked. Every user credential expires. Account and operator JWTs do not, because an expiring account closes every client in it at once.
Transport and surface
Clients use TLS handshake-first with a TLS 1.3 floor, set explicitly because the server's default minimum is 1.2. The agent pins the broker's public key, and the check lives in Go's VerifyConnection callback rather than VerifyPeerCertificate. The second is not invoked on resumed TLS sessions, and these clients reconnect constantly, so a pin there would be checked once and then never again while session tickets were issued.
The enabled listeners are a closed list: the client TLS port, with monitoring bound to loopback. MQTT, leafnode and WebSocket are off. When we evaluated the server in September 2026, nine of the fourteen advisories published against it that year were in those three listeners. A feature that is available but not enabled carries none of that history into the deployment.
Tests that are allowed to fail
The acceptance test widens one tenant's credential to the maximum the system can express and asserts it still observes and sends nothing of another tenant's, nor anything in the consuming account. Its mutation issues both credentials in one account and confirms the test then fails, which is the difference between a configured boundary and an architectural one. Other tests inject a rogue signing key into each account type, restore a stale resolver directory, and push an account signed by an undeclared key, then assert the alert and the recovery.
What the model does not confine
The account boundary confines a permission mistake and a leaked node or tenant credential. It does not confine a compromise of the host that onboards tenants, which can reach every tenant's account through the signing key. Keeping that key out of the long-running process, and reading it only in a short-lived issuing process, defeats a memory disclosure but not code execution as the same account. The comparison loop turns that exposure from silent into alerted. It does not prevent it.
Open questions
- A signing interface that never discloses the key. Moving operator and tenant signing behind an interface that signs without revealing the seed is the real answer to the onboarding-host exposure. We would build it before commands, not only status, flow over the channel.
- Accounts the record does not know. The comparison looks up only accounts we recorded. An account pushed for an unknown tenant receives no tenant's data, but it carries no connection cap. Seeing it requires enumerating the resolver directory.
- Revocation of an open connection. A later connection on a revoked credential is refused, proven by test. Whether the server closes a connection that is already open when the revocation lands is still unmeasured.
- Message rate. The connection cap bounds connections, not rate. One node publishing fast enough can push the single consuming subscription towards slow-consumer limits, and we did not find a per-account rate limit in the broker for this.
- Clustering. A push is applied whatever its issued-at time on one server, while cluster synchronisation saves only if newer. On a clustered broker a forged far-future issued-at could win on the peers, and the restore procedure would need rethinking.
- What we would do differently. Write the negative checks before the positive path. Most gaps above were found by running the pinned binary, not by reading documentation.