Security
Users, vhosts, permission regexes, TLS, and the Erlang cookie
RabbitMQ's access control is simpler than Kafka's: users authenticate, virtual hosts separate tenants, and three permission regexes per user per vhost decide what they can touch.
Users and tags
Tags control management UI/API access only. Messaging permissions are separate.
Permissions: three regexes
For each user and vhost: configure, write, read, each a regex matched against resource names:
| Permission | Allows |
|---|---|
| configure | Declaring and deleting exchanges and queues |
| write | Publishing to an exchange; binding to a queue |
| read | Consuming from a queue; binding from an exchange |
This cluster's app user, from definitions.json:
docker exec rabbit-1 rabbitmqctl -q list_permissions -p shop
user configure write read
admin .* .* .*
app ^(lab\.|tmp\.|amq\.gen-).* .* .*
monitoring ^$ ^$ ^$app can publish and consume anything in shop, but can only declare
lab.*, tmp.*, and server-named (amq.gen-*) queues. It can't delete or
redeclare the production topology. When it tried, in
The AMQP Model:
(403, "ACCESS_REFUSED - configure access to queue 'orders.billing' in vhost 'shop' refused for user 'app'")^$ matches nothing, which is how monitoring gets no messaging rights at
all.
Permission regexes are unanchored by default and match the whole name
only if you anchor them. orders matches orders, old-orders, and
orders-archive. Always write ^orders$ or ^orders\\. deliberately.
Also, exclusive server-named queues (used for RPC replies and temporary
pub/sub) need configure permission on ^amq\\.gen-, which is easy to
forget and fails only at runtime.
Topic permissions
For topic exchanges, rabbitmqctl set_topic_permissions can additionally
restrict which routing keys a user may publish with, for example
letting the EU order service publish only order.*.eu.
TLS
listeners.tcp = none # disable plaintext AMQP
listeners.ssl.default = 5671
ssl_options.cacertfile = /etc/rabbitmq/tls/ca.pem
ssl_options.certfile = /etc/rabbitmq/tls/server.pem
ssl_options.keyfile = /etc/rabbitmq/tls/server.key
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = false # true for mutual TLS
management.ssl.port = 15671 # the UI/API over HTTPS tooWith mutual TLS, the rabbitmq_auth_mechanism_ssl plugin can authenticate
clients by their certificate instead of a password. Inter-node traffic can
also be encrypted (Erlang distribution over TLS).
The Erlang cookie
The Erlang cookie is effectively a root password for the cluster: any
process with the cookie that can reach port 25672 can run arbitrary code
on the node. In this lab it's a plain value in the compose file
(RABBITMQ_ERLANG_COOKIE); in production, mount it from a secret store,
never expose 25672 or 4369 (epmd) beyond the cluster's network, and
rotate it like any other credential.
Other identity sources
The rabbitmq_auth_backend_oauth2 plugin accepts JWTs from an identity
provider, mapping token scopes to permissions; rabbitmq_auth_backend_ldap
checks LDAP. Both are common in larger organisations so credentials aren't
managed in RabbitMQ itself.
Checklist
- Delete
guest; one user per service; least-privilege regexes, anchored. - Separate vhosts for separate tenants or environments.
- TLS for AMQP and the management UI on any untrusted network.
- Erlang cookie from a secret store; ports 25672/4369 private.
monitoring-tagged users for dashboards, notadministrator.
Lab
- Create a user
billing-svcthat can only consume fromorders.billingand publish nowhere:set_permissions -p shop billing-svc '^$' '^$' '^orders\\.billing$'. - Connect as
billing-svc, consume fromorders.billing(works) and fromorders.shipping.eu(refused). Try to publish toorders(refused). - Log into the UI as
monitoringand see what you can and can't do. - Set topic permissions so a user may only publish
order.*.eutoorders, and test a.uskey.