Learn Labs
Operations

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

rabbitmqctl add_user billing-svc 'secret'rabbitmqctl change_password billing-svc 'new-secret'rabbitmqctl set_user_tags billing-svcno tags: can use AMQP, can't log into the UIrabbitmqctl set_user_tags ops-alice administratorfull UI and API adminrabbitmqctl set_user_tags grafana monitoringread-only UI/API access to every vhost's statsrabbitmqctl delete_user guestin production: remove the default user

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:

PermissionAllows
configureDeclaring and deleting exchanges and queues
writePublishing to an exchange; binding to a queue
readConsuming 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.

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 too

With 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).

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

  1. Delete guest; one user per service; least-privilege regexes, anchored.
  2. Separate vhosts for separate tenants or environments.
  3. TLS for AMQP and the management UI on any untrusted network.
  4. Erlang cookie from a secret store; ports 25672/4369 private.
  5. monitoring-tagged users for dashboards, not administrator.

Lab

  1. Create a user billing-svc that can only consume from orders.billing and publish nowhere: set_permissions -p shop billing-svc '^$' '^$' '^orders\\.billing$'.
  2. Connect as billing-svc, consume from orders.billing (works) and from orders.shipping.eu (refused). Try to publish to orders (refused).
  3. Log into the UI as monitoring and see what you can and can't do.
  4. Set topic permissions so a user may only publish order.*.eu to orders, and test a .us key.

On this page