0
0
RabbitmqHow-ToBeginner ยท 3 min read

How to Set Permissions in RabbitMQ: Simple Guide

To set permissions in RabbitMQ, use the rabbitmqctl set_permissions command followed by the virtual host, username, and permission patterns for configure, write, and read. This controls what resources a user can manage or access within a specific virtual host.
๐Ÿ“

Syntax

The rabbitmqctl set_permissions command sets user permissions on a virtual host. It requires five arguments:

  • -p <vhost>: The virtual host where permissions apply.
  • username: The RabbitMQ user to set permissions for.
  • configure: A regex pattern for resources the user can configure (create/delete).
  • write: A regex pattern for resources the user can write to (publish messages).
  • read: A regex pattern for resources the user can read from (consume messages).

Use ".*" to allow all resources or "" to deny all.

bash
rabbitmqctl set_permissions -p <vhost> <username> <configure> <write> <read>
๐Ÿ’ป

Example

This example sets permissions for user alice on virtual host /. It allows configuring and writing to all resources, but reading only from queues starting with task_.

bash
rabbitmqctl set_permissions -p / alice ".*" ".*" "^task_.*"
Output
Setting permissions for user "alice" in vhost "/" ...
โš ๏ธ

Common Pitfalls

Common mistakes when setting permissions include:

  • Using incorrect virtual host name, causing permissions not to apply.
  • Setting empty regex patterns unintentionally, which denies all access.
  • Confusing the order of configure, write, and read arguments.
  • Not restarting or reloading RabbitMQ when changes don't seem to take effect (usually not needed but good to check).

Always verify permissions with rabbitmqctl list_user_permissions <username>.

bash
rabbitmqctl set_permissions -p / alice "" ".*" ".*"
rabbitmqctl list_user_permissions alice
Output
Setting permissions for user "alice" in vhost "/" ... alice / "" ".*" ".*"
๐Ÿ“Š

Quick Reference

ArgumentDescriptionExample
vhostVirtual host where permissions apply/
usernameRabbitMQ user to set permissions foralice
configureRegex for resources user can configure.*
writeRegex for resources user can write to.*
readRegex for resources user can read from^task_.*
โœ…

Key Takeaways

Use rabbitmqctl set_permissions with virtual host, username, and regex patterns for configure, write, and read.
Regex ".*" grants full access; empty string "" denies access for that permission type.
Verify permissions with rabbitmqctl list_user_permissions to avoid mistakes.
Permissions apply per virtual host, so specify the correct vhost.
Order of arguments is important: vhost, username, configure, write, read.