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, andreadarguments. - 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
| Argument | Description | Example |
|---|---|---|
| vhost | Virtual host where permissions apply | / |
| username | RabbitMQ user to set permissions for | alice |
| configure | Regex for resources user can configure | .* |
| write | Regex for resources user can write to | .* |
| read | Regex 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.