RabbitMQ 4.0 token authentication: revoked tokens stay valid until cache TTL expires
0 reputation · 10 Jun 2024, 10:47 UTC
0 reputation · 10 Jun 2024, 10:47 UTC
We are migrating service authentication to the built-in token backend (rabbitmq_auth_backend_token) introduced in RabbitMQ 4.0.0, with per-token expiration timestamps and least-privilege configure/write/read permissions scoped per user and virtual host.
The design goal is straightforward: when a token is compromised or a credential is rotated, deleting the token entry should cut off access immediately. From the documented behavior, however, the broker caches token validation results, so a deleted or revoked token may remain usable until the token cache TTL (defaulting to roughly 60 seconds) elapses. There appears to be no built-in mechanism to force immediate invalidation.
For short-lived automation credentials this window matters, and I want to design around it deliberately rather than discover it during an incident.
31775 reputation · 10 Jun 2024, 15:34 UTC
In RabbitMQ 4.0 the only supported way to make a revoked token unusable immediately is to reduce the authentication cache TTL. The broker keeps a local cache per node; a deleted token remains accepted until the TTL expires on each node. There is no built‑in command to push a purge across the cluster, so the revocation window is bounded by the TTL you configure.
The token backend stores the token’s validity in a database or key‑value store. Each node validates a token once, then caches the result for the duration of rabbitmq_auth_backend_token_cache_ttl (default ~60 s). During that period the node will skip a lookup and accept the token even if it has been deleted in the backend. The cache is local, so revocation timing can differ slightly across nodes depending on when the token was last cached.
auth_cache metrics in the Management UI or via rabbitmqctl list_metrics and watch CPU and latency on the node. If the broker shows elevated load, increase the TTL slightly.expires_at set to a few minutes). Even if a token is revoked, its natural expiry limits the window of abuse.Because each node caches independently, a token that is revoked on the backend may still be accepted on a node that cached it earlier. The difference is usually a few milliseconds to a few seconds, depending on network latency and when the node last performed a lookup. If absolute consistency is required, consider deploying a very short TTL and ensuring that your backend lookup is fast enough to not become a bottleneck.
RabbitMQ currently offers no command to force a cache purge for a specific token across all nodes. The only workaround is to lower the TTL or to delete the token and wait for the TTL to expire on each node.
To fine‑tune the TTL, you’ll need to know how fast your authentication backend can answer a token lookup. If you’re using an external database or a networked key‑value store, measure the round‑trip latency and adjust the TTL accordingly.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.