How to Use LDAP Authentication with RabbitMQ
To use
LDAP with RabbitMQ, enable the rabbitmq_auth_backend_ldap plugin and configure the rabbitmq.conf file with your LDAP server details. This setup allows RabbitMQ to authenticate users against your LDAP directory for secure access control.Syntax
The main configuration for LDAP in RabbitMQ is done in the rabbitmq.conf file. You specify the LDAP server URL, user search base, and authentication method. The rabbitmq_auth_backend_ldap plugin must be enabled to use LDAP authentication.
Key configuration parts include:
auth_backends: List of authentication backends, including LDAP.ldap.servers: LDAP server addresses.ldap.user_dn_patternorldap.user_search_base: How to find users in LDAP.ldap.use_ssl: Whether to use SSL for LDAP connection.
ini
auth_backends.1 = ldap ldap.servers.1 = ldap.example.com ldap.user_dn_pattern = cn=${username},ou=users,dc=example,dc=com ldap.use_ssl = false # Optional: group lookup for permissions ldap.group_search_base = ou=groups,dc=example,dc=com # Enable the LDAP backend plugin # Run: rabbitmq-plugins enable rabbitmq_auth_backend_ldap
Example
This example shows how to configure RabbitMQ to authenticate users against an LDAP server at ldap.example.com. It uses a simple user DN pattern and disables SSL for LDAP connection.
bash
## rabbitmq.conf auth_backends.1 = ldap ldap.servers.1 = ldap.example.com ldap.user_dn_pattern = cn=${username},ou=users,dc=example,dc=com ldap.use_ssl = false # Enable LDAP plugin rabbitmq-plugins enable rabbitmq_auth_backend_ldap # Restart RabbitMQ service after configuration changes sudo systemctl restart rabbitmq-server
Output
Plugin "rabbitmq_auth_backend_ldap" enabled.
Restarting rabbitmq-server.service...
Common Pitfalls
- Not enabling the LDAP plugin: You must run
rabbitmq-plugins enable rabbitmq_auth_backend_ldapbefore LDAP works. - Incorrect user DN pattern or search base: If the LDAP path to users is wrong, authentication will fail.
- LDAP server unreachable: RabbitMQ must be able to connect to the LDAP server on the network.
- SSL misconfiguration: If your LDAP server requires SSL, set
ldap.use_ssl = trueand configure certificates properly.
ini
## Wrong user DN pattern example
ldap.user_dn_pattern = cn=${username},ou=wrong,dc=example,dc=com
## Correct user DN pattern example
ldap.user_dn_pattern = cn=${username},ou=users,dc=example,dc=comQuick Reference
| Configuration Key | Description | Example Value |
|---|---|---|
| auth_backends.1 | Authentication backend to use | ldap |
| ldap.servers.1 | LDAP server address | ldap.example.com |
| ldap.user_dn_pattern | Pattern to locate user DN | cn=${username},ou=users,dc=example,dc=com |
| ldap.use_ssl | Enable SSL for LDAP connection | false |
| ldap.group_search_base | Base DN for group lookup | ou=groups,dc=example,dc=com |
Key Takeaways
Enable the rabbitmq_auth_backend_ldap plugin to use LDAP authentication.
Configure user DN pattern or search base correctly to match your LDAP structure.
Ensure RabbitMQ can reach the LDAP server and SSL settings match your LDAP setup.
Restart RabbitMQ after changing LDAP configuration for changes to take effect.